From ec08ea75d0c26ebef0be70ca2164e57e62439fc4 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 10:23:54 +0000 Subject: [PATCH] refactor(x/bank): Simplify the return (backport #21602) (#21604) Co-authored-by: fx0x55 <80245546+fx0x55@users.noreply.github.com> --- 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