cosmwasm-contract-migratable-std 0.1.0

A collection of standardized messages, state structs, and helper functions a contract can use to implement contract migration.
Documentation
use cosmwasm_std::{Binary, ContractInfo};
use serde::{Deserialize, Serialize};

/// key for MigratedFrom singleton
pub static MIGRATED_FROM_KEY: &[u8] = b"migratedFrom";
/// key for MigratedTo singleton
pub static MIGRATED_TO_KEY: &[u8] = b"migratedTo";
/// key for Vec<ContractInfo> of contracts to notify when this contract has been migrated
pub static NOTIFY_ON_MIGRATION_COMPLETE_KEY: &[u8; 16] = b"notifyOnMigrated";
/// key for current ContractMode
pub const CONTRACT_MODE_KEY: &[u8] = b"contractMode";


#[derive(serde_repr::Serialize_repr, serde_repr::Deserialize_repr, Debug, PartialEq)]
#[repr(u8)]
pub enum ContractMode {
    MigrateDataIn = 1,
    Running = 2,
    // MigrateOutStarted is applicable when a migration can take more than one transaction to complete
    // For example when migrating a snip721 contract. A takes a least two transactions
    // The first execute migration message put's the contract in this state.
    // Which disables the contract's state from being altered but allows queries until migration
    // is complete (after all the tokens are migrated in a second transaction).
    // After all tokens are migrated. the contract switches to ContractMode::MigratedOut
    MigrateOutStarted = 3,
    MigratedOut = 4,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct MigratedFromState {
    /// the info of the contract being migrated from
    pub contract: ContractInfo,
    /// the secret generated by the contract being migrated from
    pub migration_secret: Binary,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct MigratedToState {
    /// the info of the contract being migrated to
    pub contract: ContractInfo,
    /// the secret needed by another contract to migrate data out
    pub migration_secret: Binary,
}