0
votes

I am trying to do a contract upgrade after I successfully authorised, I try to initiate the upgrade flow, but the counterparty is hitting an exception. So I'm wondering when/why this is happening.

At the springboot API

val states = queryUnconsumed<ObligationV1>

// Initiate upgrade contract flow.
states.forEach {

    val flowInitiate = services.startFlow({ stateAndRef, upgrade -> ContractUpgradeFlow.Initiate(stateAndRef, upgrade) }, it , ObligationContractV2::class.java)

    val resultInitiate = flowInitiate.returnValue.getOrThrow()
 }

In ContractUpgradeHandler

// Wouldn't this tx always be of type upgrade tx?
val oldStateAndRef = ourSTX!!.tx.outRef<ContractState>(proposal.stateRef.index)

But in SignedTransaction.kt

** Returns the contained [WireTransaction], or throws if this is a notary change or contract upgrade transaction. */
val tx: WireTransaction get() = coreTransaction as WireTransaction
[WARN ] 2018-08-20T10:25:03,573Z [Node thread-1] flow.[fe5bf9ea-fafc-40b6-9b51-31caaa4ee513].run - Terminated by unexpected exception {}
java.lang.ClassCastException: net.corda.core.transactions.ContractUpgradeWireTransaction cannot be cast to net.corda.core.transactions.WireTransaction
    at net.corda.core.transactions.SignedTransaction.getTx(SignedTransaction.kt:62) ~[corda-core-corda-3.0.jar:?]
    at net.corda.node.services.ContractUpgradeHandler.verifyProposal(CoreFlowHandlers.kt:57) ~[corda-node-corda-3.0.jar:?]
    at net.corda.core.flows.AbstractStateReplacementFlow$Acceptor.call(AbstractStateReplacementFlow.kt:149) ~[corda-core-corda-3.0.jar:?]
    at net.corda.core.flows.AbstractStateReplacementFlow$Acceptor.call(AbstractStateReplacementFlow.kt:129) ~[corda-core-corda-3.0.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96) [corda-node-corda-3.0.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) [corda-node-corda-3.0.jar:?]
    at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_181]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_181]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_181]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_181]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
    at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-corda-3.0.jar:?]

1
Can you add the code showing how you are invoking the upgrade?Joel
@Joel added the codeAdrian
are you able to share the code in a public repository somewhere?Joel

1 Answers

0
votes

The error message is pretty straight forward that it looks like you are trying to cast a ContractUpgradeWireTransaction to WireTransaction somewhere in your code.

Here is our recent tutorial on how to implement a contract upgrade on Corda: https://medium.com/corda/contract-upgrades-and-constraints-in-corda-425055a9a47f and here is the video tutorial: https://www.youtube.com/watch?v=rWyJRaoWNhc