1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::prelude::*;
use cosmwasm_schema::QueryResponses;

#[cw_serde]
pub struct InstantiateMsg {}

#[cw_serde]
pub struct MigrateMsg {}

#[cw_serde]
pub enum ExecuteMsg {
    /// Track the upload of a WASM file
    CodeId {
        /// User friendly string describing the contract
        contract_type: String,
        /// Code ID of the uploaded file
        code_id: u64,
        /// SHA256 hash to uniquely identify a file
        hash: String,
        /// Git commit that generated this code, if known
        gitrev: Option<String>,
    },
    /// Track the instantiation of a new contract
    ///
    /// Will automatically assign a unique identifier from the deployment family
    Instantiate {
        code_id: u64,
        address: String,
        /// Family of the deployment.
        ///
        /// This can be things like osmodev or dragonci. The idea would be that there
        /// can be a series of contracts in this family, and the latest one is the
        /// current true deployment.
        ///
        /// Each individual instantiation will get a unique identifier based on this name.
        family: String,
    },
    /// Track the migration of an existing contract to a new code ID.
    ///
    /// This information is already tracked on the blockchain, it's just
    /// convenient to have it here too.
    Migrate { new_code_id: u64, address: String },
    /// Add an administrator address
    AddAdmin { address: String },
    /// Remove an administrator address
    RemoveAdmin { address: String },
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    /// Lookup the code by ID
    #[returns(CodeIdResp)]
    CodeById { code_id: u64 },
    /// Lookup the code by hash
    #[returns(CodeIdResp)]
    CodeByHash { hash: String },
    /// Get the contract information for the given contract address
    #[returns(ContractResp)]
    ContractByAddress { address: String },
    /// Get the contract information for the latest contract in a family
    #[returns(ContractResp)]
    ContractByFamily {
        /// This is derived from the Code ID during the Instantiate call
        contract_type: String,
        family: String,
        /// Unique identifier within the series to look up.
        ///
        /// If omitted, gets the most recent
        sequence: Option<u32>,
    },
}

#[cw_serde]
pub enum CodeIdResp {
    NotFound {},
    Found {
        contract_type: String,
        code_id: u64,
        hash: String,
        tracked_at: Timestamp,
        gitrev: Option<String>,
    },
}

#[cw_serde]
pub enum ContractResp {
    NotFound {},
    Found {
        address: String,
        contract_type: String,
        original_code_id: u64,
        /// When we received the Instantiate call
        original_tracked_at: Timestamp,
        current_code_id: u64,
        /// When we received the most recent instantiate or migrate
        current_tracked_at: Timestamp,
        family: String,
        sequence: u32,
        /// How many times have we been migrated?
        migrate_count: u32,
    },
}