diff --git a/packages/utils/src/calls.rs b/packages/utils/src/calls.rs index fa21835..16fae3c 100755 --- a/packages/utils/src/calls.rs +++ b/packages/utils/src/calls.rs @@ -1,8 +1,8 @@ use serde::{de::DeserializeOwned, Serialize}; use cosmwasm_std::{ - to_binary, Coin, CosmosMsg, CustomQuery, QuerierWrapper, QueryRequest, StdResult, Uint128, - WasmMsg, WasmQuery, + to_binary, Coin, CosmosMsg, CustomQuery, QuerierWrapper, QueryRequest, StdResult, WasmMsg, + WasmQuery, }; use super::space_pad; @@ -26,14 +26,14 @@ pub trait InitCallback: Serialize { /// * `label` - String holding the label for the new contract instance /// * `code_id` - code ID of the contract to be instantiated /// * `code_hash` - String holding the code hash of the contract to be instantiated - /// * `funds_amount` - Optional Uint128 amount of native coin to send with instantiation message + /// * `funds` - Vec of Coins to send with instantiation message fn to_cosmos_msg( &self, admin: Option, label: String, code_id: u64, code_hash: String, - funds_amount: Option, + funds: Vec, ) -> StdResult { let mut msg = to_binary(self)?; // can not have 0 block size @@ -43,19 +43,13 @@ pub trait InitCallback: Serialize { Self::BLOCK_SIZE }; space_pad(&mut msg.0, padding); - let mut funds = Vec::new(); - if let Some(amount) = funds_amount { - funds.push(Coin { - amount, - denom: String::from("uscrt"), - }); - } + let init = WasmMsg::Instantiate { admin, code_id, msg, code_hash, - funds, + funds, // Using the passed funds directly label, }; Ok(init.into()) @@ -80,12 +74,12 @@ pub trait HandleCallback: Serialize { /// /// * `code_hash` - String holding the code hash of the contract to be executed /// * `contract_addr` - address of the contract being called - /// * `funds_amount` - Optional Uint128 amount of native coin to send with the handle message + /// * `funds_amount` - Vec of Coins to send with the handle message fn to_cosmos_msg( &self, code_hash: String, contract_addr: String, - funds_amount: Option, + funds: Vec, ) -> StdResult { let mut msg = to_binary(self)?; // can not have 0 block size @@ -95,13 +89,7 @@ pub trait HandleCallback: Serialize { Self::BLOCK_SIZE }; space_pad(&mut msg.0, padding); - let mut funds = Vec::new(); - if let Some(amount) = funds_amount { - funds.push(Coin { - amount, - denom: String::from("uscrt"), - }); - } + let execute = WasmMsg::Execute { msg, contract_addr, @@ -156,6 +144,7 @@ mod tests { use super::*; use cosmwasm_std::{ to_vec, Binary, ContractResult, Empty, Querier, QuerierResult, SystemError, SystemResult, + Uint128, }; use serde::Deserialize; @@ -193,12 +182,10 @@ mod tests { let address = "secret1xyzasdf".to_string(); let hash = "asdf".to_string(); let amount = Uint128::new(1234); + let coin = vec![Coin::new(1234, "uscrt")]; - let cosmos_message: CosmosMsg = FooHandle::Var1 { f1: 1, f2: 2 }.to_cosmos_msg( - hash.clone(), - address.clone(), - Some(amount), - )?; + let cosmos_message: CosmosMsg = + FooHandle::Var1 { f1: 1, f2: 2 }.to_cosmos_msg(hash.clone(), address.clone(), coin)?; match cosmos_message { CosmosMsg::Wasm(WasmMsg::Execute { @@ -227,13 +214,14 @@ mod tests { let id = 17u64; let hash = "asdf".to_string(); let amount = Uint128::new(1234); + let coin = vec![Coin::new(1234, "uscrt")]; let cosmos_message: CosmosMsg = FooInit { f1: 1, f2: 2 }.to_cosmos_msg( Some(adm.clone()), lbl.clone(), id, hash.clone(), - Some(amount), + coin, )?; match cosmos_message {