corda / net.corda.core.contracts / UpgradedContract

UpgradedContract

interface UpgradedContract<in OldState : ContractState, out NewState : ContractState> : Contract

Interface which can upgrade state objects issued by a contract to a new state object issued by a different contract. The upgraded contract should specify the legacy contract class name, and provide an upgrade function that will convert legacy contract states into states defined by this contract.

In addition to the legacy contract class name, you can also specify the legacy contract constraint by implementing UpgradedContractWithLegacyConstraint instead. Otherwise, the default WhitelistedByZoneAttachmentConstraint will be used for verifying the validity of an upgrade transaction.

Parameters

OldState - the old contract state (can be ContractState or other common supertype if this supports upgrading more than one state).

NewState - the upgraded contract state.

Properties

legacyContract

abstract val legacyContract: ContractClassName

Name of the contract this is an upgraded version of, used as part of verification of upgrade transactions.

Functions

upgrade

abstract fun upgrade(state: OldState): NewState

Upgrade contract's state object to a new state object.

Inherited Functions

verify

abstract fun verify(tx: LedgerTransaction): Unit

Takes an object that represents a state transition, and ensures the inputs/outputs/commands make sense. Must throw an exception if there's a problem that should prevent state transition. Takes a single object rather than an argument so that additional data can be added without breaking binary compatibility with existing contract code.

Extension Functions

contextLogger

fun Any.contextLogger(): Logger

When called from a companion object, returns the logger for the enclosing class.

Inheritors

UpgradedContractWithLegacyConstraint

interface UpgradedContractWithLegacyConstraint<in OldState : ContractState, out NewState : ContractState> : UpgradedContract<OldState, NewState>

This interface allows specifying a custom legacy contract constraint for upgraded contracts. The default for UpgradedContract is WhitelistedByZoneAttachmentConstraint.