Skip to content

Commit 1fc1db0

Browse files
authored
Merge pull request #910 from CosmWasm/remove-unneeded-callback
Remove unneeded callback
2 parents d9a13b5 + 058fbca commit 1fc1db0

File tree

7 files changed

+40
-133
lines changed

7 files changed

+40
-133
lines changed

contracts/ibc-reflect/src/contract.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use cosmwasm_std::{
2-
attr, entry_point, from_slice, to_binary, wasm_execute, wasm_instantiate, BankMsg, Binary,
3-
ContractResult, CosmosMsg, Deps, DepsMut, Empty, Env, Event, IbcAcknowledgement,
4-
IbcBasicResponse, IbcChannel, IbcOrder, IbcPacket, IbcReceiveResponse, MessageInfo, Order,
5-
QueryResponse, Reply, ReplyOn, Response, StdError, StdResult, SubMsg, SubcallResponse,
2+
attr, entry_point, from_slice, to_binary, wasm_execute, BankMsg, Binary, ContractResult,
3+
CosmosMsg, Deps, DepsMut, Empty, Env, Event, IbcAcknowledgement, IbcBasicResponse, IbcChannel,
4+
IbcOrder, IbcPacket, IbcReceiveResponse, MessageInfo, Order, QueryResponse, Reply, ReplyOn,
5+
Response, StdError, StdResult, SubMsg, SubcallResponse, WasmMsg,
66
};
77

88
use crate::msg::{
99
AccountInfo, AccountResponse, AcknowledgementMsg, BalancesResponse, DispatchResponse,
10-
InstantiateMsg, ListAccountsResponse, PacketMsg, QueryMsg, ReflectExecuteMsg,
11-
ReflectInstantiateMsg, WhoAmIResponse,
10+
InstantiateMsg, ListAccountsResponse, PacketMsg, QueryMsg, ReflectExecuteMsg, WhoAmIResponse,
1211
};
1312
use crate::state::{accounts, accounts_read, config, pending_channel, Config};
1413

