Skip to content

Commit

Permalink
add check send enabled (backport #2679) (#2687)
Browse files Browse the repository at this point in the history
* add check send enabled (#2679)

* add check send enabled

* changelog

(cherry picked from commit b1f494c)

# Conflicts:
#	CHANGELOG.md
#	modules/apps/transfer/keeper/msg_server.go
#	modules/apps/transfer/keeper/msg_server_test.go

* fix conflict

* fix build

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>
  • Loading branch information
3 people authored Nov 5, 2022
1 parent d0319b6 commit 0e75114
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (apps/transfer) [\#2672](https://github.com/cosmos/ibc-go/pull/2672) Check `x/bank` send enabled.

## [v2.4.1](https://github.com/cosmos/ibc-go/releases/tag/v2.4.1) - 2022-09-15

### Dependencies
Expand Down
23 changes: 23 additions & 0 deletions modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
)
Expand All @@ -19,6 +20,17 @@ func (suite *KeeperTestSuite) TestMsgTransfer() {
func() {},
true,
},
{
"bank send enabled for denom",
func() {
suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(),
banktypes.Params{
SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: true}},
},
)
},
true,
},
{
"invalid sender",
func() {
Expand All @@ -33,6 +45,17 @@ func (suite *KeeperTestSuite) TestMsgTransfer() {
},
false,
},
{
"bank send disabled for denom",
func() {
suite.chainA.GetSimApp().BankKeeper.SetParams(suite.chainA.GetContext(),
banktypes.Params{
SendEnabled: []*banktypes.SendEnabled{{Denom: sdk.DefaultBondDenom, Enabled: false}},
},
)
},
false,
},
{
"channel does not exist",
func() {
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (k Keeper) sendTransfer(
return 0, types.ErrSendDisabled
}

if !k.bankKeeper.IsSendEnabledCoin(ctx, token) {
return 0, sdkerrors.Wrapf(types.ErrSendDisabled, "%s transfers are currently disabled", token.Denom)
}

if k.bankKeeper.BlockedAddr(sender) {
return 0, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender)
}
Expand Down
1 change: 1 addition & 0 deletions modules/apps/transfer/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type BankKeeper interface {
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BlockedAddr(addr sdk.AccAddress) bool
IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool
}

// ChannelKeeper defines the expected IBC channel keeper
Expand Down

0 comments on commit 0e75114

Please sign in to comment.