Corda 代币 SDK:"There is a token group with no assigned command" 错误

Corda Tokens SDK: "There is a token group with no assigned command" error

我已经解决了这个问题,但我想先了解一下为什么会这样:
1. 我正在使用 Tokens SDK
Java 模板 2. 我创建了自己的代币类型
3. 我修改了 ExampleFlowWithFixedToken class 发行我的新令牌
4.当我运行start ExampleFlowWithFixedToken amount: 100, recipient: PartyB时,我得到错误:There is a token group with no assigned command
5. 最初我的新令牌 class 没有实现 equals() 方法,当我添加它时;错误消失了,我可以发行我的令牌了。

为什么要添加那个方法,解决问题?

public class MyTokenType implements TokenType {

    private final int fractionDigits = 6;
    private final String tokenIdentifier = "MY_TOKEN";

    @NotNull
    @Override
    public BigDecimal getDisplayTokenSize() {
        return BigDecimal.ONE.scaleByPowerOfTen(-fractionDigits);
    }

    @Override
    public int getFractionDigits() {
        return fractionDigits;
    }

    @NotNull
    @Override
    public Class<?> getTokenClass() {
        return this.getClass();
    }

    @NotNull
    @Override
    public String getTokenIdentifier() {
        return tokenIdentifier;
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof MyTokenType;
    }
}

ExampleFlowWithFixedToken 调用内置的 IssueTokens Flow。 此流程在内部构建事务,指定输入、输出状态、命令(在本例中为 IssueCommand)。 下一步是验证合约。

在验证合约之前,我们按发行人对 input/output 代币进行分组。 然后为每个组分配一个令牌命令。 这样做是因为如果一笔交易包含不止一种类型的代币,它们需要按 IssuedTokenType 分组。 另请注意,不同发行人发行的相同类型的代币不可替代。 因此需要按 IssuedTokenType 分组。 一旦我们有了 IssuedTokenType 的组,合同验证就会为每个组单独完成。

当我们尝试为每个组分配令牌命令时,我们将命令中的 IssuedTokenType 与我们组中的一个进行比较。 因此,如果我们不覆盖 equals 方法,则组中 IssuedTokenType 的 none 将与 TokenCommand 中的匹配。

因此该组不会被分配任何 TokenCommand。 每个小组应该至少有一个命令。如果没有,那么我们将不知道如何处理该组。因此它没有说 "There is a token group with no assigned command"

希望对您有所帮助!