From 784e6f2714456c7a67002dd9d457a4fa43acaed5 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 5 Feb 2021 07:51:57 +0100 Subject: [PATCH 1/5] Add WasmMsg::Migrate variant --- packages/std/src/results/cosmos_msg.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index f8647d9294..8927e65269 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -109,6 +109,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 From 9f07d639935e6b57374f0a29adebb60b0e288d20 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 5 Feb 2021 08:06:55 +0100 Subject: [PATCH 2/5] Update schema files --- .../ibc-reflect-send/schema/handle_msg.json | 36 +++++++++++++++++++ .../ibc-reflect-send/schema/packet_msg.json | 36 +++++++++++++++++++ contracts/ibc-reflect/schema/packet_msg.json | 36 +++++++++++++++++++ contracts/reflect/schema/handle_msg.json | 36 +++++++++++++++++++ .../handle_response_for__custom_msg.json | 36 +++++++++++++++++++ packages/std/schema/cosmos_msg.json | 36 +++++++++++++++++++ 6 files changed, 216 insertions(+) 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 + } + } + } + } } ] } From b0dc84c908d494e4f07cef8a0ac94b9cd17181fe Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 5 Feb 2021 08:11:35 +0100 Subject: [PATCH 3/5] [skip ci] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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 From a8374f8dc2bcb2d87b05d94c044ae7427834661c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 5 Feb 2021 12:41:24 +0100 Subject: [PATCH 4/5] Made CosmosMsg #non_exhaustive for future extensibility --- packages/std/src/ibc.rs | 1 + packages/std/src/results/cosmos_msg.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 7a0c6cc67b..d5679768d6 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 { diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index 8927e65269..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 { From 7de5a1ade5af7d67acd65ac369933c826c0143c5 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 5 Feb 2021 12:46:00 +0100 Subject: [PATCH 5/5] Make QueryRequest #non_exhaustive for future extensibility --- packages/std/src/ibc.rs | 1 + packages/std/src/query.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index d5679768d6..bc04ff1e77 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -61,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 {