diff --git a/CHANGELOG.md b/CHANGELOG.md index 0278d0630c..92c9b536d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ and this project adheres to - contracts: added new `ibc-reflect` contract that receives channels and assigns each an account to redispatch. Similar idea to ICS27/Interchain Accounts (but different implementation) ([#692], [#711], [#714]) +- cosmwasm-std: Added new `WasmMsg::Migrate` variant that allows one contract + (eg. multisig) be the admin and migrate another contract ([#768]) [#692]: https://github.com/CosmWasm/cosmwasm/issues/692 [#706]: https://github.com/CosmWasm/cosmwasm/pull/706 @@ -37,6 +39,7 @@ and this project adheres to [#711]: https://github.com/CosmWasm/cosmwasm/pull/711 [#714]: https://github.com/CosmWasm/cosmwasm/pull/714 [#716]: https://github.com/CosmWasm/cosmwasm/pull/716 +[#768]: https://github.com/CosmWasm/cosmwasm/pull/768 ### Changed diff --git a/contracts/ibc-reflect-send/schema/handle_msg.json b/contracts/ibc-reflect-send/schema/handle_msg.json index 77ac57ae2b..7a921baeaa 100644 --- a/contracts/ibc-reflect-send/schema/handle_msg.json +++ b/contracts/ibc-reflect-send/schema/handle_msg.json @@ -584,6 +584,42 @@ } } } + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis 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.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "$ref": "#/definitions/HumanAddr" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } } ] } diff --git a/contracts/ibc-reflect-send/schema/packet_msg.json b/contracts/ibc-reflect-send/schema/packet_msg.json index 437c08ba72..4cb059ff7a 100644 --- a/contracts/ibc-reflect-send/schema/packet_msg.json +++ b/contracts/ibc-reflect-send/schema/packet_msg.json @@ -538,6 +538,42 @@ } } } + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis 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.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "$ref": "#/definitions/HumanAddr" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } } ] } diff --git a/contracts/ibc-reflect/schema/packet_msg.json b/contracts/ibc-reflect/schema/packet_msg.json index de041db355..64a7cacec9 100644 --- a/contracts/ibc-reflect/schema/packet_msg.json +++ b/contracts/ibc-reflect/schema/packet_msg.json @@ -537,6 +537,42 @@ } } } + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis 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.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "$ref": "#/definitions/HumanAddr" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } } ] } diff --git a/contracts/reflect/schema/handle_msg.json b/contracts/reflect/schema/handle_msg.json index 9aff7ee39d..ff6724a833 100644 --- a/contracts/reflect/schema/handle_msg.json +++ b/contracts/reflect/schema/handle_msg.json @@ -557,6 +557,42 @@ } } } + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis 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.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "$ref": "#/definitions/HumanAddr" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } } ] } diff --git a/contracts/reflect/schema/handle_response_for__custom_msg.json b/contracts/reflect/schema/handle_response_for__custom_msg.json index 9e81de49e9..faebec503d 100644 --- a/contracts/reflect/schema/handle_response_for__custom_msg.json +++ b/contracts/reflect/schema/handle_response_for__custom_msg.json @@ -560,6 +560,42 @@ } } } + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis 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.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "$ref": "#/definitions/HumanAddr" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } } ] } diff --git a/packages/std/schema/cosmos_msg.json b/packages/std/schema/cosmos_msg.json index 87fa91617f..3a0230406c 100644 --- a/packages/std/schema/cosmos_msg.json +++ b/packages/std/schema/cosmos_msg.json @@ -304,6 +304,42 @@ } } } + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis 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.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "$ref": "#/definitions/HumanAddr" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + } } ] } diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 7a0c6cc67b..bc04ff1e77 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -15,6 +15,7 @@ use crate::types::Empty; /// These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts /// (contracts that directly speak the IBC protocol via 6 entry points) +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum IbcMsg { @@ -60,6 +61,7 @@ pub enum IbcMsg { /// These are queries to the various IBC modules to see the state of the contract's /// IBC connection. These will return errors if the contract is not "ibc enabled" +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum IbcQuery { diff --git a/packages/std/src/query.rs b/packages/std/src/query.rs index 457660a9fe..d1cd5a27b4 100644 --- a/packages/std/src/query.rs +++ b/packages/std/src/query.rs @@ -9,6 +9,7 @@ use crate::ibc::IbcQuery; use crate::math::Decimal; use crate::types::Empty; +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryRequest { @@ -31,6 +32,7 @@ pub enum QueryRequest { Wasm(WasmQuery), } +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum BankQuery { @@ -66,6 +68,7 @@ pub trait CustomQuery: Serialize {} impl CustomQuery for Empty {} +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum WasmQuery { @@ -140,6 +143,7 @@ pub struct StargateResponse { pub response: Binary, } +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum StakingQuery { diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index f8647d9294..276577cea8 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -11,6 +11,7 @@ use crate::ibc::IbcMsg; use crate::serde::to_binary; use crate::types::Empty; +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] // See https://github.com/serde-rs/serde/issues/1296 why we cannot add De-Serialize trait bounds to T @@ -38,6 +39,7 @@ where /// The message types of the bank module. /// /// See https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum BankMsg { @@ -54,6 +56,7 @@ pub enum BankMsg { /// The message types of the staking module. /// /// See https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum StakingMsg { @@ -84,6 +87,7 @@ pub enum StakingMsg { /// The message types of the wasm module. /// /// See https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto +#[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum WasmMsg { @@ -109,6 +113,20 @@ pub enum WasmMsg { /// optional human-readbale label for the contract label: Option, }, + /// Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to + /// customize behavior. + /// + /// Only the contract admin (as defined in wasmd), if any, is able to make this call. + /// + /// 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. + Migrate { + contract_addr: HumanAddr, + /// the code_id of the new logic to place in the given contract + new_code_id: u64, + /// msg is the json-encoded MigrateMsg struct that will be passed to the new code + msg: Binary, + }, } /// Shortcut helper as the construction of WasmMsg::Instantiate can be quite verbose in contract code