51 releases (1 stable)

Uses new Rust 2021

1.0.0 Nov 29, 2022
0.16.0 Oct 17, 2022
0.15.1 Sep 27, 2022
0.14.0 Jul 28, 2022
0.3.2 Oct 28, 2020

#381 in Rust patterns

Download history 5546/week @ 2022-08-15 6841/week @ 2022-08-22 5759/week @ 2022-08-29 6960/week @ 2022-09-05 8188/week @ 2022-09-12 7180/week @ 2022-09-19 5484/week @ 2022-09-26 6619/week @ 2022-10-03 6145/week @ 2022-10-10 6777/week @ 2022-10-17 7342/week @ 2022-10-24 6758/week @ 2022-10-31 7828/week @ 2022-11-07 8199/week @ 2022-11-14 7185/week @ 2022-11-21 5836/week @ 2022-11-28

29,229 downloads per month
Used in 126 crates (87 directly)

Apache-2.0

8KB
56 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 andsee if this is an expected contract we can migrate from. And also contain extra version information if we support multiple migrate paths.

Data structures

Required

All CW2-compliant contracts must store the following data:

  • key: contract_info
  • data: Json-serialized ContractVersion
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

~2.3–3.5MB
~79K SLoC