首先,我3个月前才开始学习corda,所以我还有一些学习要做。
我继承了一些在CordaV3.3下运行良好的代码,但客户希望它能在v4上运行。我正试着按照主网站上的说明去做。我有一个启动流,它调用一个子流,而子流又调用一个转发器流。
启动流:
@InitiatingFlow(version = 2)
@StartableByRPC
class TransferFlow(private val issuerName: String = "",
private val seller: String = "",
private val amount: BigDecimal = BigDecimal("0"),
private val buyer: String = "",
private val custodianNameOfBuyer: String = "",
private val notaryName: String = "") : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
subFlow(UpdateStatusOfTransferFlow(
sessions,
tokenTransferAgreement.linearId,
"Removed Tokens From Seller"))
}
}
class UpdateStatusOfTransferFlow(
private val sessions: Set<FlowSession>,
private val tokenTransferAgreementID: UniqueIdentifier,
private val newStatus: String) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
sessions.size
val idQueryCriteria = QueryCriteria.LinearStateQueryCriteria(linearId = listOf(tokenTransferAgreementID))
val states = serviceHub.vaultService.queryBy<TokenTransferAgreement>(idQueryCriteria).states
if (states.size != 1) throw FlowException("Can not find a unique state for $tokenTransferAgreementID")
val inputStateAndRef = states.single()
val inputState = inputStateAndRef.state.data
val notary = inputStateAndRef.state.notary
val outputState = inputState.withNewStatus(newStatus)
val cmd = Command(TokenContract.Commands.UpdateStatusOfTransfer(),
inputState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary = notary)
txBuilder.addCommand(cmd)
txBuilder.addInputState(inputStateAndRef)
txBuilder.addOutputState(outputState, TokenContract.ID)
txBuilder.verify(serviceHub)
val ptx = serviceHub.signInitialTransaction(txBuilder)
val sessions2 = (inputState.participants.toSet() - ourIdentity).map { initiateFlow(it) }
return subFlow(CollectSignaturesFlow(ptx, sessions2))
}
}
And the responder:
@InitiatedBy(TransferFlowResponder::class)
class UpdateStatusOfTransferFlowResponder(private val session: FlowSession) : FlowLogic<Unit>() {
@Suspendable
override fun call() {
val tokenTransferAgreements = mutableListOf<TokenTransferAgreement>()
var isBuyer = true
var notary = CordaUtility.getNotary(serviceHub) ?: throw FlowException("An notary is expected!")
val signedTransactionFlow = subFlow(object : SignTransactionFlow(session) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
"There must be one output!" using (stx.tx.outputStates.size == 1)
val tokenTransferAgreement = stx.tx.outputStates.first() as TokenTransferAgreement
tokenTransferAgreements.add(tokenTransferAgreement)
notary = stx.notary ?: throw FlowException("An notary is expected!")
if (ourIdentity == tokenTransferAgreement.issuer) {
//checks go here
}
})
}
}我相信我应该在某个时刻添加一个对ReceiveFinality flow的调用,但是它只需要一个会话作为参数,而不是像我在这里使用的列表。我是否应该进行多个调用,每个会话一个?我也不确定调用应该放在转发器还是UpdateStatusOfTransferFlow类中。
如果能帮上忙,我们将不胜感激。
发布于 2019-05-07 18:47:58
FinalityFlow主要负责确保交易经过公证、相应地分发并持久保存到本地保管库。
在以前的Corda版本中,默认情况下,所有节点都会接受传入的终结性请求。
从V4开始,您需要编写一个ReceiveFinalityFlow,以便在finality之前编写自己的处理逻辑。
finality当前在Corda中运行的方式是发起节点,作为finality期间的中间步骤,将经公证的交易分发给所有其他参与者。它发送到的每个参与节点将仅期望从该节点接收会话。
因此,在您可能向发起FinalityFlow提交多个会话以包括所有参与者的情况下,响应节点将仅从发起者接收一个会话。
将来,我们可能会考虑让公证员将经过公证的交易分发给所有参与者,但即使这样,ReceiveFinalityFlow仍然只会期待一个会话,这次是公证员。
https://stackoverflow.com/questions/56015652
复制相似问题