首页 > 解决方案 > 实现状态更新的流程,我们是否必须使用 SendTransaction

问题描述

我正在尝试实现状态更新流,那么我如何传递输入状态,我可以为 updation_flow 和问题流创建一个单独的文件,我是否必须使用 SendtransactioFlow 作为子流?

我已经传入输入状态建立交易,不知道是否正确请验证。

将输入状态添加到事务构建器中的事务的代码

// We create a transaction builder and add the components.
val hashasint: Int =  serviceHub.vaultService.hashCode()
val convertostring: String =   hashasint.toString()
val ourStateRef = StateRef(SecureHash.sha256(convertostring), 0)
val inputState: StateAndRef<KycState> = serviceHub.toStateAndRef(ourStateRef)
val txBuilder = TransactionBuilder(notary = notary)
        .addOutputState(outputState, KycContract.ID)
        .addCommand(command)
        .addInputState(inputState)

用于实现状态更新流程的代码

val signedTx = serviceHub.signInitialTransaction(txBuilder)

// Creating a session with the other party.
val otherPartySession = initiateFlow(otherParty)   // i think here is where the actual link to other node starts
subFlow(SendTransactionFlow(otherPartySession,signedTx))

// Obtaining the counterparty's signature.
val fullySignedTx = subFlow(CollectSignaturesFlow(signedTx, listOf(otherPartySession), CollectSignaturesFlow.tracker()))

// We finalise the transaction and then send it to the counterparty.
subFlow(FinalityFlow(fullySignedTx, otherPartySession))

更新流程是否需要使用 SendTransactionFlow。

标签: kotlincorda

解决方案


SendTransactionFlow 在 FinalityFlow 中调用。无需单独调用。请参阅下面的链接 -

https://github.com/corda/corda/blob/master/core/src/main/kotlin/net/corda/core/flows/FinalityFlow.kt

另请参阅 SO- Corda 在 finalityFlow 中行走链


推荐阅读