我想在Java项目中运行ContractUpgradeFlow.Initiate流。像这样:

 CordaRPCOps proxy = client.start(rpcUsername, rpcPassword).getProxy();
 proxy.startFlowDynamic(ContractUpgradeFlow.Initiate.class,stateAndRef,newContractClass.class);


但有错误:

Required type:Class<? extends FlowLogic<? extends T>>
Provided     :Class<Initiate>
reason: no instance(s) of type variable(s) T exist so that Initiate conforms to FlowLogic<? extends T>


kotlin版本是这样的:
https://github.com/corda/samples/blob/release-V4/explicit-cordapp-upgrades/src/main/kotlin/com/upgrade/client/ClientWithLegacyConstraint.kt
我如何在Java项目中运行ContractUpgradeFlow.Initiate?

最佳答案

由于某些原因,ContractUpgradeFlow.Initiate未标识为FlowLogic类型。可能是因为它不是FlowLogic的直接子类型。感谢您指出这一点,我为此提出了一个错误。

但是,您可以使用一种变通方法来解决此问题,创建新的流,并将ContractUpgradeFlow.Initiate称为子流。

@InitiatingFlow
@StartableByRPC
public class ExplicitUpgradeFlow extends FlowLogic<Void> {

    private final StateAndRef oldStateAndRef;
    private final Class newContractClass;

    public ExplicitUpgradeFlow(StateAndRef oldStateAndRef, Class newContractClass) {
        this.oldStateAndRef = oldStateAndRef;
        this.newContractClass = newContractClass;
    }

    @Override
    public Void call() throws FlowException {

        subFlow(new ContractUpgradeFlow.Initiate(oldStateAndRef, newContractClass));
        return null;
    }
}

07-24 09:27