Skip to content

Commit

Permalink
chore: refactor to accept kvStoreService instead of key
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed Mar 25, 2024
1 parent 6befb10 commit 4838021
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions x/bankplus/deprecator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bankplus
import (
"context"

"cosmossdk.io/core/store"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/runtime"
Expand Down Expand Up @@ -36,22 +37,22 @@ func inactiveAddrKey(addr sdk.AccAddress) []byte {
// func (app SimApp) deprecateBankPlusFromSimapp(ctx context.Context) {
// for _, key := range app.kvStoreKeys() {
// if key.Name() == banktypes.StoreKey {
// err := internal.DeprecateBankPlus(ctx, key)
// bankStoreService := runtime.NewKVStoreService(key)
// err := bankplus.DeprecateBankPlus(ctx, bankStoreService)
// if err != nil {
// panic(fmt.Errorf("failed to deprecate x/bankplus: %w", err))
// }
// }
// }
// }
func DeprecateBankPlus(ctx context.Context, bankKey *storetypes.KVStoreKey) error {
kss := runtime.NewKVStoreService(bankKey)
ks := kss.OpenKVStore(ctx)
adapter := runtime.KVStoreAdapter(ks)
func DeprecateBankPlus(ctx context.Context, bankStoreService store.KVStoreService) error {
kvStore := bankStoreService.OpenKVStore(ctx)
adapter := runtime.KVStoreAdapter(kvStore)
iter := storetypes.KVStorePrefixIterator(adapter, inactiveAddrsKeyPrefix)
defer iter.Close()

for ; iter.Valid(); iter.Next() {
err := ks.Delete(iter.Key())
err := kvStore.Delete(iter.Key())
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/bankplus/deprecator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *DeprecationTestSuite) TestDeprecateBankPlus() {
s.Require().True(isStoredInactiveAddr(s.ctx, s.storeService, oldAcc.GetAddress()))
s.Require().True(isStoredInactiveAddr(s.ctx, s.storeService, anotherOldAcc.GetAddress()))

err := DeprecateBankPlus(s.ctx, s.key)
err := DeprecateBankPlus(s.ctx, s.storeService)

s.Require().NoError(err)
s.Require().False(isStoredInactiveAddr(s.ctx, s.storeService, oldAcc.GetAddress()))
Expand Down

0 comments on commit 4838021

Please sign in to comment.