Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Revert "feat: add a BeforeSend hook to the bank module (#278)" (#326)
Browse files Browse the repository at this point in the history
This reverts commit 6fcd25f.
  • Loading branch information
p0mvn authored Sep 13, 2022
1 parent 870132d commit be61cb5
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 203 deletions.
17 changes: 0 additions & 17 deletions x/bank/keeper/hooks.go

This file was deleted.

101 changes: 0 additions & 101 deletions x/bank/keeper/hooks_test.go

This file was deleted.

11 changes: 0 additions & 11 deletions x/bank/keeper/internal_test.go

This file was deleted.

16 changes: 2 additions & 14 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}

// call the BeforeSend hooks
err := k.BeforeSend(ctx, delegatorAddr, moduleAccAddr, amt)
if err != nil {
return err
}

balances := sdk.NewCoins()

for _, coin := range amt {
Expand All @@ -214,7 +208,7 @@ func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr
types.NewCoinSpentEvent(delegatorAddr, amt),
)

err = k.addCoins(ctx, moduleAccAddr, amt)
err := k.addCoins(ctx, moduleAccAddr, amt)
if err != nil {
return err
}
Expand All @@ -237,13 +231,7 @@ func (k BaseKeeper) UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAdd
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}

// call the BeforeSend hooks
err := k.BeforeSend(ctx, moduleAccAddr, delegatorAddr, amt)
if err != nil {
return err
}

err = k.subUnlockedCoins(ctx, moduleAccAddr, amt)
err := k.subUnlockedCoins(ctx, moduleAccAddr, amt)
if err != nil {
return err
}
Expand Down
27 changes: 2 additions & 25 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type BaseSendKeeper struct {
ak types.AccountKeeper
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
hooks types.BankHooks

// list of addresses that are restricted from receiving transactions
blockedAddrs map[string]bool
Expand All @@ -59,17 +58,6 @@ func NewBaseSendKeeper(
}
}

// Set the bank hooks
func (k *BaseSendKeeper) SetHooks(bh types.BankHooks) *BaseSendKeeper {
if k.hooks != nil {
panic("cannot set bank hooks twice")
}

k.hooks = bh

return k
}

// GetParams returns the total set of bank parameters.
func (k BaseSendKeeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, &params)
Expand All @@ -84,13 +72,7 @@ func (k BaseSendKeeper) SetParams(ctx sdk.Context, params types.Params) {
// SendCoins transfers amt coins from a sending account to a receiving account.
// An error is returned upon failure.
func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
// call the BeforeSend hooks
err := k.BeforeSend(ctx, fromAddr, toAddr, amt)
if err != nil {
return err
}

err = k.subUnlockedCoins(ctx, fromAddr, amt)
err := k.subUnlockedCoins(ctx, fromAddr, amt)
if err != nil {
return err
}
Expand Down Expand Up @@ -134,12 +116,7 @@ func (k BaseSendKeeper) SendManyCoins(ctx sdk.Context, fromAddr sdk.AccAddress,
}

totalAmt := sdk.Coins{}
for i, amt := range amts {
// make sure to trigger the BeforeSend hooks for all the sends that are about to occur
err := k.BeforeSend(ctx, fromAddr, toAddrs[i], amts[i])
if err != nil {
return err
}
for _, amt := range amts {
totalAmt = sdk.Coins.Add(totalAmt, amt...)
}

Expand Down
11 changes: 0 additions & 11 deletions x/bank/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,3 @@ type AccountKeeper interface {
GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI
SetModuleAccount(ctx sdk.Context, macc types.ModuleAccountI)
}

// Event Hooks
// These can be utilized to communicate between a bank keeper and another
// keeper which must take particular actions when sends happen.
// The second keeper must implement this interface, which then the
// bank keeper can call.

// BankHooks event hooks for bank sends
type BankHooks interface {
BeforeSend(ctx sdk.Context, from sdk.AccAddress, to sdk.AccAddress, amount sdk.Coins) error // Must be before any send is executed
}
24 changes: 0 additions & 24 deletions x/bank/types/hooks.go

This file was deleted.

0 comments on commit be61cb5

Please sign in to comment.