Skip to content

Commit 1fbcf14

Browse files
authored
Merge pull request #1903 from CosmWasm/1621-sub-msg-response
[2.0] Add `msg_responses` to SubMsgResponse
2 parents 8fe095f + 89d00e1 commit 1fbcf14

File tree

10 files changed

+133
-13
lines changed

10 files changed

+133
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ and this project adheres to
1111
- cosmwasm-std: Add `SubMsg:reply_never` constructor ([#1929])
1212
- cosmwasm-std: Add optional memo field to `IbcMsg::Transfer`. ([#1878])
1313
- cosmwasm-std: Add `Reply::gas_used`. ([#1954])
14+
- cosmwasm-std: Add `SubMsgResponse::msg_responses` and deprecate
15+
`SubMsgResponse::data`. ([#1903])
1416

1517
[#1878]: https://github.com/CosmWasm/cosmwasm/pull/1878
18+
[#1903]: https://github.com/CosmWasm/cosmwasm/pull/1903
1619
[#1929]: https://github.com/CosmWasm/cosmwasm/pull/1929
1720
[#1954]: https://github.com/CosmWasm/cosmwasm/pull/1954
1821

contracts/ibc-reflect/src/contract.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,13 @@ mod tests {
402402
let id = res.messages[0].id;
403403

404404
// fake a reply and ensure this works
405+
#[allow(deprecated)]
405406
let response = Reply {
406407
id,
407408
gas_used: 1234567,
408409
result: SubMsgResult::Ok(SubMsgResponse {
409410
events: fake_events(&account),
411+
msg_responses: vec![],
410412
data: None,
411413
}),
412414
};
@@ -480,11 +482,13 @@ mod tests {
480482
assert_eq!(0, res.accounts.len());
481483

482484
// fake a reply and ensure this works
485+
#[allow(deprecated)]
483486
let response = Reply {
484487
id,
485488
gas_used: 1234567,
486489
result: SubMsgResult::Ok(SubMsgResponse {
487490
events: fake_events(REFLECT_ADDR),
491+
msg_responses: vec![],
488492
data: None,
489493
}),
490494
};

contracts/ibc-reflect/tests/integration.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ fn connect(
9393
let id = res.messages[0].id;
9494

9595
// fake a reply and ensure this works
96+
#[allow(deprecated)]
9697
let response = Reply {
9798
id,
9899
gas_used: 1234567,
99100
result: SubMsgResult::Ok(SubMsgResponse {
100101
events: fake_events(&account),
102+
msg_responses: vec![],
101103
data: None,
102104
}),
103105
};
@@ -172,11 +174,13 @@ fn proper_handshake_flow() {
172174
assert_eq!(0, res.accounts.len());
173175

174176
// we get the callback from reflect
177+
#[allow(deprecated)]
175178
let response = Reply {
176179
id,
177180
gas_used: 1234567,
178181
result: SubMsgResult::Ok(SubMsgResponse {
179182
events: fake_events(REFLECT_ADDR),
183+
msg_responses: vec![],
180184
data: None,
181185
}),
182186
};

contracts/reflect/schema/raw/response_to_sub_msg_result.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@
6767
}
6868
}
6969
},
70+
"MsgResponse": {
71+
"type": "object",
72+
"required": [
73+
"type_url",
74+
"value"
75+
],
76+
"properties": {
77+
"type_url": {
78+
"type": "string"
79+
},
80+
"value": {
81+
"$ref": "#/definitions/Binary"
82+
}
83+
}
84+
},
7085
"SubMsgResponse": {
7186
"description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.",
7287
"type": "object",
@@ -75,6 +90,7 @@
7590
],
7691
"properties": {
7792
"data": {
93+
"deprecated": true,
7894
"anyOf": [
7995
{
8096
"$ref": "#/definitions/Binary"
@@ -89,11 +105,18 @@
89105
"items": {
90106
"$ref": "#/definitions/Event"
91107
}
108+
},
109+
"msg_responses": {
110+
"default": [],
111+
"type": "array",
112+
"items": {
113+
"$ref": "#/definitions/MsgResponse"
114+
}
92115
}
93116
}
94117
},
95118
"SubMsgResult": {
96-
"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<SubMsgResponse>` 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\"}\"#); ```",
119+
"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<SubMsgResponse>` 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\"}\"#); ```",
97120
"oneOf": [
98121
{
99122
"type": "object",

contracts/reflect/schema/reflect.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,21 @@
19481948
}
19491949
}
19501950
},
1951+
"MsgResponse": {
1952+
"type": "object",
1953+
"required": [
1954+
"type_url",
1955+
"value"
1956+
],
1957+
"properties": {
1958+
"type_url": {
1959+
"type": "string"
1960+
},
1961+
"value": {
1962+
"$ref": "#/definitions/Binary"
1963+
}
1964+
}
1965+
},
19511966
"SubMsgResponse": {
19521967
"description": "The information we get back from a successful sub message execution, with full Cosmos SDK events.",
19531968
"type": "object",
@@ -1956,6 +1971,7 @@
19561971
],
19571972
"properties": {
19581973
"data": {
1974+
"deprecated": true,
19591975
"anyOf": [
19601976
{
19611977
"$ref": "#/definitions/Binary"
@@ -1970,11 +1986,18 @@
19701986
"items": {
19711987
"$ref": "#/definitions/Event"
19721988
}
1989+
},
1990+
"msg_responses": {
1991+
"default": [],
1992+
"type": "array",
1993+
"items": {
1994+
"$ref": "#/definitions/MsgResponse"
1995+
}
19731996
}
19741997
}
19751998
},
19761999
"SubMsgResult": {
1977-
"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<SubMsgResponse>` 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\"}\"#); ```",
2000+
"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<SubMsgResponse>` 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\"}\"#); ```",
19782001
"oneOf": [
19792002
{
19802003
"type": "object",

contracts/reflect/src/contract.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,11 @@ mod tests {
435435
let data = Binary::from(b"foobar");
436436
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
437437
let gas_used = 1234567u64;
438+
#[allow(deprecated)]
438439
let result = SubMsgResult::Ok(SubMsgResponse {
439440
events: events.clone(),
440441
data: Some(data.clone()),
442+
msg_responses: vec![],
441443
});
442444
let subcall = Reply {
443445
id,
@@ -460,7 +462,10 @@ mod tests {
460462
let qres: Reply = from_json(raw).unwrap();
461463
assert_eq!(qres.id, id);
462464
let result = qres.result.unwrap();
463-
assert_eq!(result.data, Some(data));
465+
#[allow(deprecated)]
466+
{
467+
assert_eq!(result.data, Some(data));
468+
}
464469
assert_eq!(result.events, events);
465470
}
466471
}

contracts/reflect/tests/integration.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,11 @@ fn reply_and_query() {
269269
let data = Binary::from(b"foobar");
270270
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
271271
let gas_used = 1234567u64;
272+
#[allow(deprecated)]
272273
let result = SubMsgResult::Ok(SubMsgResponse {
273274
events: events.clone(),
274275
data: Some(data.clone()),
276+
msg_responses: vec![],
275277
});
276278
let subcall = Reply {
277279
id,
@@ -290,6 +292,9 @@ fn reply_and_query() {
290292
let qres: Reply = from_json(raw).unwrap();
291293
assert_eq!(qres.id, id);
292294
let result = qres.result.unwrap();
293-
assert_eq!(result.data, Some(data));
295+
#[allow(deprecated)]
296+
{
297+
assert_eq!(result.data, Some(data));
298+
}
294299
assert_eq!(result.events, events);
295300
}

packages/std/src/results/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ pub use empty::Empty;
2323
pub use events::{attr, Attribute, Event};
2424
pub use query::QueryResponse;
2525
pub use response::Response;
26-
pub use submessages::{Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult};
26+
pub use submessages::{MsgResponse, Reply, ReplyOn, SubMsg, SubMsgResponse, SubMsgResult};
2727
pub use system_result::SystemResult;

0 commit comments

Comments
 (0)