Skip to content

Commit

Permalink
Merge pull request #707 from CosmWasm/clarify-send-msg-simon
Browse files Browse the repository at this point in the history
Document omitted "sender" fields for all message types
  • Loading branch information
mergify[bot] authored Jan 12, 2021
2 parents 02c9b7b + 4fd5c9e commit afd642f
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 59 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 0.14.0 (unreleased)

**cosmwasm-std**

- Remove `from_address` from `BankMsg::Send`, as it always sends from the
contract address, and this is consistent with other `CosmosMsg` variants.

## 0.13.1 (2020-01-12)

**cosmwasm-std**
Expand Down
18 changes: 18 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ major releases of `cosmwasm`. Note that you can also view the
# ...
```

- Remove `from_address` from `BankMsg::Send`, which is now automatically filled
with the contract address:

```rust
// before
ctx.add_message(BankMsg::Send {
from_address: env.contract.address,
to_address: to_addr,
amount: balance,
});

// after
ctx.add_message(BankMsg::Send {
to_address: to_addr,
amount: balance,
});
```

- Use the new entry point system. From `lib.rs` remove

```rust
Expand Down
4 changes: 1 addition & 3 deletions contracts/burner/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub fn migrate(
// get balance and send all to recipient
let balance = deps.querier.query_all_balances(&env.contract.address)?;
let send = BankMsg::Send {
from_address: env.contract.address,
to_address: msg.payout.clone(),
amount: balance,
};
Expand All @@ -74,7 +73,7 @@ pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult<QueryResponse>
#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info, MOCK_CONTRACT_ADDR};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coins, HumanAddr, StdError, Storage};

#[test]
Expand Down Expand Up @@ -117,7 +116,6 @@ mod tests {
assert_eq!(
msg,
&BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: payout,
amount: coins(123456, "gold"),
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/burner/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use cosmwasm_std::{
coins, BankMsg, ContractResult, HumanAddr, InitResponse, MigrateResponse, Order,
};
use cosmwasm_vm::testing::{init, migrate, mock_env, mock_info, mock_instance, MOCK_CONTRACT_ADDR};
use cosmwasm_vm::testing::{init, migrate, mock_env, mock_info, mock_instance};

use burner::msg::{InitMsg, MigrateMsg};
use cosmwasm_vm::Storage;
Expand Down Expand Up @@ -74,7 +74,6 @@ fn migrate_cleans_up_data() {
assert_eq!(
msg,
&BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: payout,
amount: coins(123456, "gold"),
}
Expand Down
2 changes: 0 additions & 2 deletions contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ fn do_release(deps: DepsMut, env: Env, info: MessageInfo) -> Result<HandleRespon
ctx.add_attribute("action", "release");
ctx.add_attribute("destination", &to_addr);
ctx.add_message(BankMsg::Send {
from_address: env.contract.address,
to_address: to_addr,
amount: balance,
});
Expand Down Expand Up @@ -491,7 +490,6 @@ mod tests {
assert_eq!(
msg,
&BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: beneficiary,
amount: coins(1000, "earth"),
}
Expand Down
1 change: 0 additions & 1 deletion contracts/hackatom/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ fn handle_release_works() {
assert_eq!(
msg,
&BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: beneficiary,
amount: coins(1000, "earth"),
}
Expand Down
16 changes: 10 additions & 6 deletions contracts/reflect/schema/handle_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
],
"definitions": {
"BankMsg": {
"description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto",
"anyOf": [
{
"description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"send"
Expand All @@ -57,7 +59,6 @@
"type": "object",
"required": [
"amount",
"from_address",
"to_address"
],
"properties": {
Expand All @@ -67,9 +68,6 @@
"$ref": "#/definitions/Coin"
}
},
"from_address": {
"$ref": "#/definitions/HumanAddr"
},
"to_address": {
"$ref": "#/definitions/HumanAddr"
}
Expand Down Expand Up @@ -177,8 +175,10 @@
"type": "string"
},
"StakingMsg": {
"description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto",
"anyOf": [
{
"description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"delegate"
Expand All @@ -202,6 +202,7 @@
}
},
{
"description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"undelegate"
Expand All @@ -225,6 +226,7 @@
}
},
{
"description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37) followed by a [MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"withdraw"
Expand Down Expand Up @@ -255,6 +257,7 @@
}
},
{
"description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"redelegate"
Expand Down Expand Up @@ -287,9 +290,10 @@
"type": "string"
},
"WasmMsg": {
"description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto",
"anyOf": [
{
"description": "this dispatches a call to another contract at a known address (with known ABI)",
"description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"execute"
Expand Down Expand Up @@ -325,7 +329,7 @@
}
},
{
"description": "this instantiates a new contracts from previously uploaded wasm code",
"description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"instantiate"
Expand Down
16 changes: 10 additions & 6 deletions contracts/reflect/schema/handle_response_for__custom_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
}
},
"BankMsg": {
"description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto",
"anyOf": [
{
"description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"send"
Expand All @@ -60,7 +62,6 @@
"type": "object",
"required": [
"amount",
"from_address",
"to_address"
],
"properties": {
Expand All @@ -70,9 +71,6 @@
"$ref": "#/definitions/Coin"
}
},
"from_address": {
"$ref": "#/definitions/HumanAddr"
},
"to_address": {
"$ref": "#/definitions/HumanAddr"
}
Expand Down Expand Up @@ -180,8 +178,10 @@
"type": "string"
},
"StakingMsg": {
"description": "The message types of the staking module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto",
"anyOf": [
{
"description": "This is translated to a [MsgDelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L81-L90). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"delegate"
Expand All @@ -205,6 +205,7 @@
}
},
{
"description": "This is translated to a [MsgUndelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L112-L121). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"undelegate"
Expand All @@ -228,6 +229,7 @@
}
},
{
"description": "This is translated to a [MsgSetWithdrawAddress](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/distribution/v1beta1/tx.proto#L29-L37) followed by a [MsgWithdrawDelegatorReward](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/distribution/v1beta1/tx.proto#L42-L50). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"withdraw"
Expand Down Expand Up @@ -258,6 +260,7 @@
}
},
{
"description": "This is translated to a [MsgBeginRedelegate](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/staking/v1beta1/tx.proto#L95-L105). `delegator_address` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"redelegate"
Expand Down Expand Up @@ -290,9 +293,10 @@
"type": "string"
},
"WasmMsg": {
"description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto",
"anyOf": [
{
"description": "this dispatches a call to another contract at a known address (with known ABI)",
"description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"execute"
Expand Down Expand Up @@ -328,7 +332,7 @@
}
},
{
"description": "this instantiates a new contracts from previously uploaded wasm code",
"description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.",
"type": "object",
"required": [
"instantiate"
Expand Down
3 changes: 0 additions & 3 deletions contracts/reflect/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ mod tests {
let _res = init(deps.as_mut(), mock_env(), info, msg).unwrap();

let payload = vec![BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: HumanAddr::from("friend"),
amount: coins(1, "token"),
}
Expand All @@ -194,7 +193,6 @@ mod tests {

// signer is not owner
let payload = vec![BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: HumanAddr::from("friend"),
amount: coins(1, "token"),
}
Expand Down Expand Up @@ -239,7 +237,6 @@ mod tests {

let payload = vec![
BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: HumanAddr::from("friend"),
amount: coins(1, "token"),
}
Expand Down
2 changes: 0 additions & 2 deletions contracts/reflect/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn reflect() {

let payload = vec![
BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: HumanAddr::from("friend"),
amount: coins(1, "token"),
}
Expand Down Expand Up @@ -117,7 +116,6 @@ fn reflect_requires_owner() {

// signer is not owner
let payload = vec![BankMsg::Send {
from_address: HumanAddr::from(MOCK_CONTRACT_ADDR),
to_address: HumanAddr::from("friend"),
amount: coins(1, "token"),
}
Expand Down
1 change: 0 additions & 1 deletion contracts/staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ pub fn claim(deps: DepsMut, env: Env, info: MessageInfo) -> StdResult<HandleResp
balance.amount = to_send;
let res = HandleResponse {
messages: vec![BankMsg::Send {
from_address: env.contract.address,
to_address: info.sender.clone(),
amount: vec![balance],
}
Expand Down
Loading

0 comments on commit afd642f

Please sign in to comment.