corda - 执行 ContractUpgradeFlow 后状态合同不会改变
问题描述
我尝试按照这篇文章https://docs.corda.net/contract-upgrade.html升级合同, 然后在执行 ContractUpgradeFlow 后没有错误,但是当查询保险库时,它似乎状态仍然属于旧合同。
在表中它已经插入到 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
}
我期望旧合同的状态应该与新合同进行交易还是我误解了概念?
解决方案
作为我的调查。这是因为用 new_contract.jar 替换 old_contract.jar 使合约的约束,然后 Corda 不让合约升级流程。所以我的解决方案是在执行 ContractUpgradeFlow 之前更新网络参数。
推荐阅读
- javascript - DFP 广告管理系统 (DFP) 解决方案上的 Adobe Flash Animate CC HTML5 广告
- haskell - 函数 buildTree' Haskell 中的非详尽模式
- php - 通过 POST 接收的 HTML 实体与在同一页面中创建的实体不可比较
- mysql - 无法连接到通过 Route53 托管的 RDS 只读副本的域名
- mysql - mysql: [错误] 未知变量 'sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE
- kubernetes - Traefik Dashboard - 自定义 API 路径
- spring - AspectJ LTW 未在 Tomcat 中配置 Spring
- tsql - 从另一个表中查找最近 90 天内的记录并返回相关列
- javascript - 在 Angular 8 项目中导入传单控制地理编码器?
- mysql - 在 MySQL 数据库上激活远程访问