【问题标题】:In Corda, can the output of one transaction be used by new transaction in the same flow?在 Corda 中,一个事务的输出可以被同一流中的新事务使用吗?
【发布时间】:2018-10-23 16:20:11
【问题描述】:

根据以下场景有一个流程。
事务 1:输入 StateA - ContractA 导致输出 StateB - ContractA
事务 2:输入 StateB - ContractA 并且没有输出
这在 Corda 中可能吗? 请务必与响应分享一个示例。谢谢。

【问题讨论】:

    标签: kotlin corda


    【解决方案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))
        }
    }
    

    【讨论】:

    • 非常感谢,这有帮助。此外,如果我们有多个签名者,即它如何与 CollectSignaturesFlow 一起使用?
    • 没问题。请您提出一个单独的问题吗?
    • 谢谢。我提出了一个单独的问题,这是链接:stackoverflow.com/questions/52983150/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    相关资源
    最近更新 更多