Repository: CosmWasm/cosmwasm
Pull request #814 (2021-03-03 11:58:34)

Make label in WasmMsg::Instantiate non-optional
This is a simple string on the blockchain side

alpe: Ref https://github.com/CosmWasm/wasmvm/pull/199
alpe: https://github.com/CosmWasm/cosmwasm/blob/main/packages/std/src/results/cosmos_msg.rs#L115  needs an update as well. Changes look good otherwise. Thanks 💐 
webmaster128: > https://github.com/CosmWasm/cosmwasm/blob/main/packages/std/src/results/cosmos_msg.rs#L115 needs an update as well. Changes look good otherwise. Thanks 💐

Thanks, but the change is included, isn't it?
alpe: > Thanks, but the change is included, isn't it?

argh, sorry. 👍 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f7e5d4842..9721917ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -85,6 +85,8 @@ and this project adheres to
 - cosmwasm-std: Remove `Default` implementation from `HumanAddr`,
   `CanonicalAddr`, `ContractInfo`, `MessageInfo`, `BlockInfo` and `Env`. If you
   need one of those, you're probably doing something wrong.
+- cosmwasm-std: Make `label` in `WasmMsg::Instantiate` non-optional to better
+  match the Go/database format.
 - cosmwasm-vm: Avoid serialization of Modules in `InMemoryCache`, for
   performance. Also, remove `memory_limit` from `InstanceOptions`, and define it
   instead at `Cache` level (same memory limit for all cached instances).
diff --git a/contracts/ibc-reflect-send/schema/handle_msg.json b/contracts/ibc-reflect-send/schema/handle_msg.json
index 7a921baea..66cc967a1 100644
--- a/contracts/ibc-reflect-send/schema/handle_msg.json
+++ b/contracts/ibc-reflect-send/schema/handle_msg.json
@@ -551,6 +551,7 @@
               "type": "object",
               "required": [
                 "code_id",
+                "label",
                 "msg",
                 "send"
               ],
