执行ContractUpgradeFlow后状态合同不会更改

时间:2019-01-25 07:44:55

标签: corda

我尝试根据本文https://docs.corda.net/contract-upgrade.html升级合同 然后执行ContractUpgradeFlow之后没有错误,但是当查询文件库时,状态似乎仍属于旧合同。

在表中,它已经插入到node_contract_upgrades

table = node_contract_upgrades

但是当从库中查询状态时,我仍然有旧合同,并且如果我使用(旧状态+新合同)进行交易,则会显示合同约束

Flow Internal Error : java.util.concurrent.ExecutionException: net.corda.core.contracts.TransactionVerificationException$ContractConstraintRejection: Contract constraints failed for th.co.jventures.ddlp.cordapp.contracts.CustomerContractV01, transaction: 418A9A1562A1A7F3C465EC2CC5DDEFB83F5D9C71269EDF83BFBA1094274F926F

在这里,我的client.kt用于运行流升级

       <pre>`<pre>fun main(args: Array<String>) {
        UpgradeContractClient().main(args)
    }

    /**
     *  A utility demonstrating the contract upgrade process.
     *  In this case, we are upgrading the states' contracts, but not the states
     *  themselves.
     **/
    private class UpgradeContractClient {
        companion object {
            val logger: Logger = loggerFor<UpgradeContractClient>()
        }

        fun main(args: Array<String>) {


            val clientDs = CordaRPCClient(parse("localhost:10009"))
            val dsProxy = clientDs.start("user1", "test").proxy

            val clientPah = CordaRPCClient(parse("localhost:10008"))
            val pahProxy = clientPah.start("user1", "test").proxy

            // Authorise the upgrade of all the State instances using OldContract.
            println("Doing Authorise")
            listOf(dsProxy, pahProxy).forEach { proxy ->
                // Extract all the unconsumed State instances from the vault.
                val stateAndRefs = proxy.vaultQuery(CustomerStateV01::class.java).states
                println("Found customerState=${stateAndRefs.size} for node : ${proxy.nodeInfo()}")

                // Run the upgrade flow for each one.
                stateAndRefs.filter { stateAndRef ->
                    stateAndRef.state.contract == CustomerContractV01.CONTRACT_ID
                }.forEach { stateAndRef ->
                    proxy.startFlowDynamic(
                            ContractUpgradeFlow.Authorise::class.java,
                            stateAndRef,
                            CustomerContractV02::class.java).returnValue.getOrThrow()
                }

                println("Finished")

            }
            Thread.sleep(5000)

            // Initiate the upgrade of all the State instances using OldContract.
            println("Doing Initiate")
            dsProxy.vaultQuery(CustomerStateV01::class.java).states
                    .filter { stateAndRef ->
                        stateAndRef.state.contract == CustomerContractV01.CONTRACT_ID
                    }
                    .forEach { stateAndRef ->
                        dsProxy.startFlowDynamic(
                                ContractUpgradeFlow.Initiate::class.java,
                                stateAndRef,
                                CustomerContractV02::class.java)
                    }

            // Log all the State instances in the vault to show they are using NewContract.
            dsProxy.vaultQuery(CustomerStateV01::class.java).states.forEach { println("${it.state}") }
            dsProxy.vaultQuery(CustomerStateV01::class.java).states.forEach { println("${it.state.contract}") }
        }}`

这是我的合同V02

class CustomerContractV02 : UpgradedContract<CustomerStateV01, CustomerStateV01>{
override val legacyContract: ContractClassName
    get() = CustomerContractV01.CONTRACT_ID


override fun upgrade(state: CustomerStateV01): CustomerStateV01 {
    return state
}

我期望旧合同的状态应该与新合同进行交易,还是我误解了概念?

1 个答案:

答案 0 :(得分:0)

作为我的调查。这是因为用new_contract.jar替换了old_contract.jar使得合同受到约束,然后Corda不允许合同升级。因此,我的解决方案是在执行ContractUpgradeFlow之前更新网络参数。