Reputation: 367
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
Upvotes: 0
Views: 615
Reputation: 23140
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 })
}
}
}
And:
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 })
}
}
}
Upvotes: 2