From da5a32cd0365a8ee5b19cab7df6cdf44dd2dc9d0 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 4 Oct 2023 17:33:52 +0200 Subject: [PATCH 01/11] Add msg_responses to SubMsgResponse --- packages/std/src/results/mod.rs | 2 +- packages/std/src/results/submessages.rs | 50 +++++++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/packages/std/src/results/mod.rs b/packages/std/src/results/mod.rs index 2df471c3ea..ed505da4c3 100644 --- a/packages/std/src/results/mod.rs +++ b/packages/std/src/results/mod.rs @@ -23,5 +23,5 @@ pub use empty::Empty; pub use events::{attr, Attribute, Event}; pub use query::QueryResponse; pub use response::Response; -pub use submessages::{Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult}; +pub use submessages::{MsgResponseValue, Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult}; pub use system_result::SystemResult; diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index 973047c771..3f0de1ca65 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -123,22 +123,26 @@ pub struct Reply { /// Success: /// /// ``` -/// # use cosmwasm_std::{to_vec, Binary, Event, SubMsgResponse, SubMsgResult}; +/// # use cosmwasm_std::{to_json_string, Binary, Event, SubMsgResponse, SubMsgResult}; /// let response = SubMsgResponse { /// data: Some(Binary::from_base64("MTIzCg==").unwrap()), /// events: vec![Event::new("wasm").add_attribute("fo", "ba")], +/// msg_responses: vec![], /// }; /// let result: SubMsgResult = SubMsgResult::Ok(response); -/// assert_eq!(to_vec(&result).unwrap(), br#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg=="}}"#); +/// assert_eq!( +/// to_json_string(&result).unwrap(), +/// r#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg==","msg_responses":[]}}"#, +/// ); /// ``` /// /// Failure: /// /// ``` -/// # use cosmwasm_std::{to_vec, SubMsgResult, Response}; +/// # use cosmwasm_std::{to_json_string, SubMsgResult, Response}; /// let error_msg = String::from("Something went wrong"); /// let result = SubMsgResult::Err(error_msg); -/// assert_eq!(to_vec(&result).unwrap(), br#"{"error":"Something went wrong"}"#); +/// assert_eq!(to_json_string(&result).unwrap(), r#"{"error":"Something went wrong"}"#); /// ``` #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] @@ -200,6 +204,14 @@ impl From for Result { pub struct SubMsgResponse { pub events: Vec, pub data: Option, + #[serde(default)] + pub msg_responses: Vec, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct MsgResponseValue { + pub type_url: String, + pub value: Binary, } #[cfg(test)] @@ -211,20 +223,26 @@ mod tests { fn sub_msg_result_serialization_works() { let result = SubMsgResult::Ok(SubMsgResponse { data: None, + msg_responses: vec![], events: vec![], }); assert_eq!( &to_json_vec(&result).unwrap(), - br#"{"ok":{"events":[],"data":null}}"# + br#"{"ok":{"events":[],"data":null,"msg_responses":[]}}"# ); let result = SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), + msg_responses: vec![MsgResponseValue { + type_url: "URL".to_string(), + value: Binary::from_base64("MTIzCg==").unwrap(), + }], events: vec![Event::new("wasm").add_attribute("fo", "ba")], }); + println!("{}", &crate::to_json_string(&result).unwrap()); assert_eq!( &to_json_vec(&result).unwrap(), - br#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg=="}}"# + br#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg==","msg_responses":[{"type_url":"URL","value":"MTIzCg=="}]}}"# ); let result: SubMsgResult = SubMsgResult::Err("broken".to_string()); @@ -233,21 +251,28 @@ mod tests { #[test] fn sub_msg_result_deserialization_works() { + // should work without `msg_responses` let result: SubMsgResult = from_json(br#"{"ok":{"events":[],"data":null}}"#).unwrap(); assert_eq!( result, SubMsgResult::Ok(SubMsgResponse { events: vec![], data: None, + msg_responses: vec![] }) ); let result: SubMsgResult = from_json( - br#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg=="}}"#).unwrap(); + br#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg==", + "msg_responses":[{"type_url":"URL","value":"MTIzCg=="}]}}"#).unwrap(); assert_eq!( result, SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), + msg_responses: vec![MsgResponseValue { + type_url: "URL".to_string(), + value: Binary::from_base64("MTIzCg==").unwrap(), + }], events: vec![Event::new("wasm").add_attribute("fo", "ba")], }) ); @@ -272,6 +297,10 @@ mod tests { fn sub_msg_result_unwrap_works() { let response = SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), + msg_responses: vec![MsgResponseValue { + type_url: "URL".to_string(), + value: Binary::from_base64("MTIzCg==").unwrap(), + }], events: vec![Event::new("wasm").add_attribute("fo", "ba")], }; let success = SubMsgResult::Ok(response.clone()); @@ -297,6 +326,7 @@ mod tests { let response = SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), events: vec![Event::new("wasm").add_attribute("fo", "ba")], + msg_responses: vec![], }; let success = SubMsgResult::Ok(response); let _ = success.unwrap_err(); @@ -307,6 +337,7 @@ mod tests { let success = SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), events: vec![Event::new("wasm").add_attribute("fo", "ba")], + msg_responses: vec![], }); let failure = SubMsgResult::Err("broken".to_string()); assert!(success.is_ok()); @@ -318,6 +349,7 @@ mod tests { let success = SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), events: vec![Event::new("wasm").add_attribute("fo", "ba")], + msg_responses: vec![], }); let failure = SubMsgResult::Err("broken".to_string()); assert!(failure.is_err()); @@ -329,6 +361,7 @@ mod tests { let original: Result = Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), events: vec![], + msg_responses: vec![], }); let converted: SubMsgResult = original.into(); assert_eq!( @@ -336,6 +369,7 @@ mod tests { SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), events: vec![], + msg_responses: vec![], }) ); @@ -352,6 +386,7 @@ mod tests { let original = SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), events: vec![], + msg_responses: vec![], }); let converted: Result = original.into(); assert_eq!( @@ -359,6 +394,7 @@ mod tests { Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), events: vec![], + msg_responses: vec![], }) ); From b0628c95597b1fe359448bea768ed4f9e1a771c5 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 4 Oct 2023 17:34:14 +0200 Subject: [PATCH 02/11] Deprecate SubMsgResponse::data --- packages/std/src/results/submessages.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index 3f0de1ca65..2568f22557 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -124,6 +124,7 @@ pub struct Reply { /// /// ``` /// # use cosmwasm_std::{to_json_string, Binary, Event, SubMsgResponse, SubMsgResult}; +/// #[allow(deprecated)] /// let response = SubMsgResponse { /// data: Some(Binary::from_base64("MTIzCg==").unwrap()), /// events: vec![Event::new("wasm").add_attribute("fo", "ba")], @@ -203,6 +204,7 @@ impl From for Result { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct SubMsgResponse { pub events: Vec, + #[deprecated = "deprecated in the cosmos-sdk in favor of msg_responses"] pub data: Option, #[serde(default)] pub msg_responses: Vec, @@ -215,6 +217,7 @@ pub struct MsgResponseValue { } #[cfg(test)] +#[allow(deprecated)] mod tests { use super::*; use crate::{from_json, to_json_vec, StdError, StdResult}; From 51c0adf46e83efdebdedb479f4225c0561b36cd5 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 4 Oct 2023 18:01:01 +0200 Subject: [PATCH 03/11] Fix contracts --- contracts/ibc-reflect/src/contract.rs | 4 ++++ contracts/ibc-reflect/tests/integration.rs | 4 ++++ contracts/reflect/src/contract.rs | 7 ++++++- contracts/reflect/tests/integration.rs | 7 ++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs index 3dd6c776ca..20a8b36568 100644 --- a/contracts/ibc-reflect/src/contract.rs +++ b/contracts/ibc-reflect/src/contract.rs @@ -402,11 +402,13 @@ mod tests { let id = res.messages[0].id; // fake a reply and ensure this works + #[allow(deprecated)] let response = Reply { id, gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(&account), + msg_responses: vec![], data: None, }), }; @@ -480,11 +482,13 @@ mod tests { assert_eq!(0, res.accounts.len()); // fake a reply and ensure this works + #[allow(deprecated)] let response = Reply { id, gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(REFLECT_ADDR), + msg_responses: vec![], data: None, }), }; diff --git a/contracts/ibc-reflect/tests/integration.rs b/contracts/ibc-reflect/tests/integration.rs index 542ff939ac..d7beffc874 100644 --- a/contracts/ibc-reflect/tests/integration.rs +++ b/contracts/ibc-reflect/tests/integration.rs @@ -93,11 +93,13 @@ fn connect( let id = res.messages[0].id; // fake a reply and ensure this works + #[allow(deprecated)] let response = Reply { id, gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(&account), + msg_responses: vec![], data: None, }), }; @@ -172,11 +174,13 @@ fn proper_handshake_flow() { assert_eq!(0, res.accounts.len()); // we get the callback from reflect + #[allow(deprecated)] let response = Reply { id, gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: fake_events(REFLECT_ADDR), + msg_responses: vec![], data: None, }), }; diff --git a/contracts/reflect/src/contract.rs b/contracts/reflect/src/contract.rs index 4d32665c6e..914c701a53 100644 --- a/contracts/reflect/src/contract.rs +++ b/contracts/reflect/src/contract.rs @@ -435,9 +435,11 @@ mod tests { let data = Binary::from(b"foobar"); let events = vec![Event::new("message").add_attribute("signer", "caller-addr")]; let gas_used = 1234567u64; + #[allow(deprecated)] let result = SubMsgResult::Ok(SubMsgResponse { events: events.clone(), data: Some(data.clone()), + msg_responses: vec![], }); let subcall = Reply { id, @@ -460,7 +462,10 @@ mod tests { let qres: Reply = from_json(raw).unwrap(); assert_eq!(qres.id, id); let result = qres.result.unwrap(); - assert_eq!(result.data, Some(data)); + #[allow(deprecated)] + { + assert_eq!(result.data, Some(data)); + } assert_eq!(result.events, events); } } diff --git a/contracts/reflect/tests/integration.rs b/contracts/reflect/tests/integration.rs index 6be7f79bd2..23bff83c8f 100644 --- a/contracts/reflect/tests/integration.rs +++ b/contracts/reflect/tests/integration.rs @@ -269,9 +269,11 @@ fn reply_and_query() { let data = Binary::from(b"foobar"); let events = vec![Event::new("message").add_attribute("signer", "caller-addr")]; let gas_used = 1234567u64; + #[allow(deprecated)] let result = SubMsgResult::Ok(SubMsgResponse { events: events.clone(), data: Some(data.clone()), + msg_responses: vec![], }); let subcall = Reply { id, @@ -290,6 +292,9 @@ fn reply_and_query() { let qres: Reply = from_json(raw).unwrap(); assert_eq!(qres.id, id); let result = qres.result.unwrap(); - assert_eq!(result.data, Some(data)); + #[allow(deprecated)] + { + assert_eq!(result.data, Some(data)); + } assert_eq!(result.events, events); } From 321e8fcbfd2f90c7b4e127eb477e7b95ae87dfc0 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 4 Oct 2023 18:12:14 +0200 Subject: [PATCH 04/11] Fix vm --- packages/vm/src/calls.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs index d9421c5b4f..97b059e109 100644 --- a/packages/vm/src/calls.rs +++ b/packages/vm/src/calls.rs @@ -898,11 +898,13 @@ mod tests { mock_wasmd_attr("_contract_address", account), ]); // which creates a reflect account. here we get the callback + #[allow(deprecated)] let response = Reply { id, gas_used: 1234567, result: SubMsgResult::Ok(SubMsgResponse { events: vec![event], + msg_responses: vec![], data: None, }), }; From 592c40c148b148ce80173fbe16251ff52fb07c5c Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 4 Oct 2023 18:24:21 +0200 Subject: [PATCH 05/11] Update contract schemas --- .../raw/response_to_sub_msg_result.json | 25 ++++++++++++++++++- contracts/reflect/schema/reflect.json | 25 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/contracts/reflect/schema/raw/response_to_sub_msg_result.json b/contracts/reflect/schema/raw/response_to_sub_msg_result.json index afe3b4b9b0..38ee54d477 100644 --- a/contracts/reflect/schema/raw/response_to_sub_msg_result.json +++ b/contracts/reflect/schema/raw/response_to_sub_msg_result.json @@ -67,6 +67,21 @@ } } }, + "MsgResponseValue": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + }, "SubMsgResponse": { "description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.", "type": "object", @@ -75,6 +90,7 @@ ], "properties": { "data": { + "deprecated": true, "anyOf": [ { "$ref": "#/definitions/Binary" @@ -89,11 +105,18 @@ "items": { "$ref": "#/definitions/Event" } + }, + "msg_responses": { + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/MsgResponseValue" + } } } }, "SubMsgResult": { - "description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, Binary, Event, SubMsgResponse, SubMsgResult}; let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\"}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```", + "description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_json_string, Binary, Event, SubMsgResponse, SubMsgResult}; #[allow(deprecated)] let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], msg_responses: vec![], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!( to_json_string(&result).unwrap(), r#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\",\"msg_responses\":[]}}\"#, ); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_json_string, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_json_string(&result).unwrap(), r#\"{\"error\":\"Something went wrong\"}\"#); ```", "oneOf": [ { "type": "object", diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 713ca2745c..c382e6605a 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -1948,6 +1948,21 @@ } } }, + "MsgResponseValue": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + }, "SubMsgResponse": { "description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.", "type": "object", @@ -1956,6 +1971,7 @@ ], "properties": { "data": { + "deprecated": true, "anyOf": [ { "$ref": "#/definitions/Binary" @@ -1970,11 +1986,18 @@ "items": { "$ref": "#/definitions/Event" } + }, + "msg_responses": { + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/MsgResponseValue" + } } } }, "SubMsgResult": { - "description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_vec, Binary, Event, SubMsgResponse, SubMsgResult}; let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!(to_vec(&result).unwrap(), br#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\"}}\"#); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_vec, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_vec(&result).unwrap(), br#\"{\"error\":\"Something went wrong\"}\"#); ```", + "description": "This is the result type that is returned from a sub message execution.\n\nWe use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.\n\nUntil version 1.0.0-beta5, `ContractResult` was used instead of this type. Once serialized, the two types are the same. However, in the Rust type system we want different types for clarity and documenation reasons.\n\n# Examples\n\nSuccess:\n\n``` # use cosmwasm_std::{to_json_string, Binary, Event, SubMsgResponse, SubMsgResult}; #[allow(deprecated)] let response = SubMsgResponse { data: Some(Binary::from_base64(\"MTIzCg==\").unwrap()), events: vec![Event::new(\"wasm\").add_attribute(\"fo\", \"ba\")], msg_responses: vec![], }; let result: SubMsgResult = SubMsgResult::Ok(response); assert_eq!( to_json_string(&result).unwrap(), r#\"{\"ok\":{\"events\":[{\"type\":\"wasm\",\"attributes\":[{\"key\":\"fo\",\"value\":\"ba\"}]}],\"data\":\"MTIzCg==\",\"msg_responses\":[]}}\"#, ); ```\n\nFailure:\n\n``` # use cosmwasm_std::{to_json_string, SubMsgResult, Response}; let error_msg = String::from(\"Something went wrong\"); let result = SubMsgResult::Err(error_msg); assert_eq!(to_json_string(&result).unwrap(), r#\"{\"error\":\"Something went wrong\"}\"#); ```", "oneOf": [ { "type": "object", From 16b91227fabf8d220d647b06e34e518a74d4ba65 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 22 Nov 2023 09:29:44 +0000 Subject: [PATCH 06/11] Rename MsgResponseValue to MsgResponse --- packages/std/src/results/mod.rs | 2 +- packages/std/src/results/submessages.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/std/src/results/mod.rs b/packages/std/src/results/mod.rs index ed505da4c3..effbf9ed73 100644 --- a/packages/std/src/results/mod.rs +++ b/packages/std/src/results/mod.rs @@ -23,5 +23,5 @@ pub use empty::Empty; pub use events::{attr, Attribute, Event}; pub use query::QueryResponse; pub use response::Response; -pub use submessages::{MsgResponseValue, Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult}; +pub use submessages::{MsgResponse, Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult}; pub use system_result::SystemResult; diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index 2568f22557..1f9a0a6ef1 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -207,11 +207,11 @@ pub struct SubMsgResponse { #[deprecated = "deprecated in the cosmos-sdk in favor of msg_responses"] pub data: Option, #[serde(default)] - pub msg_responses: Vec, + pub msg_responses: Vec, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct MsgResponseValue { +pub struct MsgResponse { pub type_url: String, pub value: Binary, } @@ -236,7 +236,7 @@ mod tests { let result = SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), - msg_responses: vec![MsgResponseValue { + msg_responses: vec![MsgResponse { type_url: "URL".to_string(), value: Binary::from_base64("MTIzCg==").unwrap(), }], @@ -272,7 +272,7 @@ mod tests { result, SubMsgResult::Ok(SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), - msg_responses: vec![MsgResponseValue { + msg_responses: vec![MsgResponse { type_url: "URL".to_string(), value: Binary::from_base64("MTIzCg==").unwrap(), }], @@ -300,7 +300,7 @@ mod tests { fn sub_msg_result_unwrap_works() { let response = SubMsgResponse { data: Some(Binary::from_base64("MTIzCg==").unwrap()), - msg_responses: vec![MsgResponseValue { + msg_responses: vec![MsgResponse { type_url: "URL".to_string(), value: Binary::from_base64("MTIzCg==").unwrap(), }], From f5356df6f7092868ecc06263168230b394e8d1ed Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 22 Nov 2023 09:44:03 +0000 Subject: [PATCH 07/11] Update schema --- contracts/reflect/schema/raw/response_to_sub_msg_result.json | 4 ++-- contracts/reflect/schema/reflect.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/reflect/schema/raw/response_to_sub_msg_result.json b/contracts/reflect/schema/raw/response_to_sub_msg_result.json index 38ee54d477..e11c7ad73e 100644 --- a/contracts/reflect/schema/raw/response_to_sub_msg_result.json +++ b/contracts/reflect/schema/raw/response_to_sub_msg_result.json @@ -67,7 +67,7 @@ } } }, - "MsgResponseValue": { + "MsgResponse": { "type": "object", "required": [ "type_url", @@ -110,7 +110,7 @@ "default": [], "type": "array", "items": { - "$ref": "#/definitions/MsgResponseValue" + "$ref": "#/definitions/MsgResponse" } } } diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index c382e6605a..3b34e13ac9 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -1948,7 +1948,7 @@ } } }, - "MsgResponseValue": { + "MsgResponse": { "type": "object", "required": [ "type_url", @@ -1991,7 +1991,7 @@ "default": [], "type": "array", "items": { - "$ref": "#/definitions/MsgResponseValue" + "$ref": "#/definitions/MsgResponse" } } } From 9b68dee1b8e3a505041dc43b958dc94060261da6 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 22 Nov 2023 10:21:13 +0000 Subject: [PATCH 08/11] Improve deprecation msg --- packages/std/src/results/submessages.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index 1f9a0a6ef1..bd9801f249 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -204,7 +204,7 @@ impl From for Result { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct SubMsgResponse { pub events: Vec, - #[deprecated = "deprecated in the cosmos-sdk in favor of msg_responses"] + #[deprecated = "Deprecated in the Cosmos SDK in favor of msg_responses. If your chain is running on CosmWasm 2.0 or higher, msg_responses will be filled. For older versions, the data field is still needed since msg_responses is empty in those cases."] pub data: Option, #[serde(default)] pub msg_responses: Vec, From 4a0d6e105e3c4ef83caf9072976612ae23d28c25 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 22 Nov 2023 17:34:37 +0100 Subject: [PATCH 09/11] Improve SubMsgResult test Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> --- packages/std/src/results/submessages.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index bd9801f249..3186ad5fa7 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -255,7 +255,7 @@ mod tests { #[test] fn sub_msg_result_deserialization_works() { // should work without `msg_responses` - let result: SubMsgResult = from_json(br#"{"ok":{"events":[],"data":null}}"#).unwrap(); + let result: SubMsgResult = from_json(br#"{"ok":{"events":[]}}"#).unwrap(); assert_eq!( result, SubMsgResult::Ok(SubMsgResponse { From 92f5512f67b4e7ef4eb529cde7435567e99058bc Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Wed, 22 Nov 2023 17:22:27 +0000 Subject: [PATCH 10/11] Add test for pre-2.0 SubMsgResponse --- packages/std/src/results/submessages.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs index 3186ad5fa7..5d58e87d2c 100644 --- a/packages/std/src/results/submessages.rs +++ b/packages/std/src/results/submessages.rs @@ -265,6 +265,18 @@ mod tests { }) ); + // should work with `data` and no `msg_responses` + // this is the case for pre-2.0 CosmWasm chains + let result: SubMsgResult = from_json(br#"{"ok":{"events":[],"data":"aGk="}}"#).unwrap(); + assert_eq!( + result, + SubMsgResult::Ok(SubMsgResponse { + events: vec![], + data: Some(Binary::from_base64("aGk=").unwrap()), + msg_responses: vec![] + }) + ); + let result: SubMsgResult = from_json( br#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg==", "msg_responses":[{"type_url":"URL","value":"MTIzCg=="}]}}"#).unwrap(); From 89d00e18160a724d596bdd8f6e462ccd87b7bbf5 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Thu, 23 Nov 2023 12:18:52 +0000 Subject: [PATCH 11/11] Add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e922810d52..ed9c9f0594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,11 @@ and this project adheres to - cosmwasm-std: Add `SubMsg:reply_never` constructor ([#1929]) - cosmwasm-std: Add optional memo field to `IbcMsg::Transfer`. ([#1878]) - cosmwasm-std: Add `Reply::gas_used`. ([#1954]) +- cosmwasm-std: Add `SubMsgResponse::msg_responses` and deprecate + `SubMsgResponse::data`. ([#1903]) [#1878]: https://github.com/CosmWasm/cosmwasm/pull/1878 +[#1903]: https://github.com/CosmWasm/cosmwasm/pull/1903 [#1929]: https://github.com/CosmWasm/cosmwasm/pull/1929 [#1954]: https://github.com/CosmWasm/cosmwasm/pull/1954