Skip to content

Commit

Permalink
fix: revert proto changes from #12610 (#12670)
Browse files Browse the repository at this point in the history
## Description

ref:#12610 (comment)



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
likhita-809 authored Jul 21, 2022
1 parent 5e1ff06 commit 5019459
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 269 deletions.
257 changes: 159 additions & 98 deletions api/cosmos/bank/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions proto/cosmos/bank/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ message MsgSend {
// MsgSendResponse defines the Msg/Send response type.
message MsgSendResponse {}

// MsgMultiSend represents a single input, multi-out send message.
// MsgMultiSend represents an arbitrary multi-in, multi-out send message.
message MsgMultiSend {
option (cosmos.msg.v1.signer) = "input";
option (cosmos.msg.v1.signer) = "inputs";

option (gogoproto.equal) = false;

Input input = 1 [(gogoproto.nullable) = false];
// Inputs, despite being `repeated`, only allows one sender input. This is
// checked in MsgMultiSend's ValidateBasic.
repeated Input inputs = 1 [(gogoproto.nullable) = false];
repeated Output outputs = 2 [(gogoproto.nullable) = false];
}

Expand Down
21 changes: 17 additions & 4 deletions x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,32 @@ var (
sendMsg1 = types.NewMsgSend(addr1, addr2, coins)

multiSendMsg1 = &types.MsgMultiSend{
Input: types.NewInput(addr1, coins),
Inputs: []types.Input{types.NewInput(addr1, coins)},
Outputs: []types.Output{types.NewOutput(addr2, coins)},
}
multiSendMsg2 = &types.MsgMultiSend{
Input: types.NewInput(addr1, coins),
Inputs: []types.Input{types.NewInput(addr1, coins)},
Outputs: []types.Output{
types.NewOutput(addr2, halfCoins),
types.NewOutput(addr3, halfCoins),
},
}
multiSendMsg3 = &types.MsgMultiSend{
Input: types.NewInput(addr2, coins),
Inputs: []types.Input{types.NewInput(addr2, coins)},
Outputs: []types.Output{
types.NewOutput(addr1, coins),
},
}
multiSendMsg4 = &types.MsgMultiSend{
Input: types.NewInput(addr1, coins),
Inputs: []types.Input{types.NewInput(addr1, coins)},
Outputs: []types.Output{
types.NewOutput(moduleAccAddr, coins),
},
}
invalidMultiSendMsg = &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1, coins), types.NewInput(addr2, coins)},
Outputs: []types.Output{},
}
)

func TestSendNotEnoughBalance(t *testing.T) {
Expand Down Expand Up @@ -154,6 +158,15 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
expPass: false,
privKeys: []cryptotypes.PrivKey{priv1},
},
{
desc: "multiple inputs not allowed",
msgs: []sdk.Msg{invalidMultiSendMsg},
accNums: []uint64{0},
accSeqs: []uint64{0},
expSimPass: false,
expPass: false,
privKeys: []cryptotypes.PrivKey{priv1},
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion x/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address.
amount = coins.MulInt(totalAddrs)
}

