From 5b4283793bcf39d61420fe25f283905a206f8a1e Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 29 Mar 2024 09:34:44 +0800 Subject: [PATCH] reorder --- x/bank/keeper/keeper.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 8bed08373c67..1a31ffc0f220 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -424,12 +424,16 @@ func (k BaseKeeper) BurnCoins(ctx context.Context, moduleName string, amounts sd // it's for evm integration, call at your own risk. // it emits mint event. func (k BaseKeeper) AddBalance(ctx context.Context, addr sdk.AccAddress, coin sdk.Coin) error { - sdkCtx := sdk.UnwrapSDKContext(ctx) + if err := k.addCoin(ctx, addr, coin); err != nil { + return err + } + // emit mint event + sdkCtx := sdk.UnwrapSDKContext(ctx) sdkCtx.EventManager().EmitEvent( types.NewCoinMintEvent(addr, sdk.NewCoins(coin)), ) - return k.addCoin(ctx, addr, coin) + return nil } // SubBalance is low level api to update balance directly, mainly used by evm integration, @@ -437,13 +441,17 @@ func (k BaseKeeper) AddBalance(ctx context.Context, addr sdk.AccAddress, coin sd // it's for evm integration, call at your own risk. // it emits burn event. func (k BaseKeeper) SubBalance(ctx context.Context, addr sdk.AccAddress, coin sdk.Coin) error { + lockedCoins := k.LockedCoins(ctx, addr) + if err := k.subCoin(ctx, addr, coin, lockedCoins); err != nil { + return err + } + sdkCtx := sdk.UnwrapSDKContext(ctx) // emit burn event sdkCtx.EventManager().EmitEvent( types.NewCoinBurnEvent(addr, sdk.NewCoins(coin)), ) - lockedCoins := k.LockedCoins(ctx, addr) - return k.subCoin(ctx, addr, coin, lockedCoins) + return nil } // setSupply sets the supply for the given coin