Skip to content

Commit

Permalink
refactoring antehandler
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Sep 15, 2022
1 parent 27fb2e5 commit e905d25
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@ func NewIsPausedDecorator(tk tokenfactory.Keeper) IsPausedDecorator {
func (ad IsPausedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
msgs := tx.GetMsgs()
for _, m := range msgs {
paused, _ := ad.tokenfactory.GetPaused(ctx)
switch m := m.(type) {
case *banktypes.MsgSend:
case *banktypes.MsgSend, *transfertypes.MsgTransfer:
paused, _ := ad.tokenfactory.GetPaused(ctx)
if paused.Paused {
return ctx, sdkerrors.Wrapf(tokenfactorytypes.ErrPaused, "can not perform token transfers")
}
_, found := ad.tokenfactory.GetBlacklisted(ctx, m.FromAddress)
if found {
return ctx, sdkerrors.Wrapf(tokenfactorytypes.ErrUnauthorized, "an account is blacklisted and can not transfer tokens")
var address string
switch m := m.(type) {
case *banktypes.MsgSend:
address = m.FromAddress
case *transfertypes.MsgTransfer:
address = m.Sender
}
case *transfertypes.MsgTransfer:
if paused.Paused {
return ctx, sdkerrors.Wrapf(tokenfactorytypes.ErrPaused, "can not perform IBC token transfers")
}
_, found := ad.tokenfactory.GetBlacklisted(ctx, m.Sender)
_, found := ad.tokenfactory.GetBlacklisted(ctx, address)
if found {
return ctx, sdkerrors.Wrapf(tokenfactorytypes.ErrUnauthorized, "an account is blacklisted and can not transfer tokens over IBC")
return ctx, sdkerrors.Wrapf(tokenfactorytypes.ErrUnauthorized, "an account is blacklisted and can not transfer tokens")
}
default:
continue
Expand Down

0 comments on commit e905d25

Please sign in to comment.