@@ -20,7 +20,6 @@ import co.paralleluniverse.fibers.Suspendable
2020import net.corda.core.contracts.ContractState
2121import net.corda.core.contracts.StateAndRef
2222import net.corda.core.contracts.StateRef
23- import net.corda.core.cordapp.CordappConfigException
2423import net.corda.core.crypto.SecureHash
2524import net.corda.core.flows.FlowException
2625import 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