Skip to content

Commit d593601

Browse files
Added projection for checkSufficientSessions to map anonymous parties to well-known parties.
1 parent fa55658 commit d593601

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=onixlabs-corda-core
22
group=io.onixlabs
3-
version=3.1.0
3+
version=3.2.0
44
onixlabs.development.jarsign.keystore=../lib/onixlabs.development.pkcs12
55
onixlabs.development.jarsign.password=5891f47942424d2acbe108691fdb5ba258712fca7e4762be4327241ebf3dbfa3

onixlabs-corda-core-workflow/src/main/kotlin/io/onixlabs/corda/core/workflow/Extensions.FlowLogic.Sessions.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ fun FlowLogic<*>.initiateFlows(parties: Iterable<AbstractParty>, vararg states:
8282
*
8383
* @param sessions The flow sessions that have been provided to the flow.
8484
* @param states The states that will be used as input or output states in a transaction.
85+
* @param partyProjection Provides a mechanism to project, or resolve anonymous to well-known identities.
8586
* @throws FlowException if a required counter-party session is missing for a state participant.
8687
*/
8788
@Suspendable
88-
fun FlowLogic<*>.checkSufficientSessions(sessions: Iterable<FlowSession>, states: Iterable<ContractState>) {
89+
fun FlowLogic<*>.checkSufficientSessions(
90+
sessions: Iterable<FlowSession>,
91+
states: Iterable<ContractState>,
92+
partyProjection: (AbstractParty) -> AbstractParty = { it }
93+
) {
8994
val stateCounterparties = states
9095
.flatMap { it.participants }
9196
.filter { it !in serviceHub.myInfo.legalIdentities }
@@ -95,7 +100,7 @@ fun FlowLogic<*>.checkSufficientSessions(sessions: Iterable<FlowSession>, states
95100
.map { it.counterparty }
96101
.toSet()
97102

98-
stateCounterparties.forEach {
103+
stateCounterparties.map { partyProjection(it) }.forEach {
99104
if (it !in sessionCounterparties) {
100105
throw FlowException("A flow session must be provided for the specified counter-party: $it.")
101106
}
@@ -114,9 +119,10 @@ fun FlowLogic<*>.checkSufficientSessions(sessions: Iterable<FlowSession>, states
114119
* @throws FlowException if a required counter-party session is missing for a state participant.
115120
*/
116121
@Suspendable
117-
fun FlowLogic<*>.checkSufficientSessions(sessions: Iterable<FlowSession>, vararg states: ContractState) {
118-
checkSufficientSessions(sessions, states.toSet())
119-
}
122+
fun FlowLogic<*>.checkSufficientSessions(
123+
sessions: Iterable<FlowSession>, vararg states: ContractState,
124+
partyProjection: (AbstractParty) -> AbstractParty = { it }
125+
) = checkSufficientSessions(sessions, states.toSet(), partyProjection)
120126

121127
/**
122128
* Checks that sufficient flow sessions have been provided for the specified transaction.
@@ -126,7 +132,11 @@ fun FlowLogic<*>.checkSufficientSessions(sessions: Iterable<FlowSession>, vararg
126132
* @throws FlowException if a required counter-party session is missing for a state participant.
127133
*/
128134
@Suspendable
129-
fun FlowLogic<*>.checkSufficientSessions(sessions: Iterable<FlowSession>, transaction: TransactionBuilder) {
135+
fun FlowLogic<*>.checkSufficientSessions(
136+
sessions: Iterable<FlowSession>,
137+
transaction: TransactionBuilder,
138+
partyProjection: (AbstractParty) -> AbstractParty = { it }
139+
) {
130140
val ledgerTransaction = transaction.toLedgerTransaction(serviceHub)
131-
checkSufficientSessions(sessions, ledgerTransaction.inputStates + ledgerTransaction.outputStates)
141+
checkSufficientSessions(sessions, ledgerTransaction.inputStates + ledgerTransaction.outputStates, partyProjection)
132142
}

0 commit comments

Comments
 (0)