Skip to content

Commit

Permalink
simplify if else statement
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Dec 1, 2023
1 parent 8220d0d commit 934d898
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions x/virtualgroup/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"fmt"
math2 "math"

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"cosmossdk.io/math"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/bnb-chain/greenfield/internal/sequence"
sptypes "github.com/bnb-chain/greenfield/x/sp/types"
Expand Down Expand Up @@ -164,20 +163,15 @@ func (k Keeper) DeleteGVG(ctx sdk.Context, primarySp *sptypes.StorageProvider, g
return err
}

if len(gvgFamily.GlobalVirtualGroupIds) == 0 && k.paymentKeeper.IsEmptyNetFlow(ctx, sdk.MustAccAddressFromHex(gvgFamily.VirtualPaymentAddress)) {
// after Eddystone, the virtual group family can be empty.
if !ctx.IsUpgraded(upgradetypes.Eddystone) {
store.Delete(types.GetGVGFamilyKey(gvg.FamilyId))
if err := ctx.EventManager().EmitTypedEvents(&types.EventDeleteGlobalVirtualGroupFamily{
Id: gvgFamily.Id,
PrimarySpId: gvgFamily.PrimarySpId,
}); err != nil {
return err
}
} else {
if err := k.SetGVGFamilyAndEmitUpdateEvent(ctx, gvgFamily); err != nil {
return err
}
if len(gvgFamily.GlobalVirtualGroupIds) == 0 &&
k.paymentKeeper.IsEmptyNetFlow(ctx, sdk.MustAccAddressFromHex(gvgFamily.VirtualPaymentAddress)) &&
!ctx.IsUpgraded(upgradetypes.Eddystone) {
store.Delete(types.GetGVGFamilyKey(gvg.FamilyId))
if err := ctx.EventManager().EmitTypedEvents(&types.EventDeleteGlobalVirtualGroupFamily{
Id: gvgFamily.Id,
PrimarySpId: gvgFamily.PrimarySpId,
}); err != nil {
return err
}
} else {
if err := k.SetGVGFamilyAndEmitUpdateEvent(ctx, gvgFamily); err != nil {
Expand Down

0 comments on commit 934d898

Please sign in to comment.