在琴弦,可以在一个事务处理的输出可以通过新的事务处理在相同的流中使用的?(In Corda, can

2019-10-30 01:50发布

有一个流程按照下面的情形。
交易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?
标签: kotlin corda