Skip to content

Commit 43573f0

Browse files
Merge pull request #14 from onix-labs/feature-v3
Feature v3
2 parents 60c7e59 + 00210ed commit 43573f0

File tree

5 files changed

+195
-36
lines changed

5 files changed

+195
-36
lines changed

docs/CHANGELOG-3.0.0.md

+134
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,138 @@ data class SignatureData(
4848
4949
---
5050

51+
### SendTransactionStep _Object_
52+
53+
**Module:** onixlabs-corda-core-workflow
54+
55+
**Package:** io.onixlabs.corda.core.workflow
56+
57+
Represents a progress tracker step indicating that a signed transaction is being sent.
58+
59+
```kotlin
60+
object SendTransactionStep : Step
61+
```
62+
63+
### Remarks
64+
65+
The `publishTransaction` extension function uses this as the default `progressTrackerStep` argument, however you can replace it with your own progress tracker step.
66+
67+
---
68+
69+
### ReceiveTransactionStep _Object_
70+
71+
**Module:** onixlabs-corda-core-workflow
72+
73+
**Package:** io.onixlabs.corda.core.workflow
74+
75+
Represents a progress tracker step indicating that a signed transaction is being received.
76+
77+
```kotlin
78+
object SendTransactionStep : Step
79+
```
80+
81+
### Remarks
82+
83+
The `publishTransactionHandler` extension function uses this as the default `progressTrackerStep` argument, however you can replace it with your own progress tracker step.
84+
85+
---
86+
87+
### publishTransaction _Extension Function_
88+
89+
**Module:** onixlabs-corda-core-workflow
90+
91+
**Package:** io.onixlabs.corda.core.workflow
92+
93+
Publishes a `SignedTransaction` to the specified flow sessions.
94+
95+
```kotlin
96+
@Suspendable
97+
fun FlowLogic<*>.publishTransaction(
98+
transaction: SignedTransaction,
99+
sessions: Set<FlowSession>,
100+
progressTrackerStep: Step = SendTransactionStep
101+
): SignedTransaction
102+
```
103+
104+
#### Remarks
105+
106+
To use this function, `SendTransactionStep` will need to be evident in your progress tracker, unless you replace the default argument with your own progress tracker step.
107+
108+
---
109+
110+
### publishTransactionHandler _Extension Function_
111+
112+
**Module:** onixlabs-corda-core-workflow
113+
114+
**Package:** io.onixlabs.corda.core.workflow
115+
116+
Handles and records a published `SignedTransaction`.
117+
118+
```kotlin
119+
@Suspendable
120+
fun FlowLogic<*>.publishTransactionHandler(
121+
session: FlowSession,
122+
statesToRecord: StatesToRecord = StatesToRecord.ALL_VISIBLE,
123+
checkSufficientSignatures: Boolean = true,
124+
progressTrackerStep: Step = ReceiveTransactionStep
125+
): SignedTransaction
126+
```
127+
128+
#### Remarks
129+
130+
To use this function, `ReceiveTransactionStep` will need to be evident in your progress tracker, unless you replace the default argument with your own progress tracker step.
131+
132+
---
133+
134+
### finalizeTransaction _Extension Function_
135+
136+
**Module:** onixlabs-corda-core-workflow
137+
138+
**Package:** io.onixlabs.corda.core.workflow
139+
140+
Finalizes a transaction.
141+
142+
```kotlin
143+
@Suspendable
144+
fun FlowLogic<*>.finalizeTransaction(
145+
transaction: SignedTransaction,
146+
sessions: Iterable<FlowSession> = emptyList(),
147+
counterpartyStatesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT,
148+
ourStatesToRecord: StatesToRecord = StatesToRecord.ONLY_RELEVANT
149+
): SignedTransaction
150+
```
151+
152+
> 🔵 **INFORMATION**
153+
>
154+
> This API exists in version 2.1.0 however in version 3.0.0 there are two notable changes:
155+
>
156+
> 1. The `sessions` parameter provides a default `emptyList()` argument; useful for finalising local transactions.
157+
> 2. `SendStatesToRecordStep` only needs to be evident in your progress tracker when finalising transactions with counter-parties. For local transactions, this progress tracker step can be omitted.
158+
159+
---
160+
161+
### StatesToRecordBySession _Class_
162+
163+
**Module:** onixlabs-corda-core-workflow
164+
165+
**Package:** io.onixlabs.corda.core.workflow
166+
167+
Represents a mapping of `FlowSession` to `StatesToRecord`, allowing a transaction initiator to specify how each counter-party should record the states of a transaction.
168+
```kotlin
169+
class StatesToRecordBySession(
170+
statesToRecordBySession: Map<FlowSession, StatesToRecord> = emptyMap()
171+
)
172+
```
173+
174+
### Remarks
175+
176+
> 🔵 **INFORMATION**
177+
>
178+
> This API exists in version 2.1.0 however in version 3.0.0, there are two notable changes:
179+
>
180+
> 1. `addSession` has been renamed to `setSessionStatesToRecord`. If a flow session already exists in the underlying map, this function will overwrite its `StatesToRecord` value. If a flow session doesn't exist in the underlying map, this function will add the flow session to the underlying map with the specified `StatesToRecord` value.
181+
> 2. `addMissionSession` has been renamed to `addSessionStatesToRecord`. If a flow session already exists in the underlying map, this function will ignore the addition. If a flow session doesn't exist in the underlying map, this function will add the flow session to the underlying map with the specified `StatesToRecord` value.
182+
183+
---
184+
51185
###

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

+42-2
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

+10
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

-27
This file was deleted.

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

+9-7
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)