Skip to content

Commit 0a1d3d9

Browse files
Additional features for v3
1 parent 60c7e59 commit 0a1d3d9

File tree

4 files changed

+61
-36
lines changed

4 files changed

+61
-36
lines changed

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ fun FlowLogic<*>.finalizeTransaction(
215215
/**
216216
* Finalizes a transaction.
217217
* To use this function, [SendStatesToRecordStep] and [FinalizeTransactionStep] will need to be evident in your progress tracker.
218+
* If your flow only updates a transaction locally, you can omit [SendStatesToRecordStep] from your progress tracker.
218219
*
219220
* This function allows the initiator to specify how counter-parties should record states of the finalized transaction.
220221
* Each session will record the transaction states according to the [counterpartyStatesToRecord] parameter, unless they
@@ -229,7 +230,7 @@ fun FlowLogic<*>.finalizeTransaction(
229230
@Suspendable
230231
fun FlowLogic<*>.finalizeTransaction(
231232
transaction: SignedTransaction,
232-
sessions: Iterable<FlowSession>,
233+
sessions: Iterable<FlowSession> = emptyList(),
233234
counterpartyStatesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT,
234235
ourStatesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT
235236
): SignedTransaction {
@@ -256,9 +257,48 @@ fun FlowLogic<*>.finalizeTransactionHandler(
256257
statesToRecord: StatesToRecord? = null
257258
): SignedTransaction {
258259
currentStep(ReceiveStatesToRecordStep)
259-
val receivedStatesToRecord = session.receive<StatesToRecord>().unwrap { it }
260+
val receivedStatesToRecord = session.receive<String>().unwrap { StatesToRecord.valueOf(it) }
260261
val ourStatesToRecord = statesToRecord ?: receivedStatesToRecord
261262

262263
currentStep(RecordFinalizedTransactionStep)
263264
return subFlow(ReceiveFinalityFlow(session, expectedTransactionId, ourStatesToRecord))
264265
}
266+
267+
/**
268+
* Publishes a [SignedTransaction] to the specified flow sessions.
269+
*
270+
* @param transaction The signed transaction to publish.
271+
* @param sessions The sessions where the signed transaction should be published.
272+
* @param progressTrackerStep The progress tracker step to set before publishing the transaction.
273+
* @return Returns the published [SignedTransaction].
274+
*/
275+
@Suspendable
276+
fun FlowLogic<*>.publishTransaction(
277+
transaction: SignedTransaction,
278+
sessions: Set<FlowSession>,
279+
progressTrackerStep: Step = SendTransactionStep
280+
): SignedTransaction {
281+
currentStep(progressTrackerStep)
282+
sessions.forEach { subFlow(SendTransactionFlow(it, transaction)) }
283+
return transaction
284+
}
285+
286+
/**
287+
* Handles and records a published [SignedTransaction].
288+
*
289+
* @param session The session where the signed transaction was published from.
290+
* @param statesToRecord Determines which states to record from the signed transaction.
291+
* @param checkSufficientSignatures Determines whether to check if the signed transaction has been sufficiently signed.
292+
* @param progressTrackerStep The progress tracker step to set before recording the published the transaction.
293+
* @return Returns the published [SignedTransaction].
294+
*/
295+
@Suspendable
296+
fun FlowLogic<*>.publishTransactionHandler(
297+
session: FlowSession,
298+
statesToRecord: StatesToRecord = StatesToRecord.ALL_VISIBLE,
299+
checkSufficientSignatures: Boolean = true,
300+
progressTrackerStep: Step = ReceiveTransactionStep
301+
): SignedTransaction {
302+
currentStep(progressTrackerStep)
303+
return subFlow(ReceiveTransactionFlow(session, checkSufficientSignatures, statesToRecord))
304+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,13 @@ object FinalizeTransactionStep : Step("Finalizing transaction.") {
7373
* Represents a progress tracker step indicating that a transaction is being recorded.
7474
*/
7575
object RecordFinalizedTransactionStep : Step("Recording finalized transaction.")
76+
77+
/**
78+
* Represents a progress tracker step indicating that a signed transaction is being sent.
79+
*/
80+
object SendTransactionStep : Step("Sending signed transaction.")
81+
82+
/**
83+
* Represents a progress tracker step indicating that a signed transaction is being received.
84+
*/
85+
object ReceiveTransactionStep : Step("Receiving signed transaction.")

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ class StatesToRecordBySession(statesToRecordBySession: Map<FlowSession, StatesTo
4747
private val sessions: Set<FlowSession> get() = mutableStatesToRecordBySession.keys
4848

4949
/**
50-
* Adds a flow session to the underlying map.
50+
* Sets the [StatesToRecord] for the specified [FlowSession].
5151
* If a flow session already exists in the underlying map, this function will overwrite its [StatesToRecord] value.
5252
*
5353
* @param session The session to add to the underlying map.
5454
* @param statesToRecord The [StatesToRecord] value for the specified flow session.
5555
*/
56-
fun addSession(session: FlowSession, statesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT) {
56+
fun setSessionStatesToRecord(session: FlowSession, statesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT) {
5757
mutableStatesToRecordBySession[session] = statesToRecord
5858
}
5959

6060
/**
61-
* Adds a flow session to the underlying map.
61+
* Adds and sets the [StatesToRecord] for the specified [FlowSession].
6262
* If a flow session already exists in the underlying map, this function will leave its [StatesToRecord] value intact.
6363
*
6464
* @param session The session to add to the underlying map.
6565
* @param statesToRecord The [StatesToRecord] value for the specified flow session.
6666
*/
67-
fun addMissingSession(session: FlowSession, statesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT) {
68-
if (session !in sessions) addSession(session, statesToRecord)
67+
fun addSessionStatesToRecord(session: FlowSession, statesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT) {
68+
if (session !in sessions) setSessionStatesToRecord(session, statesToRecord)
6969
}
7070

7171
/**
@@ -84,8 +84,10 @@ class StatesToRecordBySession(statesToRecordBySession: Map<FlowSession, StatesTo
8484
ourStatesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT,
8585
childProgressTracker: ProgressTracker = FinalizeTransactionStep.childProgressTracker()
8686
): SignedTransaction {
87-
flowLogic.currentStep(SendStatesToRecordStep)
88-
mutableStatesToRecordBySession.forEach { (key, value) -> key.send(value) }
87+
if (mutableStatesToRecordBySession.isNotEmpty()) {
88+
flowLogic.currentStep(SendStatesToRecordStep)
89+
mutableStatesToRecordBySession.forEach { (key, value) -> key.send(value.name) }
90+
}
8991

9092
flowLogic.currentStep(FinalizeTransactionStep)
9193
return flowLogic.subFlow(FinalityFlow(transaction, sessions, ourStatesToRecord, childProgressTracker))

0 commit comments

Comments
 (0)