Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Oct 13, 2023
1 parent cffd5bb commit fab5d3e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
2 changes: 1 addition & 1 deletion x/bank/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ type (
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
Get(ctx sdk.Context, key []byte, ptr interface{})
GetRaw(ctx sdk.Context, key []byte) []byte
}
)
7 changes: 6 additions & 1 deletion x/bank/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2"
Expand All @@ -13,6 +14,7 @@ import (
type Migrator struct {
keeper BaseKeeper
legacySubspace exported.Subspace
legacyAmino *codec.LegacyAmino
}

// NewMigrator returns a new Migrator.
Expand All @@ -33,7 +35,10 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error {
// Migrate3to4 migrates x/bank storage from version 3 to 4.
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
var sendEnabled []*types.SendEnabled
m.legacySubspace.Get(ctx, types.KeySendEnabled, &sendEnabled)
bz := m.legacySubspace.GetRaw(ctx, types.KeySendEnabled)
if err := m.legacyAmino.UnmarshalJSON(bz, &sendEnabled); err != nil {
return err
}
m.keeper.SetAllSendEnabled(ctx, sendEnabled)
return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
}
34 changes: 0 additions & 34 deletions x/bank/types/params_legacy.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package types

import (
fmt "fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

Expand All @@ -23,37 +20,6 @@ func ParamKeyTable() paramtypes.KeyTable {
// Deprecated: ParamSetPairs implements params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeySendEnabled, &p.SendEnabled, validateSendEnabledParams),
paramtypes.NewParamSetPair(KeyDefaultSendEnabled, &p.DefaultSendEnabled, validateIsBool),
}
}

// SendEnabledParams is a collection of parameters indicating if a coin denom is enabled for sending
type SendEnabledParams []*SendEnabled

func validateSendEnabledParams(i interface{}) error {
params, ok := i.([]*SendEnabled)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
// ensure each denom is only registered one time.
registered := make(map[string]bool)
for _, p := range params {
if _, exists := registered[p.Denom]; exists {
return fmt.Errorf("duplicate send enabled parameter found: '%s'", p.Denom)
}
if err := validateSendEnabled(*p); err != nil {
return err
}
registered[p.Denom] = true
}
return nil
}

func validateSendEnabled(i interface{}) error {
param, ok := i.(SendEnabled)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return sdk.ValidateDenom(param.Denom)
}

0 comments on commit fab5d3e

Please sign in to comment.