Skip to content

Commit e3425fd

Browse files
1.0.0-rc2
1 parent 6e7dd19 commit e3425fd

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ buildscript {
2929
}
3030

3131
group 'io.onixlabs'
32-
version '1.0.0-rc1'
32+
version '1.0.0-rc2'
3333

3434
subprojects {
3535
repositories {

onixlabs-corda-core-workflow/src/main/kotlin/io/onixlabs/corda/core/workflow/FlowLogicExtensions.kt

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import co.paralleluniverse.fibers.Suspendable
2020
import net.corda.core.contracts.ContractState
2121
import net.corda.core.contracts.StateAndRef
2222
import net.corda.core.contracts.StateRef
23-
import net.corda.core.cordapp.CordappConfigException
2423
import net.corda.core.crypto.SecureHash
2524
import net.corda.core.flows.FlowException
2625
import net.corda.core.flows.FlowLogic
@@ -54,16 +53,16 @@ val FlowLogic<*>.randomNotary: Party
5453
*
5554
* @param defaultSelector The selector function to obtain a notary if none have been specified in the CorDapp config.
5655
* @return Returns the preferred or default notary.
57-
* @throws IllegalAccessException If the preferred notary cannot be found in the network map cache.
56+
* @throws IllegalArgumentException If the preferred notary cannot be found in the network map cache.
5857
*/
5958
@Suspendable
60-
fun FlowLogic<*>.getPreferredNotary(defaultSelector: (ServiceHub) -> Party = { firstNotary }): Party = try {
61-
val name = CordaX500Name.parse(serviceHub.getAppContext().config.getString("notary"))
62-
serviceHub.networkMapCache.getNotary(name) ?: throw IllegalArgumentException(
63-
"Notary with the specified name cannot be found in the network map cache: $name."
64-
)
65-
} catch (e: CordappConfigException) {
66-
defaultSelector(serviceHub)
59+
inline fun FlowLogic<*>.getPreferredNotary(defaultSelector: (ServiceHub) -> Party = { firstNotary }): Party {
60+
return if (serviceHub.getAppContext().config.exists("notary")) {
61+
val name = CordaX500Name.parse(serviceHub.getAppContext().config.getString("notary"))
62+
serviceHub.networkMapCache.getNotary(name) ?: throw IllegalArgumentException(
63+
"Notary with the specified name cannot be found in the network map cache: $name."
64+
)
65+
} else defaultSelector(serviceHub)
6766
}
6867

6968
/**
@@ -86,6 +85,38 @@ fun FlowLogic<*>.currentStep(step: Step, log: Boolean = true, additionalLogInfo:
8685
}
8786
}
8887

88+
/**
89+
* Initiates flow sessions for the specified parties, except for identities that belong to the local node,
90+
* since flow sessions are not required locally.
91+
*
92+
* @param parties The parties for which to create flow sessions.
93+
* @return Returns a set of flow sessions.
94+
*/
95+
@Suspendable
96+
fun FlowLogic<*>.initiateFlows(vararg parties: AbstractParty): Set<FlowSession> {
97+
return parties
98+
.map { serviceHub.identityService.requireWellKnownPartyFromAnonymous(it) }
99+
.filter { it !in serviceHub.myInfo.legalIdentities }
100+
.map { initiateFlow(it) }
101+
.toSet()
102+
}
103+
104+
/**
105+
* Initiates flow sessions for the participants of the specified states, except for
106+
* identities that belong to the local node, since flow sessions are not required locally.
107+
*
108+
* @param states The states for which to create flow sessions for the state participants.
109+
* @return Returns a set of flow sessions.
110+
*/
111+
@Suspendable
112+
fun FlowLogic<*>.initiateFlows(vararg states: ContractState): Set<FlowSession> {
113+
return states.flatMap { it.participants }
114+
.map { serviceHub.identityService.requireWellKnownPartyFromAnonymous(it) }
115+
.filter { it !in serviceHub.myInfo.legalIdentities }
116+
.map { initiateFlow(it) }
117+
.toSet()
118+
}
119+
89120
/**
90121
* Initiates flow sessions for the specified parties and participants of the specified states, except for
91122
* identities that belong to the local node, since flow sessions are not required locally.

0 commit comments

Comments
 (0)