@@ -90,39 +90,39 @@ fun FlowLogic<*>.findTransaction(stateAndRef: StateAndRef<*>): SignedTransaction
9090
9191/* *
9292 * Provides a DSL-like transaction builder.
93- * To use this function, [BuildingTransactionStep ] will need to be evident in your progress tracker.
93+ * To use this function, [BuildTransactionStep ] will need to be evident in your progress tracker.
9494 *
9595 * @param notary The notary which will be applied to the transaction.
9696 * @param action The action which will be used to build the transaction.
9797 * @return Returns a [TransactionBuilder] representing the built transaction.
9898 */
9999@Suspendable
100100fun FlowLogic <* >.buildTransaction (notary : Party , action : TransactionBuilder .() -> Unit ): TransactionBuilder {
101- currentStep(BuildingTransactionStep )
101+ currentStep(BuildTransactionStep )
102102 val transactionBuilder = TransactionBuilder (notary)
103103 action(transactionBuilder)
104104 return transactionBuilder
105105}
106106
107107/* *
108108 * Verifies a transaction.
109- * To use this function, [VerifyingTransactionStep ] will need to be evident in your progress tracker.
109+ * To use this function, [VerifyTransactionStep ] will need to be evident in your progress tracker.
110110 *
111111 * @param transaction The transaction to verify.
112112 */
113113@Suspendable
114114fun FlowLogic <* >.verifyTransaction (transaction : TransactionBuilder ) {
115- currentStep(VerifyingTransactionStep )
115+ currentStep(VerifyTransactionStep )
116116 transaction.verify(serviceHub)
117117}
118118
119119/* *
120- * Signs a transaction
121- * To use this function, [SigningTransactionStep ] will need to be evident in your progress tracker.
120+ * Signs a transaction.
121+ * To use this function, [SignTransactionStep ] will need to be evident in your progress tracker.
122122 */
123123@Suspendable
124124fun FlowLogic <* >.signTransaction (transaction : TransactionBuilder ): SignedTransaction {
125- currentStep(SigningTransactionStep )
125+ currentStep(SignTransactionStep )
126126 val ourSigningKeys = transaction.getOurSigningKeys(serviceHub.keyManagementService)
127127 return serviceHub.signInitialTransaction(transaction, ourSigningKeys)
128128}
@@ -137,11 +137,16 @@ fun FlowLogic<*>.signTransaction(transaction: TransactionBuilder): SignedTransac
137137 *
138138 * @param transaction The transaction for which to collect remaining signatures from the specified counter-parties.
139139 * @param sessions All flow sessions that have been passed to this flow.
140+ * @param additionalSigningAction Allows additional signing actions to be specified. This will be executed after all other activity in this flow.
140141 * @return Returns a transaction which should be signed by all required signers.
141142 * @throws FlowException if the local node has been passed to this function as a counter-party or in a flow session.
142143 */
143144@Suspendable
144- fun FlowLogic <* >.collectSignatures (transaction : SignedTransaction , sessions : Iterable <FlowSession >): SignedTransaction {
145+ fun FlowLogic <* >.collectSignatures (
146+ transaction : SignedTransaction ,
147+ sessions : Iterable <FlowSession >,
148+ additionalSigningAction : ((SignedTransaction ) -> SignedTransaction )? = null
149+ ): SignedTransaction {
145150 currentStep(CollectTransactionSignaturesStep )
146151 val missingSigningKeys = transaction.getMissingSigners()
147152
@@ -155,14 +160,16 @@ fun FlowLogic<*>.collectSignatures(transaction: SignedTransaction, sessions: Ite
155160
156161 sessions.forEach { it.send(it in signingSessions) }
157162
158- return if (signingSessions.isEmpty()) transaction else subFlow(
163+ val signedTransaction = if (signingSessions.isEmpty()) transaction else subFlow(
159164 CollectSignaturesFlow (transaction, signingSessions, CollectTransactionSignaturesStep .childProgressTracker())
160165 )
166+
167+ return additionalSigningAction?.invoke(signedTransaction) ? : signedTransaction
161168}
162169
163170/* *
164171 * Signs a transaction.
165- * To use this function, [SigningTransactionStep ] will need to be evident in your progress tracker.
172+ * To use this function, [SignTransactionStep ] will need to be evident in your progress tracker.
166173 * Due to the way this function works, it is intended to be paired with [collectSignatures] in the initiating flow.
167174 *
168175 * @param session The flow session of the initiating flow that is requesting a transaction signature.
@@ -175,35 +182,67 @@ fun FlowLogic<*>.collectSignaturesHandler(
175182): SignedTransaction ? {
176183 val isRequiredToSign = session.receive<Boolean >().unwrap { it }
177184 return if (isRequiredToSign) {
178- currentStep(SigningTransactionStep )
179- subFlow(object : SignTransactionFlow (session, SigningTransactionStep .childProgressTracker()) {
185+ currentStep(SignTransactionStep )
186+ subFlow(object : SignTransactionFlow (session, SignTransactionStep .childProgressTracker()) {
180187 override fun checkTransaction (stx : SignedTransaction ) = action(stx)
181188 })
182189 } else null
183190}
184191
185192/* *
186193 * Finalizes a transaction.
187- * To use this function, [FinalizingTransactionStep] will need to be evident in your progress tracker.
194+ * To use this function, [SendStatesToRecordStep] and [FinalizeTransactionStep] will need to be evident in your progress tracker.
195+ *
196+ * This function allows the initiator to specify how counter-parties should record states of the finalized transaction.
197+ * For each session of the [statesToRecordBySession] object, the counter-party will receive their [StatesToRecord]
198+ * enumeration, unless they have specified an override via the [finalizeTransactionHandler] function. Finally they
199+ * will record the finalized transaction.
200+ *
201+ * @param transaction The transaction to finalize and record.
202+ * @param statesToRecordBySession Determines how counter-parties should record states in the transaction.
203+ * @param ourStatesToRecord Determines how our node should record states in the transaction.
204+ * @return Returns a fully signed, finalized and recorded transaction.
205+ */
206+ @Suspendable
207+ fun FlowLogic <* >.finalizeTransaction (
208+ transaction : SignedTransaction ,
209+ statesToRecordBySession : StatesToRecordBySession ,
210+ ourStatesToRecord : StatesToRecord = StatesToRecord .ONLY_RELEVANT
211+ ): SignedTransaction {
212+ return statesToRecordBySession.finalizeTransaction(transaction, this , ourStatesToRecord)
213+ }
214+
215+ /* *
216+ * Finalizes a transaction.
217+ * To use this function, [SendStatesToRecordStep] and [FinalizeTransactionStep] will need to be evident in your progress tracker.
218+ *
219+ * This function allows the initiator to specify how counter-parties should record states of the finalized transaction.
220+ * Each session will record the transaction states according to the [counterpartyStatesToRecord] parameter, unless they
221+ * have specified an override via the [finalizeTransactionHandler] function. Finally they will record the finalized transaction.
188222 *
189223 * @param transaction The transaction to be finalized.
190224 * @param sessions The sessions for all counter-parties and observers where this transaction should be recorded.
191- * @param statesToRecord Determines which states from the transaction should be recorded.
225+ * @param counterpartyStatesToRecord Determines how counter-parties should record states in the transaction.
226+ * @param ourStatesToRecord Determines how our node should record states in the transaction.
192227 * @return Returns a fully signed, finalized and recorded transaction.
193228 */
194229@Suspendable
195230fun FlowLogic <* >.finalizeTransaction (
196231 transaction : SignedTransaction ,
197232 sessions : Iterable <FlowSession >,
198- statesToRecord : StatesToRecord = StatesToRecord .ONLY_RELEVANT
233+ counterpartyStatesToRecord : StatesToRecord = StatesToRecord .ONLY_RELEVANT ,
234+ ourStatesToRecord : StatesToRecord = StatesToRecord .ONLY_RELEVANT
199235): SignedTransaction {
200- currentStep( FinalizingTransactionStep )
201- return subFlow( FinalityFlow ( transaction, sessions.toSet(), statesToRecord) )
236+ val statesToRecordBySession = StatesToRecordBySession (sessions, counterpartyStatesToRecord )
237+ return finalizeTransaction( transaction, statesToRecordBySession, ourStatesToRecord )
202238}
203239
204240/* *
205241 * Finalizes a transaction.
206- * To use this function, [RecordingFinalizedTransactionStep] will need to be evident in your progress tracker.
242+ * To use this function, [ReceiveStatesToRecordStep] and [RecordFinalizedTransactionStep] will need to be evident in your progress tracker.
243+ *
244+ * This function will first receive the [StatesToRecord] from the initiating node, however this can be overridden using
245+ * the [statesToRecord] parameter. Finally the transaction will be received and recorded.
207246 *
208247 * @param session The flow session of the initiating flow that is requesting the transaction to be finalized.
209248 * @param expectedTransactionId The expected transaction ID of the transaction to be recorded.
@@ -214,8 +253,12 @@ fun FlowLogic<*>.finalizeTransaction(
214253fun FlowLogic <* >.finalizeTransactionHandler (
215254 session : FlowSession ,
216255 expectedTransactionId : SecureHash ? = null,
217- statesToRecord : StatesToRecord = StatesToRecord . ONLY_RELEVANT
256+ statesToRecord : StatesToRecord ? = null
218257): SignedTransaction {
219- currentStep(RecordingFinalizedTransactionStep )
220- return subFlow(ReceiveFinalityFlow (session, expectedTransactionId, statesToRecord))
258+ currentStep(ReceiveStatesToRecordStep )
259+ val receivedStatesToRecord = session.receive<StatesToRecord >().unwrap { it }
260+ val ourStatesToRecord = statesToRecord ? : receivedStatesToRecord
261+
262+ currentStep(RecordFinalizedTransactionStep )
263+ return subFlow(ReceiveFinalityFlow (session, expectedTransactionId, ourStatesToRecord))
221264}
0 commit comments