From 2acebaf34896ed6094f8748b26eacdfd5aa32649 Mon Sep 17 00:00:00 2001 From: fx0x55 <80245546+fx0x55@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:08:10 +0800 Subject: [PATCH] refactor(x/bank): Simplify the return (#21602) (cherry picked from commit 9672879d211d3465e93da9f6103a0d48e334c17d) --- x/bank/keeper/keeper.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index ba7ee06976e8..9b1d79c1091b 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -150,7 +150,7 @@ func (k BaseKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccA if err != nil { return err } - if err := k.EventService.EventManager(ctx).EmitKV( + if err = k.EventService.EventManager(ctx).EmitKV( types.EventTypeCoinSpent, event.NewAttribute(types.AttributeKeySpender, delAddrStr), event.NewAttribute(sdk.AttributeKeyAmount, amt.String()), @@ -158,12 +158,7 @@ func (k BaseKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccA return err } - err = k.addCoins(ctx, moduleAccAddr, amt) - if err != nil { - return err - } - - return nil + return k.addCoins(ctx, moduleAccAddr, amt) } // UndelegateCoins performs undelegation by crediting amt coins to an account with @@ -181,8 +176,7 @@ func (k BaseKeeper) UndelegateCoins(ctx context.Context, moduleAccAddr, delegato return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, amt.String()) } - err := k.subUnlockedCoins(ctx, moduleAccAddr, amt) - if err != nil { + if err := k.subUnlockedCoins(ctx, moduleAccAddr, amt); err != nil { return err } @@ -190,12 +184,7 @@ func (k BaseKeeper) UndelegateCoins(ctx context.Context, moduleAccAddr, delegato return errorsmod.Wrap(err, "failed to track undelegation") } - err = k.addCoins(ctx, delegatorAddr, amt) - if err != nil { - return err - } - - return nil + return k.addCoins(ctx, delegatorAddr, amt) } // GetSupply retrieves the Supply from store