使用不同类型的状态作为输入和输出时,事务验证失败 [英] Transaction verification failed when using different type of states as input and output

查看:90
本文介绍了使用不同类型的状态作为输入和输出时,事务验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Corda事务,在此我使用一种类型的输入状态,同时创建另一种类型的状态作为输出,但是在验证输入和输出状态的过程中,使用相同的命令在不同的合同中对它们进行评估,因此验证部分失败.有什么方法可以使用命令针对第一个状态来评估输入合同,而使用另一个合同来验证输出状态.

I am trying to create a corda transaction where I am consuming one type of input state while creating another type of state as output but while verification the input and the output state are being evaluated using the same command in different contracts hence the verification part is failing. Is there any way through which the input contract would be evaluated using the command for the first state while output state would be verified using another contract.

在两个合同中,我都在做这样的事情:

In both contracts I am doing something like this:

val command = tx.commands.requireSingleCommand<Commands>()
when (command.value) {
    is Commands.Issue -> verifyIssue(tx, setOfSigners)
    is Commands.Transfer -> verifyTransfer(tx, setOfSigners)
    else -> throw IllegalArgumentException("Unrecognised command")
}

这是日志文件中的输出:

This is the output in the log file:

[WARN ] 2018-01-31T12:07:53,963Z [Node thread] flow.[51120088-7c8c-457b-b143-966b85e788cb].run - Flow finished with exception
net.corda.core.contracts.TransactionVerificationException$ContractRejection: Contract verification failed: Required com.template.AssetContract.Commands command, contract: com.template.AssetContract@53cc722e, transaction: 6FBE6CB29E2385C81683ED25C0A5CE21E07A18BE9DFD74AD47C45223138B35E6

推荐答案

您需要编写每个合同,以便它仅对某些类型的状态施加条件.例如,假设您有两种状态类型- XState YState -以及两种合同类型- XContract YContract .然后可以如下编写合同:

You need to write each contract so that it only imposes conditions on certain types of states. For example, suppose you have two state types - XState and YState - and two types of contract - XContract and YContract. Then could then write your contracts as follows:

class XContract : Contract {
    override fun verify(tx: LedgerTransaction) {
        val inputXStates = tx.inputsOfType<XState>()
        val outputXStates = tx.outputsOfType<XState>()

        requireThat {
            "All XState inputs are unapproved." using (inputXStates.all { it.approved == false })
            "All XState outputs are approved" using (outputXStates.all { it.approved == true })
        }
    }
}

并且:

class YContract : Contract {
    override fun verify(tx: LedgerTransaction) {
        val inputYStates = tx.inputsOfType<YState>()
        val outputYStates = tx.outputsOfType<YState>()

        requireThat {
            "All YState inputs are unaudited." using (inputYStates.all { it.audited == false })
            "All YState outputs are audited" using (outputYStates.all { it.audited == true })
        }
    }
}

这篇关于使用不同类型的状态作为输入和输出时,事务验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