Skip to content

Commit b0ff68d

Browse files
authored
Merge pull request #1954 from CosmWasm/1611-reply-gas-used
Add `gas_used` to `Reply`
2 parents 8a652d7 + 4a0fc53 commit b0ff68d

File tree

11 files changed

+41
-6
lines changed

11 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ and this project adheres to
1010

1111
- cosmwasm-std: Add `SubMsg:reply_never` constructor ([#1929])
1212
- cosmwasm-std: Add optional memo field to `IbcMsg::Transfer`. ([#1878])
13+
- cosmwasm-std: Add `Reply::gas_used`. ([#1954])
1314

1415
[#1878]: https://github.com/CosmWasm/cosmwasm/pull/1878
1516
[#1929]: https://github.com/CosmWasm/cosmwasm/pull/1929
17+
[#1954]: https://github.com/CosmWasm/cosmwasm/pull/1954
1618

1719
### Changed
1820

SEMANTICS.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
286286

287287
pub struct Reply {
288288
pub id: u64,
289-
/// ContractResult is just a nicely serializable version of `Result<SubcallResponse, String>`
290-
pub result: ContractResult<SubcallResponse>,
289+
pub gas_used: u64,
290+
/// SubMsgResult is just a nicely serializable version of `Result<SubMsgResponse, String>`
291+
pub result: SubMsgResult,
291292
}
292293

293-
pub struct SubcallResponse {
294+
pub struct SubMsgResponse {
294295
pub events: Vec<Event>,
295296
pub data: Option<Binary>,
296297
}

contracts/ibc-reflect/src/contract.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ mod tests {
404404
// fake a reply and ensure this works
405405
let response = Reply {
406406
id,
407+
gas_used: 1234567,
407408
result: SubMsgResult::Ok(SubMsgResponse {
408409
events: fake_events(&account),
409410
data: None,
@@ -481,6 +482,7 @@ mod tests {
481482
// fake a reply and ensure this works
482483
let response = Reply {
483484
id,
485+
gas_used: 1234567,
484486
result: SubMsgResult::Ok(SubMsgResponse {
485487
events: fake_events(REFLECT_ADDR),
486488
data: None,

contracts/ibc-reflect/tests/integration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ fn connect(
9595
// fake a reply and ensure this works
9696
let response = Reply {
9797
id,
98+
gas_used: 1234567,
9899
result: SubMsgResult::Ok(SubMsgResponse {
99100
events: fake_events(&account),
100101
data: None,
@@ -173,6 +174,7 @@ fn proper_handshake_flow() {
173174
// we get the callback from reflect
174175
let response = Reply {
175176
id,
177+
gas_used: 1234567,
176178
result: SubMsgResult::Ok(SubMsgResponse {
177179
events: fake_events(REFLECT_ADDR),
178180
data: None,

contracts/reflect/schema/raw/response_to_sub_msg_result.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
"description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.",
55
"type": "object",
66
"required": [
7+
"gas_used",
78
"id",
89
"result"
910
],
1011
"properties": {
12+
"gas_used": {
13+
"description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).",
14+
"type": "integer",
15+
"format": "uint64",
16+
"minimum": 0.0
17+
},
1118
"id": {
1219
"description": "The ID that the contract set when emitting the `SubMsg`. Use this to identify which submessage triggered the `reply`.",
1320
"type": "integer",

contracts/reflect/schema/reflect.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,10 +1885,17 @@
18851885
"description": "The result object returned to `reply`. We always get the ID from the submessage back and then must handle success and error cases ourselves.",
18861886
"type": "object",
18871887
"required": [
1888+
"gas_used",
18881889
"id",
18891890
"result"
18901891
],
18911892
"properties": {
1893+
"gas_used": {
1894+
"description": "The amount of gas used by the submessage, measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).",
1895+
"type": "integer",
1896+
"format": "uint64",
1897+
"minimum": 0.0
1898+
},
18921899
"id": {
18931900
"description": "The ID that the contract set when emitting the `SubMsg`. Use this to identify which submessage triggered the `reply`.",
18941901
"type": "integer",

contracts/reflect/src/contract.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,16 @@ mod tests {
434434
let id = 123u64;
435435
let data = Binary::from(b"foobar");
436436
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
437+
let gas_used = 1234567u64;
437438
let result = SubMsgResult::Ok(SubMsgResponse {
438439
events: events.clone(),
439440
data: Some(data.clone()),
440441
});
441-
let subcall = Reply { id, result };
442+
let subcall = Reply {
443+
id,
444+
gas_used,
445+
result,
446+
};
442447
let res = reply(deps.as_mut(), mock_env(), subcall).unwrap();
443448
assert_eq!(0, res.messages.len());
444449

contracts/reflect/tests/integration.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,16 @@ fn reply_and_query() {
268268
let id = 123u64;
269269
let data = Binary::from(b"foobar");
270270
let events = vec![Event::new("message").add_attribute("signer", "caller-addr")];
271+
let gas_used = 1234567u64;
271272
let result = SubMsgResult::Ok(SubMsgResponse {
272273
events: events.clone(),
273274
data: Some(data.clone()),
274275
});
275-
let subcall = Reply { id, result };
276+
let subcall = Reply {
277+
id,
278+
gas_used,
279+
result,
280+
};
276281
let res: Response = reply(&mut deps, mock_env(), subcall).unwrap();
277282
assert_eq!(0, res.messages.len());
278283

packages/go-gen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod schema;
1111
mod utils;
1212

1313
fn main() -> Result<()> {
14-
let root = cosmwasm_schema::schema_for!(cosmwasm_std::BankQuery);
14+
let root = cosmwasm_schema::schema_for!(cosmwasm_std::Reply);
1515

1616
let code = generate_go(root)?;
1717
println!("{}", code);

packages/std/src/results/submessages.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ pub struct Reply {
102102
/// The ID that the contract set when emitting the `SubMsg`.
103103
/// Use this to identify which submessage triggered the `reply`.
104104
pub id: u64,
105+
/// The amount of gas used by the submessage,
106+
/// measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
107+
pub gas_used: u64,
105108
pub result: SubMsgResult,
106109
}
107110

0 commit comments

Comments
 (0)