Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cw20ReceiveMsg msg field #286

Merged
merged 10 commits into from
Apr 26, 2021
10 changes: 2 additions & 8 deletions contracts/cw20-atomic-swap/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,15 @@
"type": "object",
"required": [
"amount",
"msg",
"sender"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"sender": {
"type": "string"
Expand Down
7 changes: 2 additions & 5 deletions contracts/cw20-atomic-swap/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ pub fn execute_receive(
info: MessageInfo,
wrapper: Cw20ReceiveMsg,
) -> Result<Response, ContractError> {
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,
Expand Down Expand Up @@ -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, &[]);
Expand Down
3 changes: 0 additions & 3 deletions contracts/cw20-atomic-swap/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
22 changes: 5 additions & 17 deletions contracts/cw20-base/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"type": "object",
"required": [
"amount",
"contract"
"contract",
"msg"
],
"properties": {
"amount": {
Expand All @@ -69,14 +70,7 @@
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
}
}
}
Expand Down Expand Up @@ -219,6 +213,7 @@
"required": [
"amount",
"contract",
"msg",
"owner"
],
"properties": {
Expand All @@ -229,14 +224,7 @@
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"owner": {
"type": "string"
Expand Down
10 changes: 5 additions & 5 deletions contracts/cw20-base/src/allowances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn execute_send_from(
owner: String,
contract: String,
amount: Uint128,
msg: Option<Binary>,
msg: Binary,
) -> Result<Response, ContractError> {
let rcpt_addr = deps.api.addr_validate(&contract)?;
let owner_addr = deps.api.addr_validate(&owner)?;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions contracts/cw20-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub fn execute_send(
info: MessageInfo,
contract: String,
amount: Uint128,
msg: Option<Binary>,
msg: Binary,
) -> Result<Response, ContractError> {
if amount == Uint128::zero() {
return Err(ContractError::InvalidZeroAmount {});
Expand Down Expand Up @@ -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 {});
Expand All @@ -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 { .. })));
Expand All @@ -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);
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw20-base/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub enum ExecuteMsg {
Send {
contract: String,
amount: Uint128,
msg: Option<Binary>,
msg: Binary,
},
/// Only with the "mintable" extension. If authorized, creates amount new tokens
/// and adds to the recipient balance.
Expand Down Expand Up @@ -103,7 +103,7 @@ pub enum ExecuteMsg {
owner: String,
contract: String,
amount: Uint128,
msg: Option<Binary>,
msg: Binary,
},
/// Only with "approval" extension. Destroys tokens forever
BurnFrom { owner: String, amount: Uint128 },
Expand Down
22 changes: 5 additions & 17 deletions contracts/cw20-bonding/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"type": "object",
"required": [
"amount",
"contract"
"contract",
"msg"
],
"properties": {
"amount": {
Expand All @@ -82,14 +83,7 @@
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
}
}
}
Expand Down Expand Up @@ -207,6 +201,7 @@
"required": [
"amount",
"contract",
"msg",
"owner"
],
"properties": {
Expand All @@ -217,14 +212,7 @@
"type": "string"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"owner": {
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw20-bonding/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum ExecuteMsg {
Send {
contract: String,
amount: Uint128,
msg: Option<Binary>,
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
Expand Down Expand Up @@ -113,7 +113,7 @@ pub enum ExecuteMsg {
owner: String,
contract: String,
amount: Uint128,
msg: Option<Binary>,
msg: Binary,
},
/// Implements CW20 "approval" extension. Destroys tokens forever
BurnFrom { owner: String, amount: Uint128 },
Expand Down
10 changes: 2 additions & 8 deletions contracts/cw20-escrow/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,15 @@
"type": "object",
"required": [
"amount",
"msg",
"sender"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"sender": {
"type": "string"
Expand Down
13 changes: 5 additions & 8 deletions contracts/cw20-escrow/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ pub fn execute_receive(
info: MessageInfo,
wrapper: Cw20ReceiveMsg,
) -> Result<Response, ContractError> {
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,
Expand Down Expand Up @@ -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, &[]);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions contracts/cw20-escrow/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("No data in ReceiveMsg")]
NoData {},

#[error("Unauthorized")]
Unauthorized {},

Expand Down
10 changes: 2 additions & 8 deletions contracts/cw20-ics20/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,15 @@
"type": "object",
"required": [
"amount",
"msg",
"sender"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"msg": {
"anyOf": [
{
"$ref": "#/definitions/Binary"
},
{
"type": "null"
}
]
"$ref": "#/definitions/Binary"
},
"sender": {
"type": "string"
Expand Down
Loading