|
| 1 | +// ExecuteMsg is used to call another defined contract on this chain. |
| 2 | +// The calling contract requires the callee to be defined beforehand, |
| 3 | +// and the address should have been defined in initialization. |
| 4 | +// And we assume the developer tested the ABIs and coded them together. |
| 5 | +// |
| 6 | +// Since a contract is immutable once it is deployed, we don't need to transform this. |
| 7 | +// If it was properly coded and worked once, it will continue to work throughout upgrades. |
| 8 | +type ExecuteMsg struct { |
| 9 | + // ContractAddr is the sdk.AccAddress of the contract, which uniquely defines |
| 10 | + // the contract ID and instance ID. The sdk module should maintain a reverse lookup table. |
| 11 | + ContractAddr string `json:"contract_addr"` |
| 12 | + // Send is an optional amount of coins this contract sends to the called contract |
| 13 | + Funds []Coin `json:"funds"` |
| 14 | + // Msg is assumed to be a json-encoded message, which will be passed directly |
| 15 | + // as `userMsg` when calling `Handle` on the above-defined contract |
| 16 | + Msg []byte `json:"msg"` |
| 17 | +} |
| 18 | + |
| 19 | +// InstantiateMsg will create a new contract instance from a previously uploaded CodeID. |
| 20 | +// This allows one contract to spawn "sub-contracts". |
| 21 | +type InstantiateMsg struct { |
| 22 | + // Admin (optional) may be set here to allow future migrations from this address |
| 23 | + Admin string `json:"admin,omitempty"` |
| 24 | + // CodeID is the reference to the wasm byte code as used by the Cosmos-SDK |
| 25 | + CodeID uint64 `json:"code_id"` |
| 26 | + // Send is an optional amount of coins this contract sends to the called contract |
| 27 | + Funds []Coin `json:"funds"` |
| 28 | + // Label is optional metadata to be stored with a contract instance. |
| 29 | + Label string `json:"label"` |
| 30 | + // Msg is assumed to be a json-encoded message, which will be passed directly |
| 31 | + // as `userMsg` when calling `Instantiate` on a new contract with the above-defined CodeID |
| 32 | + Msg []byte `json:"msg"` |
| 33 | +} |
| 34 | + |
| 35 | +// Instantiate2Msg will create a new contract instance from a previously uploaded CodeID |
| 36 | +// using the predictable address derivation. |
| 37 | +type Instantiate2Msg struct { |
| 38 | + // Admin (optional) may be set here to allow future migrations from this address |
| 39 | + Admin string `json:"admin,omitempty"` |
| 40 | + // CodeID is the reference to the wasm byte code as used by the Cosmos-SDK |
| 41 | + CodeID uint64 `json:"code_id"` |
| 42 | + // Send is an optional amount of coins this contract sends to the called contract |
| 43 | + Funds []Coin `json:"funds"` |
| 44 | + // Label is optional metadata to be stored with a contract instance. |
| 45 | + Label string `json:"label"` |
| 46 | + // Msg is assumed to be a json-encoded message, which will be passed directly |
| 47 | + // as `userMsg` when calling `Instantiate` on a new contract with the above-defined CodeID |
| 48 | + Msg []byte `json:"msg"` |
| 49 | + Salt []byte `json:"salt"` |
| 50 | +} |
| 51 | + |
| 52 | +// MigrateMsg will migrate an existing contract from it's current wasm code (logic) |
| 53 | +// to another previously uploaded wasm code. It requires the calling contract to be |
| 54 | +// listed as "admin" of the contract to be migrated. |
| 55 | +type MigrateMsg struct { |
| 56 | + // ContractAddr is the sdk.AccAddress of the target contract, to migrate. |
| 57 | + ContractAddr string `json:"contract_addr"` |
| 58 | + // Msg is assumed to be a json-encoded message, which will be passed directly |
| 59 | + // as `userMsg` when calling `Migrate` on the above-defined contract |
| 60 | + Msg []byte `json:"msg"` |
| 61 | + // NewCodeID is the reference to the wasm byte code for the new logic to migrate to |
| 62 | + NewCodeID uint64 `json:"new_code_id"` |
| 63 | +} |
| 64 | + |
| 65 | +// UpdateAdminMsg is the Go counterpart of WasmMsg::UpdateAdmin |
| 66 | +// (https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta5/packages/std/src/results/cosmos_msg.rs#L158-L160). |
| 67 | +type UpdateAdminMsg struct { |
| 68 | + // Admin is the sdk.AccAddress of the new admin. |
| 69 | + Admin string `json:"admin"` |
| 70 | + // ContractAddr is the sdk.AccAddress of the target contract. |
| 71 | + ContractAddr string `json:"contract_addr"` |
| 72 | +} |
| 73 | + |
| 74 | +// ClearAdminMsg is the Go counterpart of WasmMsg::ClearAdmin |
| 75 | +// (https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta5/packages/std/src/results/cosmos_msg.rs#L158-L160). |
| 76 | +type ClearAdminMsg struct { |
| 77 | + // ContractAddr is the sdk.AccAddress of the target contract. |
| 78 | + ContractAddr string `json:"contract_addr"` |
| 79 | +} |
| 80 | + |
| 81 | +// The message types of the wasm module. |
| 82 | +// |
| 83 | +// See https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto |
| 84 | +type WasmMsg struct { |
| 85 | + // Dispatches a call to another contract at a known address (with known ABI). |
| 86 | + // |
| 87 | + // This is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address. |
| 88 | + Execute *ExecuteMsg `json:"execute,omitempty"` |
| 89 | + // Instantiates a new contracts from previously uploaded Wasm code. |
| 90 | + // |
| 91 | + // The contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2. |
| 92 | + // |
| 93 | + // This is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address. |
| 94 | + Instantiate *InstantiateMsg `json:"instantiate,omitempty"` |
| 95 | + // Instantiates a new contracts from previously uploaded Wasm code using a predictable address derivation algorithm implemented in [`cosmwasm_std::instantiate2_address`]. |
| 96 | + // |
| 97 | + // This is translated to a [MsgInstantiateContract2](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L73-L96). `sender` is automatically filled with the current contract's address. `fix_msg` is automatically set to false. |
| 98 | + Instantiate2 *Instantiate2Msg `json:"instantiate2,omitempty"` |
| 99 | + // Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior. |
| 100 | + // |
| 101 | + // Only the contract admin (as defined in wasmd), if any, is able to make this call. |
| 102 | + // |
| 103 | + // This is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address. |
| 104 | + Migrate *MigrateMsg `json:"migrate,omitempty"` |
| 105 | + // Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract. |
| 106 | + UpdateAdmin *UpdateAdminMsg `json:"update_admin,omitempty"` |
| 107 | + // Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract. |
| 108 | + ClearAdmin *ClearAdminMsg `json:"clear_admin,omitempty"` |
| 109 | +} |
| 110 | + |
| 111 | +// Coin is a string representation of the sdk.Coin type (more portable than sdk.Int) |
| 112 | +type Coin struct { |
| 113 | + Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456" |
| 114 | + Denom string `json:"denom"` // type, eg. "ATOM" |
| 115 | +} |
0 commit comments