diff --git a/contracts/cw20-escrow/schema/details_response.json b/contracts/cw20-escrow/schema/details_response.json index 653de5dde..89b9ae6fc 100644 --- a/contracts/cw20-escrow/schema/details_response.json +++ b/contracts/cw20-escrow/schema/details_response.json @@ -5,6 +5,7 @@ "required": [ "arbiter", "cw20_balance", + "cw20_whitelist", "id", "native_balance", "recipient", @@ -26,6 +27,13 @@ "$ref": "#/definitions/Cw20CoinHuman" } }, + "cw20_whitelist": { + "description": "Whitelisted cw20 tokens", + "type": "array", + "items": { + "$ref": "#/definitions/HumanAddr" + } + }, "end_height": { "description": "When end height set and block height exceeds this value, the escrow is expired. Once an escrow is expired, it can be returned to the original funder (via \"refund\").", "type": [ diff --git a/contracts/cw20-escrow/src/contract.rs b/contracts/cw20-escrow/src/contract.rs index 5c51a979a..a64ea7d37 100644 --- a/contracts/cw20-escrow/src/contract.rs +++ b/contracts/cw20-escrow/src/contract.rs @@ -313,6 +313,8 @@ fn query_details( ) -> StdResult { let escrow = escrows_read(&deps.storage).load(id.as_bytes())?; + let cw20_whitelist = escrow.human_whitelist(&deps.api)?; + // transform tokens let cw20_balance: StdResult> = escrow .cw20_balance @@ -334,6 +336,7 @@ fn query_details( end_time: escrow.end_time, native_balance: escrow.native_balance, cw20_balance: cw20_balance?, + cw20_whitelist, }; Ok(details) } @@ -369,7 +372,7 @@ mod tests { arbiter: HumanAddr::from("arbitrate"), recipient: HumanAddr::from("recd"), end_time: None, - end_height: None, + end_height: Some(123456), cw20_whitelist: None, }; let sender = HumanAddr::from("source"); @@ -379,6 +382,23 @@ mod tests { assert_eq!(0, res.messages.len()); assert_eq!(log("action", "create"), res.log[0]); + // ensure the details is what we expect + let details = query_details(&deps, "foobar".to_string()).unwrap(); + assert_eq!( + details, + DetailsResponse { + id: "foobar".to_string(), + arbiter: HumanAddr::from("arbitrate"), + recipient: HumanAddr::from("recd"), + source: HumanAddr::from("source"), + end_height: Some(123456), + end_time: None, + native_balance: balance.clone(), + cw20_balance: vec![], + cw20_whitelist: vec![], + } + ); + // approve it let id = create.id.clone(); let env = mock_env(&deps.api, &create.arbiter, &[]); @@ -421,7 +441,7 @@ mod tests { recipient: HumanAddr::from("recd"), end_time: None, end_height: None, - cw20_whitelist: None, + cw20_whitelist: Some(vec![HumanAddr::from("other-token")]), }; let receive = Cw20ReceiveMsg { sender: HumanAddr::from("source"), @@ -434,6 +454,29 @@ mod tests { assert_eq!(0, res.messages.len()); assert_eq!(log("action", "create"), res.log[0]); + // ensure the whitelist is what we expect + let details = query_details(&deps, "foobar".to_string()).unwrap(); + assert_eq!( + details, + DetailsResponse { + id: "foobar".to_string(), + arbiter: HumanAddr::from("arbitrate"), + recipient: HumanAddr::from("recd"), + source: HumanAddr::from("source"), + end_height: None, + end_time: None, + native_balance: vec![], + cw20_balance: vec![Cw20CoinHuman { + address: HumanAddr::from("my-cw20-token"), + amount: Uint128(100) + }], + cw20_whitelist: vec![ + HumanAddr::from("other-token"), + HumanAddr::from("my-cw20-token") + ], + } + ); + // approve it let id = create.id.clone(); let env = mock_env(&deps.api, &create.arbiter, &[]); diff --git a/contracts/cw20-escrow/src/msg.rs b/contracts/cw20-escrow/src/msg.rs index f1b8cd240..56c56a7e2 100644 --- a/contracts/cw20-escrow/src/msg.rs +++ b/contracts/cw20-escrow/src/msg.rs @@ -116,6 +116,8 @@ pub struct DetailsResponse { pub native_balance: Vec, /// Balance in cw20 tokens pub cw20_balance: Vec, + /// Whitelisted cw20 tokens + pub cw20_whitelist: Vec, } #[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] diff --git a/contracts/cw20-escrow/src/state.rs b/contracts/cw20-escrow/src/state.rs index 99686ea5c..0b552b7d6 100644 --- a/contracts/cw20-escrow/src/state.rs +++ b/contracts/cw20-escrow/src/state.rs @@ -2,7 +2,8 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use cosmwasm_std::{ - CanonicalAddr, Coin, Env, Order, ReadonlyStorage, StdError, StdResult, Storage, Uint128, + Api, CanonicalAddr, Coin, Env, HumanAddr, Order, ReadonlyStorage, StdError, StdResult, Storage, + Uint128, }; use cosmwasm_storage::{bucket, bucket_read, prefixed_read, Bucket, ReadonlyBucket}; @@ -51,6 +52,13 @@ impl Escrow { false } + + pub fn human_whitelist(&self, api: &A) -> StdResult> { + self.cw20_whitelist + .iter() + .map(|h| api.human_address(h)) + .collect() + } } pub const PREFIX_ESCROW: &[u8] = b"escrow";