实现更新状态的流程,我们是否必须使用 SendTransaction

Implementing flow for Updation of state , do we have to use SendTransaction

我正在尝试实现状态更新流程,那么我该如何传递输入状态,我能否为 updation_flow 创建一个单独的文件并发布流程,我是否必须使用 SendtransactioFlow作为子流?

我已经通过input状态建立交易,不知道是否正确请验证。

将输入状态添加到事务生成器中的事务的代码

// 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。

要更新状态,您需要从保险库中获取状态并将其用作交易生成器中的输入状态。要从保险库中获取状态,您可以使用 vaultQuery。这是一个例子:

List<StateAndRef<MyState>> myStateAndRefs = getServiceHub().getVaultService().queryBy(MyState.class).getStates();

如果您想要过滤后的结果,可以使用 QueryCriteria。 有关更多信息,请参阅此处:https://docs.corda.net/api-vault-query.html

SendTransactionFlow 通常不需要更新状态。在发起人没有他想要更新的状态的情况下,这将是必需的,在这种情况下,他需要向交易对手请求输入状态。因为在这种情况下,他不会拥有相关状态的交易链,他将不得不使用 SendTransactionFlow 从交易对手那里请求相同的交易链。这是必需的,因为发起者需要遍历从状态发布到当前状态的交易链,以验证他所提供状态的真实性。

在 FinalityFlow 中调用了 SendTransactionFlow。无需单独调用。 见下文 link -

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

另请参阅 SO - Corda Walking the Chain in finalityFlow