diff --git a/contracts/cw20-atomic-swap/schema/execute_msg.json b/contracts/cw20-atomic-swap/schema/execute_msg.json index 71133e048..886a9f042 100644 --- a/contracts/cw20-atomic-swap/schema/execute_msg.json +++ b/contracts/cw20-atomic-swap/schema/execute_msg.json @@ -116,6 +116,7 @@ "type": "object", "required": [ "amount", + "msg", "sender" ], "properties": { @@ -123,14 +124,7 @@ "$ref": "#/definitions/Uint128" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" }, "sender": { "type": "string" diff --git a/contracts/cw20-atomic-swap/src/contract.rs b/contracts/cw20-atomic-swap/src/contract.rs index 061c5d745..06b62141f 100644 --- a/contracts/cw20-atomic-swap/src/contract.rs +++ b/contracts/cw20-atomic-swap/src/contract.rs @@ -57,10 +57,7 @@ pub fn execute_receive( info: MessageInfo, wrapper: Cw20ReceiveMsg, ) -> Result { - let msg: ReceiveMsg = match wrapper.msg { - Some(bin) => Ok(from_binary(&bin)?), - None => Err(ContractError::NoData {}), - }?; + let msg: ReceiveMsg = from_binary(&wrapper.msg)?; let token = Cw20CoinVerified { address: info.sender, amount: wrapper.amount, @@ -687,7 +684,7 @@ mod tests { let receive = Cw20ReceiveMsg { sender: cw20_sender, amount: cw20_coin.amount, - msg: Some(to_binary(&ExecuteMsg::Create(create)).unwrap()), + msg: to_binary(&ExecuteMsg::Create(create)).unwrap(), }; let token_contract = cw20_coin.address; let info = mock_info(&token_contract, &[]); diff --git a/contracts/cw20-atomic-swap/src/error.rs b/contracts/cw20-atomic-swap/src/error.rs index 8c00064e1..29d725666 100644 --- a/contracts/cw20-atomic-swap/src/error.rs +++ b/contracts/cw20-atomic-swap/src/error.rs @@ -6,9 +6,6 @@ pub enum ContractError { #[error("{0}")] Std(#[from] StdError), - #[error("No data in ReceiveMsg")] - NoData {}, - #[error("Hash parse error: {0}")] ParseError(String), diff --git a/contracts/cw20-base/schema/execute_msg.json b/contracts/cw20-base/schema/execute_msg.json index 771d9e1ad..55b1289bf 100644 --- a/contracts/cw20-base/schema/execute_msg.json +++ b/contracts/cw20-base/schema/execute_msg.json @@ -59,7 +59,8 @@ "type": "object", "required": [ "amount", - "contract" + "contract", + "msg" ], "properties": { "amount": { @@ -69,14 +70,7 @@ "type": "string" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" } } } @@ -219,6 +213,7 @@ "required": [ "amount", "contract", + "msg", "owner" ], "properties": { @@ -229,14 +224,7 @@ "type": "string" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" }, "owner": { "type": "string" diff --git a/contracts/cw20-base/src/allowances.rs b/contracts/cw20-base/src/allowances.rs index d7587649c..70632af28 100644 --- a/contracts/cw20-base/src/allowances.rs +++ b/contracts/cw20-base/src/allowances.rs @@ -208,7 +208,7 @@ pub fn execute_send_from( owner: String, contract: String, amount: Uint128, - msg: Option, + msg: Binary, ) -> Result { let rcpt_addr = deps.api.addr_validate(&contract)?; let owner_addr = deps.api.addr_validate(&owner)?; @@ -691,7 +691,7 @@ mod tests { owner: owner.clone(), amount: transfer, contract: contract.clone(), - msg: Some(send_msg.clone()), + msg: send_msg.clone(), }; let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); @@ -703,7 +703,7 @@ mod tests { let binary_msg = Cw20ReceiveMsg { sender: spender.clone(), amount: transfer, - msg: Some(send_msg.clone()), + msg: send_msg.clone(), } .into_binary() .unwrap(); @@ -736,7 +736,7 @@ mod tests { owner: owner.clone(), amount: Uint128(33443), contract: contract.clone(), - msg: Some(send_msg.clone()), + msg: send_msg.clone(), }; let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); @@ -758,7 +758,7 @@ mod tests { owner, amount: Uint128(33443), contract, - msg: Some(send_msg), + msg: send_msg, }; let info = mock_info(spender.as_ref(), &[]); let env = mock_env(); diff --git a/contracts/cw20-base/src/contract.rs b/contracts/cw20-base/src/contract.rs index a4b216121..c10f18f66 100644 --- a/contracts/cw20-base/src/contract.rs +++ b/contracts/cw20-base/src/contract.rs @@ -242,7 +242,7 @@ pub fn execute_send( info: MessageInfo, contract: String, amount: Uint128, - msg: Option, + msg: Binary, ) -> Result { if amount == Uint128::zero() { return Err(ContractError::InvalidZeroAmount {}); @@ -801,7 +801,7 @@ mod tests { let msg = ExecuteMsg::Send { contract: contract.clone(), amount: Uint128::zero(), - msg: Some(send_msg.clone()), + msg: send_msg.clone(), }; let err = execute(deps.as_mut(), env, info, msg).unwrap_err(); assert_eq!(err, ContractError::InvalidZeroAmount {}); @@ -812,7 +812,7 @@ mod tests { let msg = ExecuteMsg::Send { contract: contract.clone(), amount: too_much, - msg: Some(send_msg.clone()), + msg: send_msg.clone(), }; let err = execute(deps.as_mut(), env, info, msg).unwrap_err(); assert!(matches!(err, ContractError::Std(StdError::Overflow { .. }))); @@ -823,7 +823,7 @@ mod tests { let msg = ExecuteMsg::Send { contract: contract.clone(), amount: transfer, - msg: Some(send_msg.clone()), + msg: send_msg.clone(), }; let res = execute(deps.as_mut(), env, info, msg).unwrap(); assert_eq!(res.messages.len(), 1); @@ -833,7 +833,7 @@ mod tests { let binary_msg = Cw20ReceiveMsg { sender: addr1.clone(), amount: transfer, - msg: Some(send_msg), + msg: send_msg, } .into_binary() .unwrap(); diff --git a/contracts/cw20-base/src/msg.rs b/contracts/cw20-base/src/msg.rs index 4ad84296e..7491fc74f 100644 --- a/contracts/cw20-base/src/msg.rs +++ b/contracts/cw20-base/src/msg.rs @@ -69,7 +69,7 @@ pub enum ExecuteMsg { Send { contract: String, amount: Uint128, - msg: Option, + msg: Binary, }, /// Only with the "mintable" extension. If authorized, creates amount new tokens /// and adds to the recipient balance. @@ -103,7 +103,7 @@ pub enum ExecuteMsg { owner: String, contract: String, amount: Uint128, - msg: Option, + msg: Binary, }, /// Only with "approval" extension. Destroys tokens forever BurnFrom { owner: String, amount: Uint128 }, diff --git a/contracts/cw20-bonding/schema/execute_msg.json b/contracts/cw20-bonding/schema/execute_msg.json index 625af98a4..78ac0325f 100644 --- a/contracts/cw20-bonding/schema/execute_msg.json +++ b/contracts/cw20-bonding/schema/execute_msg.json @@ -72,7 +72,8 @@ "type": "object", "required": [ "amount", - "contract" + "contract", + "msg" ], "properties": { "amount": { @@ -82,14 +83,7 @@ "type": "string" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" } } } @@ -207,6 +201,7 @@ "required": [ "amount", "contract", + "msg", "owner" ], "properties": { @@ -217,14 +212,7 @@ "type": "string" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" }, "owner": { "type": "string" diff --git a/contracts/cw20-bonding/src/msg.rs b/contracts/cw20-bonding/src/msg.rs index 591150549..3bb201c4a 100644 --- a/contracts/cw20-bonding/src/msg.rs +++ b/contracts/cw20-bonding/src/msg.rs @@ -82,7 +82,7 @@ pub enum ExecuteMsg { Send { contract: String, amount: Uint128, - msg: Option, + msg: Binary, }, /// Implements CW20 "approval" extension. Allows spender to access an additional amount tokens /// from the owner's (env.sender) account. If expires is Some(), overwrites current allowance @@ -113,7 +113,7 @@ pub enum ExecuteMsg { owner: String, contract: String, amount: Uint128, - msg: Option, + msg: Binary, }, /// Implements CW20 "approval" extension. Destroys tokens forever BurnFrom { owner: String, amount: Uint128 }, diff --git a/contracts/cw20-escrow/schema/execute_msg.json b/contracts/cw20-escrow/schema/execute_msg.json index 4a13e3341..58ed58172 100644 --- a/contracts/cw20-escrow/schema/execute_msg.json +++ b/contracts/cw20-escrow/schema/execute_msg.json @@ -153,6 +153,7 @@ "type": "object", "required": [ "amount", + "msg", "sender" ], "properties": { @@ -160,14 +161,7 @@ "$ref": "#/definitions/Uint128" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" }, "sender": { "type": "string" diff --git a/contracts/cw20-escrow/src/contract.rs b/contracts/cw20-escrow/src/contract.rs index 83d934e07..002473226 100644 --- a/contracts/cw20-escrow/src/contract.rs +++ b/contracts/cw20-escrow/src/contract.rs @@ -53,10 +53,7 @@ pub fn execute_receive( info: MessageInfo, wrapper: Cw20ReceiveMsg, ) -> Result { - let msg: ReceiveMsg = match wrapper.msg { - Some(bin) => Ok(from_binary(&bin)?), - None => Err(ContractError::NoData {}), - }?; + let msg: ReceiveMsg = from_binary(&wrapper.msg)?; let balance = Balance::Cw20(Cw20CoinVerified { address: info.sender, amount: wrapper.amount, @@ -395,7 +392,7 @@ mod tests { let receive = Cw20ReceiveMsg { sender: String::from("source"), amount: Uint128(100), - msg: Some(to_binary(&ExecuteMsg::Create(create.clone())).unwrap()), + msg: to_binary(&ExecuteMsg::Create(create.clone())).unwrap(), }; let token_contract = String::from("my-cw20-token"); let info = mock_info(&token_contract, &[]); @@ -541,7 +538,7 @@ mod tests { let top_up = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: String::from("random"), amount: Uint128(7890), - msg: Some(to_binary(&base).unwrap()), + msg: to_binary(&base).unwrap(), }); let info = mock_info(&bar_token, &[]); let res = execute(deps.as_mut(), mock_env(), info, top_up).unwrap(); @@ -557,7 +554,7 @@ mod tests { let top_up = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: String::from("random"), amount: Uint128(7890), - msg: Some(to_binary(&base).unwrap()), + msg: to_binary(&base).unwrap(), }); let info = mock_info(&baz_token, &[]); let err = execute(deps.as_mut(), mock_env(), info, top_up).unwrap_err(); @@ -571,7 +568,7 @@ mod tests { let top_up = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: String::from("random"), amount: Uint128(888), - msg: Some(to_binary(&base).unwrap()), + msg: to_binary(&base).unwrap(), }); let info = mock_info(&foo_token, &[]); let res = execute(deps.as_mut(), mock_env(), info, top_up).unwrap(); diff --git a/contracts/cw20-escrow/src/error.rs b/contracts/cw20-escrow/src/error.rs index 32512ef8b..69e258ccf 100644 --- a/contracts/cw20-escrow/src/error.rs +++ b/contracts/cw20-escrow/src/error.rs @@ -6,9 +6,6 @@ pub enum ContractError { #[error("{0}")] Std(#[from] StdError), - #[error("No data in ReceiveMsg")] - NoData {}, - #[error("Unauthorized")] Unauthorized {}, diff --git a/contracts/cw20-ics20/schema/execute_msg.json b/contracts/cw20-ics20/schema/execute_msg.json index 8deeadf71..701fea83d 100644 --- a/contracts/cw20-ics20/schema/execute_msg.json +++ b/contracts/cw20-ics20/schema/execute_msg.json @@ -39,6 +39,7 @@ "type": "object", "required": [ "amount", + "msg", "sender" ], "properties": { @@ -46,14 +47,7 @@ "$ref": "#/definitions/Uint128" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" }, "sender": { "type": "string" diff --git a/contracts/cw20-ics20/src/contract.rs b/contracts/cw20-ics20/src/contract.rs index 91a18ba38..430787202 100644 --- a/contracts/cw20-ics20/src/contract.rs +++ b/contracts/cw20-ics20/src/contract.rs @@ -61,10 +61,7 @@ pub fn execute_receive( ) -> Result { nonpayable(&info)?; - let msg: TransferMsg = match wrapper.msg { - Some(bin) => from_binary(&bin)?, - None => return Err(ContractError::NoData {}), - }; + let msg: TransferMsg = from_binary(&wrapper.msg)?; let amount = Amount::Cw20(Cw20Coin { address: info.sender.to_string(), amount: wrapper.amount, @@ -317,7 +314,7 @@ mod test { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "my-account".into(), amount: Uint128(888777666), - msg: Some(to_binary(&transfer).unwrap()), + msg: to_binary(&transfer).unwrap(), }); // works with proper funds diff --git a/contracts/cw20-ics20/src/error.rs b/contracts/cw20-ics20/src/error.rs index a3f05a780..71e3f298d 100644 --- a/contracts/cw20-ics20/src/error.rs +++ b/contracts/cw20-ics20/src/error.rs @@ -17,9 +17,6 @@ pub enum ContractError { #[error("{0}")] Payment(#[from] PaymentError), - #[error("No data in ReceiveMsg")] - NoData {}, - #[error("Channel doesn't exist: {id}")] NoSuchChannel { id: String }, diff --git a/contracts/cw20-staking/schema/execute_msg.json b/contracts/cw20-staking/schema/execute_msg.json index 2a20bfb90..1dbeadd61 100644 --- a/contracts/cw20-staking/schema/execute_msg.json +++ b/contracts/cw20-staking/schema/execute_msg.json @@ -132,7 +132,8 @@ "type": "object", "required": [ "amount", - "contract" + "contract", + "msg" ], "properties": { "amount": { @@ -142,14 +143,7 @@ "type": "string" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" } } } @@ -267,6 +261,7 @@ "required": [ "amount", "contract", + "msg", "owner" ], "properties": { @@ -277,14 +272,7 @@ "type": "string" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" }, "owner": { "type": "string" diff --git a/contracts/cw20-staking/src/msg.rs b/contracts/cw20-staking/src/msg.rs index d49613c54..c3fe3c443 100644 --- a/contracts/cw20-staking/src/msg.rs +++ b/contracts/cw20-staking/src/msg.rs @@ -57,7 +57,7 @@ pub enum ExecuteMsg { Send { contract: String, amount: Uint128, - msg: Option, + msg: Binary, }, /// Implements CW20 "approval" extension. Allows spender to access an additional amount tokens /// from the owner's (env.sender) account. If expires is Some(), overwrites current allowance @@ -88,7 +88,7 @@ pub enum ExecuteMsg { owner: String, contract: String, amount: Uint128, - msg: Option, + msg: Binary, }, /// Implements CW20 "approval" extension. Destroys tokens forever BurnFrom { owner: String, amount: Uint128 }, diff --git a/packages/cw20/schema/cw20_receive_msg.json b/packages/cw20/schema/cw20_receive_msg.json index 34ddb09a8..7633b46c3 100644 --- a/packages/cw20/schema/cw20_receive_msg.json +++ b/packages/cw20/schema/cw20_receive_msg.json @@ -5,6 +5,7 @@ "type": "object", "required": [ "amount", + "msg", "sender" ], "properties": { @@ -12,14 +13,7 @@ "$ref": "#/definitions/Uint128" }, "msg": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Binary" }, "sender": { "type": "string" diff --git a/packages/cw20/src/receiver.rs b/packages/cw20/src/receiver.rs index fb6629c34..735baa923 100644 --- a/packages/cw20/src/receiver.rs +++ b/packages/cw20/src/receiver.rs @@ -9,7 +9,7 @@ use cosmwasm_std::{to_binary, Binary, CosmosMsg, StdResult, Uint128, WasmMsg}; pub struct Cw20ReceiveMsg { pub sender: String, pub amount: Uint128, - pub msg: Option, + pub msg: Binary, } impl Cw20ReceiveMsg {