调用corda中的流时发生事务验证异常
我有一个合同,它使用typeA的输入来产生typeB的输出,我的合同看起来与图中所示类似调用corda中的流时发生事务验证异常,corda,Corda,我有一个合同,它使用typeA的输入来产生typeB的输出,我的合同看起来与图中所示类似 override fun verify(tx: LedgerTransaction) { val commandCreate = tx.commands.requireSingleCommand<Commands.Create>() requireThat { "One input state should be there for TypeB" usin
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())
我哪里出错了???问题是
requireSingleCommand
。创建具有输入状态的事务时,输入状态包含在另一个事务中的命令也将在此处加载
要解决此问题,请使用tx.commandsOfType()
或任何语法。这不会引发异常。当事务中存在输入和输出时,应该使用此解决方案
异常是由于在requireSingleCommand
中调用了single
val txCommand = Command(TypeBContract.Commands.Create(), listOf(me.owningKey))
val txBuilder = TransactionBuilder(notary)
.addInputState(typeARef)
.addOutputState(outputState, TYPEB_CREATION_CONTRACT_ID)
.addCommand(txCommand)