@@ -561,11 +562,8 @@
                   "minimum": 0.0
                 },
                 "label": {
-                  "description": "optional human-readbale label for the contract",
-                  "type": [
-                    "string",
-                    "null"
-                  ]
+                  "description": "A human-readbale label for the contract",
+                  "type": "string"
                 },
                 "msg": {
                   "description": "msg is the json-encoded InitMsg struct (as raw Binary)",
diff --git a/contracts/ibc-reflect-send/schema/packet_msg.json b/contracts/ibc-reflect-send/schema/packet_msg.json
index 4cb059ff7..aac4f82c0 100644
--- a/contracts/ibc-reflect-send/schema/packet_msg.json
+++ b/contracts/ibc-reflect-send/schema/packet_msg.json
@@ -505,6 +505,7 @@
               "type": "object",
               "required": [
                 "code_id",
+                "label",
                 "msg",
                 "send"
               ],
@@ -515,11 +516,8 @@
                   "minimum": 0.0
                 },
                 "label": {
-                  "description": "optional human-readbale label for the contract",
-                  "type": [
-                    "string",
-                    "null"
-                  ]
+                  "description": "A human-readbale label for the contract",
+                  "type": "string"
                 },
                 "msg": {
                   "description": "msg is the json-encoded InitMsg struct (as raw Binary)",
diff --git a/contracts/ibc-reflect/schema/packet_msg.json b/contracts/ibc-reflect/schema/packet_msg.json
index 64a7cacec..486201012 100644
--- a/contracts/ibc-reflect/schema/packet_msg.json
+++ b/contracts/ibc-reflect/schema/packet_msg.json
@@ -504,6 +504,7 @@
               "type": "object",
               "required": [
                 "code_id",
+                "label",
                 "msg",
                 "send"
               ],
@@ -514,11 +515,8 @@
                   "minimum": 0.0
                 },
                 "label": {
-                  "description": "optional human-readbale label for the contract",
-                  "type": [
-                    "string",
-                    "null"
-                  ]
+                  "description": "A human-readbale label for the contract",
+                  "type": "string"
                 },
                 "msg": {
                   "description": "msg is the json-encoded InitMsg struct (as raw Binary)",
diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs
index 98722862a..d652ab900 100644
--- a/contracts/ibc-reflect/src/contract.rs
+++ b/contracts/ibc-reflect/src/contract.rs
@@ -140,7 +140,7 @@ pub fn ibc_channel_connect(
     let payload = ReflectInitMsg {
         callback_id: Some(chan_id.clone()),
     };
-    let msg = wasm_instantiate(cfg.reflect_code_id, &payload, vec![], Some(label))?;
+    let msg = wasm_instantiate(cfg.reflect_code_id, &payload, vec![], label)?;
     Ok(IbcBasicResponse {
         messages: vec![msg.into()],
         attributes: vec![attr("action", "ibc_connect"), attr("channel_id", chan_id)],
@@ -403,7 +403,7 @@ mod tests {
         {
             assert_eq!(&REFLECT_ID, code_id);
             assert_eq!(0, send.len());
-            assert!(label.as_ref().unwrap().contains(channel_id));
+            assert!(label.contains(channel_id));
             // parse the message - should callback with proper channel_id
             let rmsg: ReflectInitMsg = from_slice(&msg).unwrap();
             assert_eq!(rmsg.callback_id, Some(channel_id.to_string()));
diff --git a/contracts/reflect/schema/handle_msg.json b/contracts/reflect/schema/handle_msg.json
index 73887a47a..d1b581f58 100644
--- a/contracts/reflect/schema/handle_msg.json
+++ b/contracts/reflect/schema/handle_msg.json
@@ -572,6 +572,7 @@
               "type": "object",
               "required": [
                 "code_id",
+                "label",
                 "msg",
                 "send"
               ],
@@ -582,11 +583,8 @@
                   "minimum": 0.0
                 },
                 "label": {
-                  "description": "optional human-readbale label for the contract",
-                  "type": [
-                    "string",
-                    "null"
-                  ]
+                  "description": "A human-readbale label for the contract",
+                  "type": "string"
                 },
                 "msg": {
                   "description": "msg is the json-encoded InitMsg struct (as raw Binary)",
diff --git a/contracts/reflect/schema/response_for__custom_msg.json b/contracts/reflect/schema/response_for__custom_msg.json
index b8c691b67..3edb5d70f 100644
--- a/contracts/reflect/schema/response_for__custom_msg.json
+++ b/contracts/reflect/schema/response_for__custom_msg.json
@@ -563,6 +563,7 @@
               "type": "object",
               "required": [
                 "code_id",
+                "label",
                 "msg",
                 "send"
               ],
@@ -573,11 +574,8 @@
                   "minimum": 0.0
                 },
                 "label": {
-                  "description": "optional human-readbale label for the contract",
-                  "type": [
-                    "string",
-                    "null"
-                  ]
+                  "description": "A human-readbale label for the contract",
+                  "type": "string"
                 },
                 "msg": {
                   "description": "msg is the json-encoded InitMsg struct (as raw Binary)",
diff --git a/packages/std/schema/cosmos_msg.json b/packages/std/schema/cosmos_msg.json
index 3a0230406..84eaedc9d 100644
--- a/packages/std/schema/cosmos_msg.json
+++ b/packages/std/schema/cosmos_msg.json
@@ -271,6 +271,7 @@
               "type": "object",
               "required": [
                 "code_id",
+                "label",
                 "msg",
                 "send"
               ],
@@ -281,11 +282,8 @@
                   "minimum": 0.0
                 },
                 "label": {
-                  "description": "optional human-readbale label for the contract",
-                  "type": [
-                    "string",
-                    "null"
-                  ]
+                  "description": "A human-readbale label for the contract",
+                  "type": "string"
                 },
                 "msg": {
                   "description": "msg is the json-encoded InitMsg struct (as raw Binary)",
diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs
index 983c782af..15c408a8d 100644
--- a/packages/std/src/results/cosmos_msg.rs
+++ b/packages/std/src/results/cosmos_msg.rs
@@ -111,8 +111,8 @@ pub enum WasmMsg {
         /// msg is the json-encoded InitMsg struct (as raw Binary)
         msg: Binary,
         send: Vec<Coin>,
-        /// optional human-readbale label for the contract
-        label: Option<String>,
+        /// A human-readbale label for the contract
+        label: String,
     },
     /// Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to
     /// customize behavior.
@@ -135,7 +135,7 @@ pub fn wasm_instantiate<T>(
     code_id: u64,
     msg: &T,
     send: Vec<Coin>,
-    label: Option<String>,
+    label: String,
 ) -> StdResult<WasmMsg>
 where
     T: Serialize,


Test patch:
diff --git a/contracts/ibc-reflect/tests/integration.rs b/contracts/ibc-reflect/tests/integration.rs
index c41cae908..c43d0823a 100644
--- a/contracts/ibc-reflect/tests/integration.rs
+++ b/contracts/ibc-reflect/tests/integration.rs
@@ -132,7 +132,7 @@ fn proper_handshake_flow() {
     {
         assert_eq!(&REFLECT_ID, code_id);
         assert_eq!(0, send.len());
-        assert!(label.as_ref().unwrap().contains(channel_id));
+        assert!(label.contains(channel_id));
         // parse the message - should callback with proper channel_id
         let rmsg: ReflectInitMsg = from_slice(&msg).unwrap();
         assert_eq!(rmsg.callback_id, Some(channel_id.to_string()));