57 releases (6 stable)

2.0.0 Mar 15, 2024
1.1.2 Nov 23, 2023
1.1.0 Jun 19, 2023
1.0.1 Dec 19, 2022
0.3.2 Oct 28, 2020

#1422 in Magic Beans

Download history 10299/week @ 2024-01-03 11710/week @ 2024-01-10 11838/week @ 2024-01-17 11457/week @ 2024-01-24 12173/week @ 2024-01-31 15120/week @ 2024-02-07 16775/week @ 2024-02-14 12660/week @ 2024-02-21 12320/week @ 2024-02-28 14689/week @ 2024-03-06 17480/week @ 2024-03-13 14271/week @ 2024-03-20 12611/week @ 2024-03-27 13084/week @ 2024-04-03 11111/week @ 2024-04-10 9678/week @ 2024-04-17

49,281 downloads per month
Used in 414 crates (252 directly)

Apache-2.0

15KB
202 lines

CW2 Spec: Contract Info

Most of the CW* specs are focused on the public interfaces of the contract – the APIs used for ExecuteMsg or QueryMsg. However, when we wish to migrate or inspect smart contract info, we need some form of smart contract information embedded on state.

This is where CW2 comes in. It specifies a special Item to be stored on disk by all contracts on instantiate.

ContractInfo must be stored under the "contract_info" key which translates to "636F6E74726163745F696E666F" in hex format. Since the state is well defined, we do not need to support any "smart queries". We do provide a helper to construct a "raw query" to read the ContractInfo of any CW2-compliant contract.

You can query using:

wasmd query wasm contract-state raw [contract_addr] 636F6E74726163745F696E666F --node $RPC

When the migrate function is called, then the new contract can read that data and see if this is an expected contract we can migrate from. And also contain extra version information if we support multiple migrate paths. This crate provides an ensure_from_older_version helper that handles this.

Data structures

Required

All CW2-compliant contracts must store the following data:

pub struct ContractVersion {
    /// contract is a globally unique identifier for the contract.
    /// it should build off standard namespacing for whichever language it is in,
    /// and prefix it with the registry we use.
    /// For rust we prefix with `crates.io:`, to give us eg. `crates.io:cw20-base`
    pub contract: String,
    /// version is any string that this implementation knows. It may be simple counter "1", "2".
    /// or semantic version on release tags "v0.7.0", or some custom feature flag list.
    /// the only code that needs to understand the version parsing is code that knows how to
    /// migrate from the given contract (and is tied to it's implementation somehow)
    pub version: String,
}

Thus, an serialized example may looks like:

{
  "contract": "crates.io:cw20-base",
  "version": "v0.1.0"
}

Dependencies

~3.5–5.5MB
~118K SLoC