corda - 验证交易
问题描述
我需要一些帮助来了解交易验证在 Corda 中的工作原理。如果我理解正确,交易中的所有各方都有责任自己验证。
我有一个与两方之间的协商 cordapp非常相似的用例。在编写流程时,我会在发起方中验证未签名的交易:
// build the state that will be used as an output
val utx = TransactionBuilder(notary)
.addInputState(input)
.addOutputState(output)
.addCommand(RequestContract.Commands.Accept(), output.participants.map { it.owningKey })
// verify the transaction against the smart contract
utx.verify(serviceHub)
// Sign the transaction.
val ptx = serviceHub.signInitialTransaction(utx, ourIdentity.owningKey)
在响应者中,我还需要验证交易。
val signTransactionFlow = object : SignTransactionFlow(counterpartySession) {
override fun checkTransaction(stx: SignedTransaction) {
val state = stx.tx.outputStates.single() as RequestState
requireThat {
"Fulfilling a request has to be initiated by the fulfilling party" using (state.requestingParty == ourIdentity)
}
}
}
val stx = subFlow(signTransactionFlow)
// verify the transaction against the smart contract
stx.verify(serviceHub, checkSufficientSignatures = false)
return subFlow(ReceiveFinalityFlow(counterpartySession, stx.id))
除非我设置checkSufficientSignatures = false
,否则我会收到签名丢失的错误 ( SignedTransaction$SignaturesMissingException
)。
为什么我会收到错误消息?我在发起者和响应者流程中签署了交易。checkSufficientSignatures
如果我设置为 false ,如何确保所有签名都存在?最后,为什么在创建时没有出现错误RequestState
,双方都是签名者,并且流程的构建几乎相同?
解决方案
- 我没有看到你打电话
CollectSignaturesFlow
给发起人;没有那个电话,你将如何要求对方签字? - 不需要调用
verify()
响应者,如果你打开代码SignTransactionFlow()
你会在这里看到它收到交易时;它解决并验证导致此交易的所有交易(包括此交易)。因此,您可以安全地删除该呼叫。
推荐阅读
- mysql - MySQL undo log 不断增长
- java - 共享首选项重新调整为 null
- javafx - 在javafx中画一条带过渡的线
- c++ - 子程序,不使用 pow,带参数和返回
- java - 当我使用 requestDispatcher.forward 函数时,为什么我的代码没有打印正确的结果?
- mysql - 无法使用 docker 容器连接到 MySQL 数据库
- syntax - 中间人在使用 link_to 块时显示语法错误
- mongodb - MongoDb 两个集合还是一个?
- c++ - 使用 bfs 解决连接组件问题时得到错误答案
- java - Java 无法通过 JPA 连接到 mySQL