Skip to content

Commit a458ab6

Browse files
committed
fix(#242): Fixed address prefixes in chain
1 parent 2bf71f5 commit a458ab6

5 files changed

Lines changed: 11 additions & 2 deletions

File tree

scripts/migrate_with_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
new_dict["app_state"]["cardchain"]["users"].append(
164164
old_dict["app_state"]["cardchain"]["users"][idx]
165165
)
166+
166167
for i in old_dict["app_state"]["auth"]["accounts"]:
167168
if i.get("address") == addr:
168169
new_dict["app_state"]["auth"]["accounts"].append(i)

types/generic_type_keeper/address_gtk.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package generic_type_keeper
22

33
import (
4+
"bytes"
5+
46
"cosmossdk.io/core/store"
7+
"github.com/DecentralCardGame/cardchain/x/cardchain/types"
58
"github.com/cosmos/cosmos-sdk/codec"
69
sdk "github.com/cosmos/cosmos-sdk/types"
710
"github.com/cosmos/gogoproto/proto"
@@ -11,6 +14,10 @@ type GenericAddressTypeKeeper[T proto.Message] struct {
1114
GenericTypeKeeper[T, sdk.AccAddress]
1215
}
1316

17+
func (gtk GenericAddressTypeKeeper[T]) NormalizeAddress(address []byte) sdk.AccAddress {
18+
return bytes.TrimPrefix(address, append(types.KeyPrefix(gtk.valueKey()), []byte("/")...))
19+
}
20+
1421
func NewAddressGTK[T proto.Message](key string, storeService store.KVStoreService, cdc codec.BinaryCodec, getEmpty func() T) GenericAddressTypeKeeper[T] {
1522
gtk := GenericAddressTypeKeeper[T]{
1623
GenericTypeKeeper[T, sdk.AccAddress]{

types/generic_type_keeper/generic_type_keeper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (gtk GenericTypeKeeper[T, K]) Set(ctx sdk.Context, id K, new T) {
6666
// GetIterator Returns an iterator for all objects
6767
func (gtk GenericTypeKeeper[T, K]) GetIterator(ctx sdk.Context) db.Iterator {
6868
store := gtk.getValueStore(ctx)
69-
return storetypes.KVStorePrefixIterator(store, []byte{})
69+
return storetypes.KVStorePrefixIterator(store, types.KeyPrefix(gtk.valueKey()))
7070
}
7171

7272
// GetAll Gets all objs from store -- use GetItemIterator instead

x/cardchain/keeper/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (k Keeper) GetAllUsers(ctx sdk.Context) (allUsers []*types.User, allAddress
6767
k.cdc.MustUnmarshal(iterator.Value(), &gottenUser)
6868

6969
allUsers = append(allUsers, &gottenUser)
70-
allAddresses = append(allAddresses, iterator.Key())
70+
allAddresses = append(allAddresses, k.Users.NormalizeAddress(iterator.Key()))
7171
}
7272
return
7373
}

x/cardchain/module/genesis.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
123123
addresses = append(addresses, addr.String())
124124
}
125125
genesis.Users = users
126+
genesis.Addresses = addresses
126127
// this line is used by starport scaffolding # genesis/module/export
127128

128129
return genesis

0 commit comments

Comments
 (0)