Corda 验证事务

Corda 验证事务,corda,Corda,我需要一些帮助来了解如何在Corda中验证事务。如果我理解正确,那么交易中的所有各方都有责任自行验证 我有一个非常类似于两方之间的用例。写入流时,我在启动器中验证未签名的事务: // build the state that will be used as an output val utx = TransactionBuilder(notary) .addInputState(input) .addOutputState(output) .addCommand(Requ

我需要一些帮助来了解如何在Corda中验证事务。如果我理解正确,那么交易中的所有各方都有责任自行验证

我有一个非常类似于两方之间的用例。写入流时,我在启动器中验证未签名的事务:

// 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))
除非我设置了
checksulficientsignatures=false
,否则我会得到一个签名丢失的错误(
SignedTransaction$SignaturesMissingException

为什么我会出错?我在发起方和响应方流中对事务进行了签名。如果我将
checksulficientsignatures
设置为false,如何确保所有签名都存在?最后,为什么在创建
RequestState
时没有出现错误,因为双方都是签名者,并且流的构建方式几乎相同

  • 我没有看到您在启动器中调用
    CollectSignaturesFlow
    ;没有那个电话,你怎么要求对方签字
  • 无需在响应程序中调用
    verify()
    ,如果打开
    SignTransactionFlow()
    的代码,您将在它接收到事务时看到;它解析并验证导致此事务的所有事务(包括此事务)。这样您就可以安全地删除该呼叫

  • 我在签名后立即调用
    CollectSignaturesFlow
    ,不想在示例中包含太多代码。我不知道我不需要在应答器中呼叫验证,谢谢!