如何覆盖AbstractTokenContract上的dispatchOnCommand并创建新的命令?

问题描述 投票:0回答:1

UpdateTokenCommand是我要在AbstractTokenContract中添加的那个

override fun dispatchOnCommand(commands: List<CommandWithParties<TokenCommand>>, inputs: List<IndexedState<WalletState>>, outputs: List<IndexedState<WalletState>>, attachments: List<Attachment>) {
        super.dispatchOnCommand(commands, inputs, outputs, attachments)
        when (commands.first().value) {
            // Issuances should only contain one issue command.
            is IssueTokenCommand -> verifyIssue(commands.single(), inputs, outputs, attachments)
            // Moves may contain more than one move command.
            is MoveTokenCommand -> verifyMove(commands, inputs, outputs, attachments)
            // Redeems must only contain one redeem command.
            is RedeemTokenCommand -> verifyRedeem(commands.single(), inputs, outputs, attachments)
            // Transfer Command
            is UpdateTokenCommand -> verifyUpdate(commands.single(), inputs, outputs, attachments)
        }
    }
corda
1个回答
0
投票

[在kotlin(https://github.com/corda/samples-kotlin/blob/master/Advanced/obligation-cordapp/contracts-kotlin/src/main/kotlin/net/corda/training/contracts/IOUContract.kt)中查看此示例

要注意的是,此合同示例中的IOUState实际上是如何查看命令类型的,以确定合同将如何验证该资产上的交易。

override fun verify(tx: LedgerTransaction) {
    val command = tx.commands.requireSingleCommand<IOUContract.Commands>()
    when (command.value) {
        is Commands.Issue -> requireThat {
© www.soinside.com 2019 - 2024. All rights reserved.