首页 > 解决方案 > 如何为 FungibleToken 创建新命令

问题描述

如何为 FungibleToken 创建新命令?
这是 FungibleTokenContract 文档。

 * The [FungibleToken] contract sub-classes the [AbstractToken] contract which contains the "verify" method.
 * To add functionality to this contract, developers should:
 * 1. Create their own commands which implement the [TokenCommand] interface.
 * 2. Override the [AbstractTokenContract.dispatchOnCommand] method to add support for the new command, remembering
 *    to call the super method to handle the existing commands.
 * 3. Add a method to handle the new command in the new sub-class contract.

但是如何覆盖 [AbstractTokenContract.dispatchOnCommand] 方法?

标签: corda

解决方案


您可以重写 AbstractTokenContract 的所有方法,就像在任何 Abstract 类中一样,如下所示:

class ExampleTokenContract: AbstractTokenContract<FungibleToken>() {

    override val accepts: Class<FungibleToken> get() = uncheckedCast(FungibleToken::class.java)

    override fun dispatchOnCommand(
            commands: List<CommandWithParties<TokenCommand>>,
            inputs: List<IndexedState<AT>>,
            outputs: List<IndexedState<AT>>,
            attachments: List<Attachment>,
            references: List<StateAndRef<ContractState>>
) {
        // do some logic
  }}

推荐阅读