How to upgrade stateV1 to V2 without changing the Contract version?
How to upgrade stateV1 to V2 without changing the Contract version?
I have an ObligationV1
and two states ObligationStateV1
and ObligationStateV2
.
ObligationV1
ObligationStateV1
ObligationStateV2
How do I achieve A state is upgraded while the contract stays the same.
where the state goes from V1 to V2 without changing the contract version. Based on the examples exampleLink, docs
A state is upgraded while the contract stays the same.
It seems that the code will end up looking like this where you have a new ObligationContractV2? The example was trying to achieveThis CorDapp shows how to upgrade a state without upgrading the Contract.
But I don't see how does the implementation actually prove that the new states is still referring to the old contract?
This CorDapp shows how to upgrade a state without upgrading the Contract.
1 Answer
1
The contract class must change whenever you upgrade a state, but the rules it imposes can remain the same.
You could achieve this by delegating the transaction checking to the old contract:
override fun verify(tx: LedgerTransaction) {
ObligationContractV1().verify()
}
You could also delegate the checking to the old contract, and adding additional checks:
override fun verify(tx: LedgerTransaction) {
ObligationContractV1().verify()
additionalChecks()
}
However, note that delegating verify
in this way while upgrading states will only work if the original contract isn't hardcoded to verify the transaction in terms of the old state. You'd have to write the original contract in terms of some interface or abstract class implemented by both the old state class and the new state class, or in some other way write the old contract in an open-ended manner. If you didn’t write the old contract in this forward-thinking way initially, you'll have to re-write the verify
method.
verify
verify
Sorry, I'll update my answer.
– Joel
Jun 26 at 11:18
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
But the intention here is to upgrade state without contract. How do I do that without needing to up the contract version?
– Adrian
Jun 26 at 10:12