@@ -161,12 +160,13 @@ pub fn ibc_channel_connect(
161160
let cfg = config(deps.storage).load()?;
162161
let chan_id = channel.endpoint.channel_id;
163162

164-
let label = format!("ibc-reflect-{}", &chan_id);
165-
let payload = ReflectInstantiateMsg {
166-
callback_id: Some(chan_id.clone()),
163+
let msg = WasmMsg::Instantiate {
164+
admin: None,
165+
code_id: cfg.reflect_code_id,
166+
msg: b"{}".into(),
167+
send: vec![],
168+
label: format!("ibc-reflect-{}", &chan_id),
167169
};
168-
let msg = wasm_instantiate(cfg.reflect_code_id, &payload, vec![], label)?;
169-
170170
let sub_msg = SubMsg {
171171
id: INIT_CALLBACK_ID,
172172
msg: msg.into(),
@@ -476,7 +476,7 @@ mod tests {
476476
if let CosmosMsg::Wasm(WasmMsg::Instantiate {
477477
admin,
478478
code_id,
479-
msg,
479+
msg: _,
480480
send,
481481
label,
482482
}) = &res.submessages[0].msg
@@ -485,9 +485,6 @@ mod tests {
485485
assert_eq!(*code_id, REFLECT_ID);
486486
assert_eq!(send.len(), 0);
487487
assert!(label.contains(channel_id));
488-
// parse the message - should callback with proper channel_id
489-
let rmsg: ReflectInstantiateMsg = from_slice(&msg).unwrap();
490-
assert_eq!(rmsg.callback_id, Some(channel_id.to_string()));
491488
} else {
492489
panic!("invalid return message: {:?}", res.messages[0]);
493490
}

contracts/ibc-reflect/src/msg.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ pub struct AccountInfo {
3535
pub channel_id: String,
3636
}
3737

38-
/// This is the message we send to the reflect contract to initialize it
39-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
40-
pub struct ReflectInstantiateMsg {
41-
pub callback_id: Option<String>,
42-
}
43-
4438
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
4539
#[serde(rename_all = "snake_case")]
4640
pub enum ReflectExecuteMsg {

contracts/ibc-reflect/tests/integration.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use cosmwasm_vm::{from_slice, Instance};
3131
use ibc_reflect::contract::{IBC_VERSION, RECEIVE_DISPATCH_ID};
3232
use ibc_reflect::msg::{
3333
AccountInfo, AccountResponse, AcknowledgementMsg, DispatchResponse, InstantiateMsg,
34-
ListAccountsResponse, PacketMsg, QueryMsg, ReflectExecuteMsg, ReflectInstantiateMsg,
34+
ListAccountsResponse, PacketMsg, QueryMsg, ReflectExecuteMsg,
3535
};
3636

3737
// This line will test the output of cargo wasm
@@ -144,7 +144,7 @@ fn proper_handshake_flow() {
144144
if let CosmosMsg::Wasm(WasmMsg::Instantiate {
145145
admin,
146146
code_id,
147-
msg,
147+
msg: _,
148148
send,
149149
label,
150150
}) = &res.submessages[0].msg
@@ -153,9 +153,6 @@ fn proper_handshake_flow() {
153153
assert_eq!(*code_id, REFLECT_ID);
154154
assert_eq!(send.len(), 0);
155155
assert!(label.contains(channel_id));
156-
// parse the message - should callback with proper channel_id
157-
let rmsg: ReflectInstantiateMsg = from_slice(&msg).unwrap();
158-
assert_eq!(rmsg.callback_id, Some(channel_id.to_string()));
159156
} else {
160157
panic!("invalid return message: {:?}", res.messages[0]);
161158
}
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "InstantiateMsg",
4-
"type": "object",
5-
"properties": {
6-
"callback_id": {
7-
"description": "if set, returns CallbackMsg::InstantiateCallback{} to the caller with this contract's address and this id",
8-
"type": [
9-
"string",
10-
"null"
11-
]
12-
}
13-
}
4+
"type": "object"
145
}

contracts/reflect/src/contract.rs

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,25 @@
11
use cosmwasm_std::{
22
attr, entry_point, to_binary, to_vec, Binary, ContractResult, CosmosMsg, Deps, DepsMut, Env,
33
MessageInfo, QueryRequest, QueryResponse, Reply, Response, StdError, StdResult, SubMsg,
4-
SystemResult, WasmMsg,
4+
SystemResult,
55
};
66

77
use crate::errors::ReflectError;
88
use crate::msg::{
9-
CallbackMsg, CapitalizedResponse, ChainResponse, CustomMsg, ExecuteMsg, InstantiateMsg,
10-
OwnerResponse, QueryMsg, RawResponse, SpecialQuery, SpecialResponse,
9+
CapitalizedResponse, ChainResponse, CustomMsg, ExecuteMsg, InstantiateMsg, OwnerResponse,
10+
QueryMsg, RawResponse, SpecialQuery, SpecialResponse,
1111
};
1212
use crate::state::{config, config_read, replies, replies_read, State};
1313

1414
pub fn instantiate(
1515
deps: DepsMut,
16-
env: Env,
16+
_env: Env,
1717
info: MessageInfo,
18-
msg: InstantiateMsg,
18+
_msg: InstantiateMsg,
1919
) -> StdResult<Response<CustomMsg>> {
20-
let state = State {
21-
owner: info.sender.clone(),
22-
};
20+
let state = State { owner: info.sender };
2321
config(deps.storage).save(&state)?;
24-
25-
let mut resp = Response::new();
26-
if let Some(id) = msg.callback_id {
27-
let data = CallbackMsg::InitCallback {
28-
id,
29-
contract_addr: env.contract.address.into(),
30-
};
31-
let msg = WasmMsg::Execute {
32-
contract_addr: info.sender.into(),
33-
msg: to_binary(&data)?,
34-
send: vec![],
35-
};
36-
resp.add_message(msg);
37-
}
38-
Ok(resp)
22+
Ok(Response::default())
3923
}
4024

4125
pub fn execute(
@@ -202,7 +186,7 @@ mod tests {
202186
fn proper_instantialization() {
203187
let mut deps = mock_dependencies_with_custom_querier(&[]);
204188

205-
let msg = InstantiateMsg { callback_id: None };
189+
let msg = InstantiateMsg {};
206190
let info = mock_info("creator", &coins(1000, "earth"));
207191

208192
// we can just call .unwrap() to assert this was a success
@@ -214,50 +198,11 @@ mod tests {
214198
assert_eq!("creator", value.owner.as_str());
215199
}
216200

217-
#[test]
218-
fn instantiate_with_callback() {
219-
let mut deps = mock_dependencies_with_custom_querier(&[]);
220-
let caller = String::from("calling-contract");
221-
222-
let msg = InstantiateMsg {
223-
callback_id: Some("foobar".to_string()),
224-
};
225-
let info = mock_info(&caller, &coins(1000, "earth"));
226-
227-
// we can just call .unwrap() to assert this was a success
228-
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
229-
assert_eq!(1, res.messages.len());
230-
let msg = &res.messages[0];
231-
match msg {
232-
CosmosMsg::Wasm(WasmMsg::Execute {
233-
contract_addr,
234-
msg,
235-
send,
236-
}) => {
237-
assert_eq!(contract_addr.as_str(), &caller);
238-
let parsed: CallbackMsg = from_binary(&msg).unwrap();
239-
assert_eq!(
240-
parsed,
241-
CallbackMsg::InitCallback {
242-
id: "foobar".to_string(),
243-
contract_addr: MOCK_CONTRACT_ADDR.into(),
244-
}
245-
);
246-
assert_eq!(0, send.len());
247-
}
248-
_ => panic!("expect wasm execute message"),
249-
}
250-
251-
// it worked, let's query the state
252-
let value = query_owner(deps.as_ref()).unwrap();
253-
assert_eq!(value.owner, caller);
254-
}
255-
256201
#[test]
257202
fn reflect() {
258203
let mut deps = mock_dependencies_with_custom_querier(&[]);
259204

260-
let msg = InstantiateMsg { callback_id: None };
205+
let msg = InstantiateMsg {};
261206
let info = mock_info("creator", &coins(2, "token"));
262207
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
263208

@@ -279,7 +224,7 @@ mod tests {
279224
fn reflect_requires_owner() {
280225
let mut deps = mock_dependencies_with_custom_querier(&[]);
281226

282-
let msg = InstantiateMsg { callback_id: None };
227+
let msg = InstantiateMsg {};
283228
let info = mock_info("creator", &coins(2, "token"));
284229
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
285230

@@ -303,7 +248,7 @@ mod tests {
303248
fn reflect_reject_empty_msgs() {
304249
let mut deps = mock_dependencies_with_custom_querier(&[]);
305250

306-
let msg = InstantiateMsg { callback_id: None };
251+
let msg = InstantiateMsg {};
307252
let info = mock_info("creator", &coins(2, "token"));
308253
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
309254

@@ -319,7 +264,7 @@ mod tests {
319264
fn reflect_multiple_messages() {
320265
let mut deps = mock_dependencies_with_custom_querier(&[]);
321266

322-
let msg = InstantiateMsg { callback_id: None };
267+
let msg = InstantiateMsg {};
323268
let info = mock_info("creator", &coins(2, "token"));
324269
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
325270

@@ -351,7 +296,7 @@ mod tests {
351296
fn change_owner_works() {
352297
let mut deps = mock_dependencies_with_custom_querier(&[]);
353298

354-
let msg = InstantiateMsg { callback_id: None };
299+
let msg = InstantiateMsg {};
355300
let info = mock_info("creator", &coins(2, "token"));
356301
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
357302

@@ -370,7 +315,7 @@ mod tests {
370315
fn change_owner_requires_current_owner_as_sender() {
371316
let mut deps = mock_dependencies_with_custom_querier(&[]);
372317

373-
let msg = InstantiateMsg { callback_id: None };
318+
let msg = InstantiateMsg {};
374319
let creator = String::from("creator");
375320
let info = mock_info(&creator, &coins(2, "token"));
376321
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
@@ -395,7 +340,7 @@ mod tests {
395340
let mut deps = mock_dependencies_with_custom_querier(&[]);
396341
let creator = String::from("creator");
397342

398-
let msg = InstantiateMsg { callback_id: None };
343+
let msg = InstantiateMsg {};
399344
let info = mock_info(&creator, &coins(2, "token"));
400345
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
401346

@@ -454,7 +399,7 @@ mod tests {
454399
fn reflect_subcall() {
455400
let mut deps = mock_dependencies_with_custom_querier(&[]);
456401

457-
let msg = InstantiateMsg { callback_id: None };
402+
let msg = InstantiateMsg {};
458403
let info = mock_info("creator", &coins(2, "token"));
459404
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
460405

@@ -486,7 +431,7 @@ mod tests {
486431
fn reply_and_query() {
487432
let mut deps = mock_dependencies_with_custom_querier(&[]);
488433

489-
let msg = InstantiateMsg { callback_id: None };
434+
let msg = InstantiateMsg {};
490435
let info = mock_info("creator", &coins(2, "token"));
491436
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
492437

contracts/reflect/src/msg.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,7 @@ use serde::{Deserialize, Serialize};
44
use cosmwasm_std::{Binary, CosmosMsg, CustomQuery, QueryRequest, SubMsg};
55

66
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
7-
pub struct InstantiateMsg {
8-
/// if set, returns CallbackMsg::InstantiateCallback{} to the caller with this contract's address
9-
/// and this id
10-
pub callback_id: Option<String>,
11-
}
12-
13-
/// This is what we return upon init if callback is set
14-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
15-
#[serde(rename_all = "snake_case")]
16-
pub enum CallbackMsg {
17-
/// This type must match [ExecuteMsg::InitCallback from ibc-reflect](https://github.com/CosmWasm/cosmwasm/blob/9fd06ea/contracts/ibc-reflect/src/msg.rs#L17-L22).
18-
InitCallback {
19-
/// Callback ID provided in the InstantiateMsg
20-
id: String,
21-
/// contract_addr is the address of this contract
22-
contract_addr: String,
23-
},
24-
}
7+
pub struct InstantiateMsg {}
258

269
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2710
#[serde(rename_all = "snake_case")]

contracts/reflect/tests/integration.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn mock_dependencies_with_custom_querier(
6060
fn proper_initialization() {
6161
let mut deps = mock_instance(WASM, &[]);
6262

63-
let msg = InstantiateMsg { callback_id: None };
63+
let msg = InstantiateMsg {};
6464
let info = mock_info("creator", &coins(1000, "earth"));
6565

6666
// we can just call .unwrap() to assert this was a success
@@ -77,7 +77,7 @@ fn proper_initialization() {
7777
fn reflect() {
7878
let mut deps = mock_instance(WASM, &[]);
7979

80-
let msg = InstantiateMsg { callback_id: None };
80+
let msg = InstantiateMsg {};
8181
let info = mock_info("creator", &coins(2, "token"));
8282
let _res: Response<CustomMsg> = instantiate(&mut deps, mock_env(), info, msg).unwrap();
8383

@@ -110,7 +110,7 @@ fn reflect() {
110110
fn reflect_requires_owner() {
111111
let mut deps = mock_instance(WASM, &[]);
112112

113-
let msg = InstantiateMsg { callback_id: None };
113+
let msg = InstantiateMsg {};
114114
let info = mock_info("creator", &coins(2, "token"));
115115
let _res: Response<CustomMsg> = instantiate(&mut deps, mock_env(), info, msg).unwrap();
116116

@@ -132,7 +132,7 @@ fn reflect_requires_owner() {
132132
fn transfer() {
133133
let mut deps = mock_instance(WASM, &[]);
134134

135-
let msg = InstantiateMsg { callback_id: None };
135+
let msg = InstantiateMsg {};
136136
let info = mock_info("creator", &coins(2, "token"));
137137
let _res: Response<CustomMsg> = instantiate(&mut deps, mock_env(), info, msg).unwrap();
138138

@@ -152,7 +152,7 @@ fn transfer() {
152152
fn transfer_requires_owner() {
153153
let mut deps = mock_instance(WASM, &[]);
154154

155-
let msg = InstantiateMsg { callback_id: None };
155+
let msg = InstantiateMsg {};
156156
let info = mock_info("creator", &coins(2, "token"));
157157
let _res: Response<CustomMsg> = instantiate(&mut deps, mock_env(), info, msg).unwrap();
158158

@@ -190,7 +190,7 @@ fn dispatch_custom_query() {
190190
fn reflect_subcall() {
191191
let mut deps = mock_instance(WASM, &[]);
192192

193-
let msg = InstantiateMsg { callback_id: None };
193+
let msg = InstantiateMsg {};
194194
let info = mock_info("creator", &coins(2, "token"));
195195
let _res: Response = instantiate(&mut deps, mock_env(), info, msg).unwrap();
196196

@@ -222,7 +222,7 @@ fn reflect_subcall() {
222222
fn reply_and_query() {
223223
let mut deps = mock_instance(WASM, &[]);
224224

225-
let msg = InstantiateMsg { callback_id: None };
225+
let msg = InstantiateMsg {};
226226
let info = mock_info("creator", &coins(2, "token"));
227227
let _res: Response = instantiate(&mut deps, mock_env(), info, msg).unwrap();
228228

0 commit comments

Comments
 (0)