forked from icon-project/xcall-multi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdapp.rs
52 lines (47 loc) · 1.49 KB
/
dapp.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use cosmwasm_std::{to_binary, Addr, Binary, CosmosMsg, MessageInfo, StdError, SubMsg, WasmMsg};
use cw_xcall_lib::{dapp_msg, dapp_multi_msg, network_address::NetworkAddress};
use crate::{error::ContractError, state::CwCallService};
impl<'a> CwCallService<'a> {
pub fn call_dapp_handle_message(
&self,
info: MessageInfo,
to: Addr,
from: NetworkAddress,
data: Vec<u8>,
protocols: Vec<String>,
reply_id: u64,
) -> Result<SubMsg, ContractError> {
let cosm_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: to.to_string(),
msg: self
.get_handle_message(from, data, protocols)
.map_err(ContractError::Std)?,
funds: info.funds,
});
let submessage = SubMsg {
id: reply_id,
msg: cosm_msg,
gas_limit: None,
reply_on: cosmwasm_std::ReplyOn::Always,
};
Ok(submessage)
}
pub fn get_handle_message(
&self,
from: NetworkAddress,
data: Vec<u8>,
protocols: Vec<String>,
) -> Result<Binary, StdError> {
if protocols.is_empty() {
let message = dapp_msg::ExecuteMsg::HandleCallMessage { from, data };
let msg = to_binary(&message);
return msg;
}
let message = dapp_multi_msg::ExecuteMsg::HandleCallMessage {
from,
data,
protocols,
};
to_binary(&message)
}
}