msg := types.NewMsgMultiSend(types.NewInput(clientCtx.FromAddress, amount), output)
msg := types.NewMsgMultiSend([]types.Input{types.NewInput(clientCtx.FromAddress, amount)}, output)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
Expand Down
27 changes: 14 additions & 13 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,14 @@ func (suite *IntegrationTestSuite) TestInputOutputNewAccount() {
suite.Require().Nil(app.AccountKeeper.GetAccount(ctx, addr2))
suite.Require().Empty(app.BankKeeper.GetAllBalances(ctx, addr2))

input := types.Input{
Address: addr1.String(),
Coins: sdk.NewCoins(newFooCoin(30), newBarCoin(10)),
inputs := []types.Input{
{Address: addr1.String(), Coins: sdk.NewCoins(newFooCoin(30), newBarCoin(10))},
}
outputs := []types.Output{
{Address: addr2.String(), Coins: sdk.NewCoins(newFooCoin(30), newBarCoin(10))},
}

suite.Require().NoError(app.BankKeeper.InputOutputCoins(ctx, input, outputs))
suite.Require().NoError(app.BankKeeper.InputOutputCoins(ctx, inputs, outputs))

expected := sdk.NewCoins(newFooCoin(30), newBarCoin(10))
acc2Balances := app.BankKeeper.GetAllBalances(ctx, addr2)
Expand All @@ -393,9 +392,8 @@ func (suite *IntegrationTestSuite) TestInputOutputCoins() {
acc3 := app.AccountKeeper.NewAccountWithAddress(ctx, addr3)
app.AccountKeeper.SetAccount(ctx, acc3)

input := types.Input{
Address: addr1.String(),
Coins: sdk.NewCoins(newFooCoin(60), newBarCoin(20)),
input := []types.Input{
{Address: addr1.String(), Coins: sdk.NewCoins(newFooCoin(60), newBarCoin(20))},
}
outputs := []types.Output{
{Address: addr2.String(), Coins: sdk.NewCoins(newFooCoin(30), newBarCoin(10))},
Expand All @@ -407,9 +405,11 @@ func (suite *IntegrationTestSuite) TestInputOutputCoins() {

suite.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, addr1, balances))

insufficientInput := types.Input{
Address: addr1.String(),
Coins: sdk.NewCoins(newFooCoin(300), newBarCoin(100)),
insufficientInput := []types.Input{
{
Address: addr1.String(),
Coins: sdk.NewCoins(newFooCoin(300), newBarCoin(100)),
},
}
insufficientOutputs := []types.Output{
{Address: addr2.String(), Coins: sdk.NewCoins(newFooCoin(300), newBarCoin(100))},
Expand Down Expand Up @@ -613,9 +613,10 @@ func (suite *IntegrationTestSuite) TestMsgMultiSendEvents() {
coins := sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50), sdk.NewInt64Coin(barDenom, 100))
newCoins := sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))
newCoins2 := sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))
input := types.Input{
Address: addr.String(),
Coins: coins,
input := []types.Input{
{Address: addr.String(),
Coins: coins,
},
}
outputs := []types.Output{
{Address: addr3.String(), Coins: newCoins},
Expand Down
8 changes: 5 additions & 3 deletions x/bank/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t
ctx := sdk.UnwrapSDKContext(goCtx)

// NOTE: totalIn == totalOut should already have been checked
if err := k.IsSendEnabledCoins(ctx, msg.Input.Coins...); err != nil {
return nil, err
for _, in := range msg.Inputs {
if err := k.IsSendEnabledCoins(ctx, in.Coins...); err != nil {
return nil, err
}
}

for _, out := range msg.Outputs {
Expand All @@ -88,7 +90,7 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t
}
}

err := k.InputOutputCoins(ctx, msg.Input, msg.Outputs)
err := k.InputOutputCoins(ctx, msg.Inputs, msg.Outputs)
if err != nil {
return nil, err
}
Expand Down
35 changes: 18 additions & 17 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
type SendKeeper interface {
ViewKeeper

InputOutputCoins(ctx sdk.Context, input types.Input, outputs []types.Output) error
InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) error
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error

GetParams(ctx sdk.Context) types.Params
Expand Down Expand Up @@ -120,30 +120,31 @@ func (k BaseSendKeeper) SetParams(ctx sdk.Context, params types.Params) error {
// InputOutputCoins performs multi-send functionality. It accepts a series of
// inputs that correspond to a series of outputs. It returns an error if the
// inputs and outputs don't line up or if any single transfer of tokens fails.
func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, input types.Input, outputs []types.Output) error {
func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) error {
// Safety check ensuring that when sending coins the keeper must maintain the
// Check supply invariant and validity of Coins.
if err := types.ValidateInputsOutputs(input, outputs); err != nil {
if err := types.ValidateInputsOutputs(inputs, outputs); err != nil {
return err
}

inAddress, err := sdk.AccAddressFromBech32(input.Address)
if err != nil {
return err
}
for _, in := range inputs {
inAddress, err := sdk.AccAddressFromBech32(in.Address)
if err != nil {
return err
}

err = k.subUnlockedCoins(ctx, inAddress, input.Coins)
if err != nil {
return err
err = k.subUnlockedCoins(ctx, inAddress, in.Coins)
if err != nil {
return err
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, in.Address),
),
)
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, input.Address),
),
)

for _, out := range outputs {
outAddress, err := sdk.AccAddressFromBech32(out.Address)
if err != nil {
Expand Down
Loading

0 comments on commit 5019459

Please sign in to comment.