如何重写AbstractTokenContract上的dispatchOnCommand并创建一个新的命令? [英] How to override the dispatchOnCommand on the AbstractTokenContract and create a new commmand?

查看:28
本文介绍了如何重写AbstractTokenContract上的dispatchOnCommand并创建一个新的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UpdateTokenCommand是我要在AbstractTokenContract中添加的

The UpdateTokenCommand is the one that I want to add in the 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)
        }
    }

推荐答案

在kotlin中查看此示例(

Take a look at this example in kotlin (https://github.com/corda/samples-kotlin/blob/master/Advanced/obligation-cordapp/contracts-kotlin/src/main/kotlin/net/corda/training/contracts/IOUContract.kt)

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

The thing to notice is how the IOUState in this contract example actually looks at the command type to determine HOW the contract will verify the transaction on that asset.

override fun verify(tx: LedgerTransaction) {
    val command = tx.commands.requireSingleCommand<IOUContract.Commands>()
    when (command.value) {
        is Commands.Issue -> requireThat {

这篇关于如何重写AbstractTokenContract上的dispatchOnCommand并创建一个新的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