在 corda 中调用流时出现交易验证异常



我有一个合约,它使用类型A的输入来产生类型B的输出,我的合约看起来类似,如图所示

override fun verify(tx: LedgerTransaction) {
val commandCreate = tx.commands.requireSingleCommand<Commands.Create>()
requireThat {
"One input state should be there for TypeB" using (tx.inputStates.size==1)
"One output states should be there for TypeB" using (tx.outputStates.size==1)
"Input State should be a TypeA" using (tx.getInput(0) is TypeAState)
"Output State should be a TypeB" using(tx.getOutput(0) is TypeBState)
"TypeA id Number should not be empty" using((tx.getInput(0) as TypeAState).idNumber.isNotEmpty())

}

我在调用流时收到以下错误

java.util.concurrent.ExecutionException: net.corda.core.contracts.TransactionVerificationException$ContractRejection: 合同验证失败:必需 com.example.contract.PolicyContract.Command.Create command, contract: com.example.contract.policyContract, transaction: B2AE49DEDFE882C9DDBA9ECB35740A689CFDC4F8ED78DD43D912FDC9DC5DC2C4

我的流如下所示

val txCommand = Command(TypeBContract.Commands.Create(), listOf(me.owningKey))
val txBuilder = TransactionBuilder(notary)
.addInputState(typeARef)
.addOutputState(outputState, TYPEB_CREATION_CONTRACT_ID)
.addCommand(txCommand)

我哪里做错了??

问题是requireSingleCommand.创建具有输入状态的事务时,输入状态包含在另一个事务中的命令也将在此处加载。

要解决此问题,请使用tx.commandsOfType<YourType>()或任何语法。这不会引发异常。当事务中有输入和输出时,应使用此解决方案。

异常是由于在requireSingleCommand中调用single

最新更新