有一个流程按照下面的情形。
交易1:输入状态σ - ContractA结果输出StateB - ContractA
交易2:输入StateB - ContractA并没有输出
这是可能的琴弦? 请不要与响应共享的例子。 谢谢。
Answer 1:
是的,这是可能的。 例如:
@InitiatingFlow
@StartableByRPC
class TwoTransactionFlow(val inputStateAndRefA: StateAndRef<StateA>) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val notary = serviceHub.networkMapCache.notaryIdentities[0]
// Creating, signing and finalising the first transaction.
val txBuilderOne = TransactionBuilder(notary)
.addInputState(inputStateAndRefA)
.addOutputState(StateB(), ContractA.ID)
.addCommand(ContractA.Commands.Transfer(), ourIdentity.owningKey)
val signedTxOne = serviceHub.signInitialTransaction(txBuilderOne)
val notarisedTxOne = subFlow(FinalityFlow(signedTxOne))
// Creating, signing and finalising the second transaction.
val stateRefB = StateRef(notarisedTxOne.id, 0)
val stateAndRefB = serviceHub.toStateAndRef<StateB>(stateRefB)
val transactionBuilderTwo = TransactionBuilder(notary)
.addInputState(stateAndRefB)
.addCommand(ContractA.Commands.Exit(), ourIdentity.owningKey)
val signedTransactionTwo = serviceHub.signInitialTransaction(transactionBuilderTwo)
subFlow(FinalityFlow(signedTransactionTwo))
}
}
文章来源: In Corda, can the output of one transaction be used by new transaction in the same flow?