UpgradedContract
Keywords: net.corda.core.contracts.UpgradedContract interface
Date: 2023-09-18

net.corda.core.contracts

## Interface UpgradedContract<OldState extends ContractState,NewState extends ContractState>

- Type Parameters:
    `OldState` -

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

    `NewState` -

    the upgraded contract state.

  All Superinterfaces:
    Contract
  All Known Subinterfaces:
    UpgradedContractWithLegacyConstraint<OldState,NewState>

      public UpgradedContract<OldState extends ContractState,NewState extends ContractState>
      extends 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 `interface UpgradedContractWithLegacyConstraint` instead. Otherwise, the default `class WhitelistedByZoneAttachmentConstraint` will be used for verifying the validity of an upgrade transaction.

  See Also:
    `interface UpgradedContractWithLegacyConstraint`, `class WhitelistedByZoneAttachmentConstraint`

- - ### Constructor Detail

    - #### UpgradedContract

          public UpgradedContract()

  - ### Method Detail

    - #### getLegacyContract

          @NotNull
          java.lang.String getLegacyContract()

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

    - #### upgrade

          @NotNull
          NewState upgrade(@NotNull
                                    OldState state)

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

      Throws:
        `IllegalArgumentException` - if the given state object is not one that can be upgraded. This can be either that the class is incompatible, or that the data inside the state object cannot be upgraded for some reason.