在Corda中,一个事务的输出可以被同一事务中的新事务使用吗? [英] In Corda, can the output of one transaction be used by new transaction in the same flow?
本文介绍了在Corda中,一个事务的输出可以被同一事务中的新事务使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照下面的方案有一个流程.
事务1:输入状态A-合同A产生输出状态B-合同A
交易2:输入状态B-合同A,无输出
在科尔达有可能吗?
请与响应分享一个例子.谢谢.
There is a flow as per below scenario.
Transaction 1: Input StateA - ContractA results in output StateB - ContractA
Transaction 2: Input StateB - ContractA and no output
Is this possible in Corda?
Please do share an example with response. Thanks.
推荐答案
是的,这是可能的.例如:
Yes, this is possible. For example:
@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))
}
}
这篇关于在Corda中,一个事务的输出可以被同一事务中的新事务使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文