Search code examples
javacorda

Corda explict upgrades(Java)


i want to run ContractUpgradeFlow.Initiate flow in java project. just like this:

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

but has error :

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>

the kotlin version is this: https://github.com/corda/samples/blob/release-V4/explicit-cordapp-upgrades/src/main/kotlin/com/upgrade/client/ClientWithLegacyConstraint.kt
How can i run ContractUpgradeFlow.Initiate in java project?


Solution

  • For some reason ContractUpgradeFlow.Initiate is not identified as FlowLogic type. probably because it is not a direct sub-type of FlowLogic. Thanks for pointing this out, I would raise a bug for this.

    However, you could use a workaround to get around this, create a new flow and call the ContractUpgradeFlow.Initiate as a sub-flow.

    @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;
        }
    }