Corda 在事务处理中,获取与特定状态关联的命令

Corda 在事务处理中,获取与特定状态关联的命令,corda,Corda,我有一个具有多个状态和多个命令的Corda事务。如何将每个状态与其对应的命令关联?事务中没有状态到命令的映射。每个事务都有一个或多个命令和一个或多个状态,但它们不需要以任何方式关联 但是,您通常会看到的模式是: 州的合同检查特定的命令类型 根据命令的类型,契约将检查有关状态的约束 例如: class MyContract : Contract { override fun verify(tx: LedgerTransaction) { val command = tx

我有一个具有多个状态和多个命令的Corda事务。如何将每个状态与其对应的命令关联?

事务中没有状态到命令的映射。每个事务都有一个或多个命令和一个或多个状态,但它们不需要以任何方式关联

但是,您通常会看到的模式是:

  • 州的合同检查特定的命令类型
  • 根据命令的类型,契约将检查有关状态的约束
例如:

class MyContract : Contract {
    override fun verify(tx: LedgerTransaction) {
        val command = tx.commands.requireSingleCommand<Commands>()

        when (command.value) {
            is Commands.MyCommand1 -> {
                if (tx.inputStates.size != 1) 
                    throw IllegalArgumentException("When its a MyCommand1 transaction, there must be one input.")
                TODO("More checking.")
            }

            is Commands.MyCommand2 -> {
                if (tx.inputStates.size != 2)
                    throw IllegalArgumentException("When its a MyCommand1 transaction, there must be two inputs.")
                TODO("More checking.")
            }
        }

    }

    interface Commands : CommandData {
        class MyCommand1 : Commands
        class MyCommand2 : Commands
    }
}
class MyContract:合同{
覆盖验证(tx:LedgertTransaction){
val command=tx.commands.requireSingleCommand()
何时(命令值){
is Commands.MyCommand1->{
如果(tx.inputStates.size!=1)
抛出IllegalArgumentException(“当它是MyCommand1事务时,必须有一个输入。”)
待办事项(“更多检查”)
}
is Commands.MyCommand2->{
如果(tx.inputStates.size!=2)
抛出IllegalArgumentException(“当它是MyCommand1事务时,必须有两个输入。”)
待办事项(“更多检查”)
}
}
}
接口命令:CommandData{
类MyCommand1:命令
类MyCommand2:命令
}
}

这是我为我的用例所做的

class Reject(val linearIds: List<UniqueIdentifier>) : TypeOnlyCommandData(), Commands


val correspondingStatesToEnforce = tx.inputsOfType<Obligation>()
.filter { it.linearId in command.linearIds }

require(...)
class拒绝(val-linearIds:List):TypeOnlyCommandData(),命令
val correspondingStatesToEnforce=tx.InputSoftType()
.filter{it.linearId in command.linearIds}
要求(…)