Corda V3 错误 java.util.concurrent.ExecutionException

Corda V3 Error java.util.concurrent.ExecutionException

我今天从 Corda V2 升级到 Corda V3。 V2 上 运行 的程序将无法运行,请帮助我。 出现以下错误:-

[ERROR] 16:02:31,129 [qtp1715876585-27] (ExampleApi.java:226) api.ExampleApi.myMethod - java.io.NotSerializableException: net.corda.core.contracts.TransactionState -> data(net.corda.core.contracts.ContractState) -> Constructor parameter - "parameter_2" - doesn't refer to a property of "class com.example.state.MyState" -> class com.example.state.MyState {} java.util.concurrent.ExecutionException: java.io.NotSerializableException: net.corda.core.contracts.TransactionState -> data(net.corda.core.contracts.ContractState) -> Constructor parameter - "parameter_2" - doesn't refer to a property of "class com.example.state.MyState" -> class com.example.state.MyState

它出现在以下来源中。

flowHandle = rpcOps.startTrackedFlowDynamic(Myflow.Initiator.class, 
parameter1 ,parameter_2);
final SignedTransaction result = flowHandle
        .getReturnValue()
        .get();




public class MyState implements QueryableState,LinearState {
    private final Party partyA; 
    private final Party partyB; 
    private final int parameter_2
    private final UniqueIdentifier linearId;

    public Party getPartyA() {
        return partyA;
    }

    public Party getPartyB() {
        return partyB;
    }

    public int getParameter_2() {
        return parameter_2;
    }

    public MyState(Party partyA, Party partyB, int parameter_2) {
        this.partyA = partyA;
        this.partyB = partyB;
        parameter_2 = parameter_2;
        this.linearId = new UniqueIdentifier();
    }


    @Override
    public Iterable<MappedSchema> supportedSchemas() {
        return ImmutableList.of(new MySchemaV1());
    }

    @Override
    public PersistentState generateMappedObject(MappedSchema schema) {
        if (schema instanceof MySchemaV1){
            return new MySchemaV1.PersistentAA(
                    this.pratyA.getName().toString(),
                    this.partyB.getName().toString(),
                    this.parameter_2,
                    this.linearId.getId()
            );
        }else{
            throw new IllegalArgumentException("abnormal argument");
        }
    }

    @Override
    public List<AbstractParty> getParticipants() {
        return Arrays.asList(this.partyA,this.partyB);
    }

    @Override
    public String toString() {
        return  String.format(“%s(partyA=%s, partyB=%s, parameter2=%s, linearId=%s)",
                getClass().getSimpleName(),this.partyA,this.partyB,this.parameter_2,this.linearId);
    }

    @NotNull
    @Override
    public UniqueIdentifier getLinearId() {
        return this.linearId;
    }

}

你好像不能在Corda V3中为State的成员变量使用下划线。

在上面的示例代码中,当我们将"parameter 2"更改为"parameter 2"时,异常就不再出现了。

字段名中的下划线没有限制。例如,以下状态定义是有效的:

public class IOUState implements ContractState {
    private final Integer value_2;

    public IOUState(Integer value_2) { this.value_2 = value_2; }

    public Integer getValue_2() { return value_2; }

    @Override public List<AbstractParty> getParticipants() {
        return ImmutableList.of();
    }
}

你的代码中肯定有问题。