From b2071b742624d44af3aa0bdb0aeb807f65e862a1 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 26 Aug 2021 20:09:00 +0200 Subject: [PATCH 1/4] Use QuerierWrapper not Querier in cw20 helpers --- packages/cw20/src/helpers.rs | 103 ++++++++++++++--------------------- 1 file changed, 42 insertions(+), 61 deletions(-) diff --git a/packages/cw20/src/helpers.rs b/packages/cw20/src/helpers.rs index f38ef3386..1b1f2c067 100644 --- a/packages/cw20/src/helpers.rs +++ b/packages/cw20/src/helpers.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_binary, Addr, CosmosMsg, CustomQuery, Querier, QuerierWrapper, StdResult, Uint128, WasmMsg, - WasmQuery, + to_binary, Addr, CosmosMsg, CustomQuery, QuerierWrapper, QueryRequest, StdResult, Uint128, + WasmMsg, WasmQuery, }; use crate::{ @@ -31,89 +31,70 @@ impl Cw20Contract { .into()) } - /// Get token balance for the given address - pub fn balance(&self, querier: &Q, address: T) -> StdResult - where - Q: Querier, - T: Into, - CQ: CustomQuery, - { - let msg = Cw20QueryMsg::Balance { - address: address.into(), - }; - let query = WasmQuery::Smart { + fn encode_smart_query( + &self, + msg: Cw20QueryMsg, + ) -> StdResult> { + Ok(WasmQuery::Smart { contract_addr: self.addr().into(), msg: to_binary(&msg)?, } - .into(); - let res: BalanceResponse = QuerierWrapper::::new(querier).query(&query)?; + .into()) + } + + /// Get token balance for the given address + pub fn balance, CQ: CustomQuery>( + &self, + querier: &QuerierWrapper, + address: T, + ) -> StdResult { + let query = self.encode_smart_query(Cw20QueryMsg::Balance { + address: address.into(), + })?; + let res: BalanceResponse = querier.query(&query)?; Ok(res.balance) } /// Get metadata from the contract. This is a good check that the address /// is a valid Cw20 contract. - pub fn meta(&self, querier: &Q) -> StdResult - where - Q: Querier, - CQ: CustomQuery, - { - let msg = Cw20QueryMsg::TokenInfo {}; - let query = WasmQuery::Smart { - contract_addr: self.addr().into(), - msg: to_binary(&msg)?, - } - .into(); - QuerierWrapper::::new(querier).query(&query) + pub fn meta( + &self, + querier: &QuerierWrapper, + ) -> StdResult { + let query = self.encode_smart_query(Cw20QueryMsg::TokenInfo {})?; + querier.query(&query) } /// Get allowance of spender to use owner's account - pub fn allowance( + pub fn allowance, U: Into, CQ: CustomQuery>( &self, - querier: &Q, + querier: &QuerierWrapper, owner: T, spender: U, - ) -> StdResult - where - Q: Querier, - T: Into, - U: Into, - CQ: CustomQuery, - { - let msg = Cw20QueryMsg::Allowance { + ) -> StdResult { + let query = self.encode_smart_query(Cw20QueryMsg::Allowance { owner: owner.into(), spender: spender.into(), - }; - let query = WasmQuery::Smart { - contract_addr: self.addr().into(), - msg: to_binary(&msg)?, - } - .into(); - QuerierWrapper::::new(querier).query(&query) + })?; + querier.query(&query) } /// Find info on who can mint, and how much - pub fn minter(&self, querier: &Q) -> StdResult> - where - Q: Querier, - CQ: CustomQuery, - { - let msg = Cw20QueryMsg::Minter {}; - let query = WasmQuery::Smart { - contract_addr: self.addr().into(), - msg: to_binary(&msg)?, - } - .into(); - QuerierWrapper::::new(querier).query(&query) + pub fn minter( + &self, + querier: &QuerierWrapper, + ) -> StdResult> { + let query = self.encode_smart_query(Cw20QueryMsg::Minter {})?; + querier.query(&query) } /// returns true if the contract supports the allowance extension - pub fn has_allowance(&self, querier: &Q) -> bool { - self.allowance::<_, _, _, CQ>(querier, self.addr(), self.addr()) - .is_ok() + pub fn has_allowance(&self, querier: &QuerierWrapper) -> bool { + self.allowance(querier, self.addr(), self.addr()).is_ok() } /// returns true if the contract supports the mintable extension - pub fn is_mintable(&self, querier: &Q) -> bool { - self.minter::<_, CQ>(querier).is_ok() + pub fn is_mintable(&self, querier: &QuerierWrapper) -> bool { + self.minter(querier).is_ok() } } From 2191c7a94edd4d73646314dff502fbe5c4cc721f Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Tue, 25 Oct 2022 18:01:13 +0200 Subject: [PATCH 2/4] cw20: style --- packages/cw20/src/helpers.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/cw20/src/helpers.rs b/packages/cw20/src/helpers.rs index 1b1f2c067..78f13a136 100644 --- a/packages/cw20/src/helpers.rs +++ b/packages/cw20/src/helpers.rs @@ -43,11 +43,11 @@ impl Cw20Contract { } /// Get token balance for the given address - pub fn balance, CQ: CustomQuery>( - &self, - querier: &QuerierWrapper, - address: T, - ) -> StdResult { + pub fn balance(&self, querier: &QuerierWrapper, address: T) -> StdResult + where + T: Into, + CQ: CustomQuery, + { let query = self.encode_smart_query(Cw20QueryMsg::Balance { address: address.into(), })?; @@ -66,12 +66,17 @@ impl Cw20Contract { } /// Get allowance of spender to use owner's account - pub fn allowance, U: Into, CQ: CustomQuery>( + pub fn allowance( &self, querier: &QuerierWrapper, owner: T, spender: U, - ) -> StdResult { + ) -> StdResult + where + T: Into, + U: Into, + CQ: CustomQuery, + { let query = self.encode_smart_query(Cw20QueryMsg::Allowance { owner: owner.into(), spender: spender.into(), From 87df7f2e8b4bdc32267f980392c9690ae1c8db06 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Tue, 25 Oct 2022 18:22:47 +0200 Subject: [PATCH 3/4] Use QuerierWrapper not Querier in cw2 helpers --- packages/cw2/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/cw2/src/lib.rs b/packages/cw2/src/lib.rs index 12cb7b594..aae498609 100644 --- a/packages/cw2/src/lib.rs +++ b/packages/cw2/src/lib.rs @@ -18,7 +18,7 @@ For more information on this specification, please check out the */ use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Empty, Querier, QuerierWrapper, QueryRequest, StdResult, Storage, WasmQuery}; +use cosmwasm_std::{CustomQuery, QuerierWrapper, QueryRequest, StdResult, Storage, WasmQuery}; use cw_storage_plus::Item; pub const CONTRACT: Item = Item::new("contract_info"); @@ -59,15 +59,19 @@ pub fn set_contract_version, U: Into>( /// if the other contract exists and claims to be a cw20-base contract for example. /// (Note: you usually want to require *interfaces* not *implementations* of the /// contracts you compose with, so be careful of overuse) -pub fn query_contract_info>( - querier: &Q, +pub fn query_contract_info( + querier: &QuerierWrapper, contract_addr: T, -) -> StdResult { +) -> StdResult +where + T: Into, + CQ: CustomQuery, +{ let req = QueryRequest::Wasm(WasmQuery::Raw { contract_addr: contract_addr.into(), key: CONTRACT.as_slice().into(), }); - QuerierWrapper::::new(querier).query(&req) + querier.query(&req) } #[cfg(test)] From 06f126d9fc7e0ed9d1102b725db8181ba094f464 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Tue, 25 Oct 2022 18:29:54 +0200 Subject: [PATCH 4/4] Fix cw3-fixed-multisig --- contracts/cw3-flex-multisig/src/contract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/cw3-flex-multisig/src/contract.rs b/contracts/cw3-flex-multisig/src/contract.rs index 2b473a250..36d4d1afb 100644 --- a/contracts/cw3-flex-multisig/src/contract.rs +++ b/contracts/cw3-flex-multisig/src/contract.rs @@ -690,7 +690,7 @@ mod tests { .unwrap(); // Verify contract version set properly - let version = query_contract_info(&app, flex_addr.clone()).unwrap(); + let version = query_contract_info(&app.wrap(), flex_addr.clone()).unwrap(); assert_eq!( ContractVersion { contract: CONTRACT_NAME.to_string(),