-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06a6e5b
commit e87fed4
Showing
4 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v2 "github.com/cosmos/cosmos-sdk/x/nft/migrations/v2" | ||
) | ||
|
||
type Migrator struct { | ||
keeper Keeper | ||
} | ||
|
||
func NewMigrator(keeper Keeper) Migrator { | ||
return Migrator{ | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
if err := v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package v2 | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/nft/types" | ||
) | ||
|
||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { | ||
ctx.Logger().Info(fmt.Sprintf("Performing v12.1.8-rc2 %s module migrations", types.ModuleName)) | ||
|
||
store := prefix.NewStore(ctx.KVStore(storeKey), types.KeyPrefix(types.NFTKeyPrefix)) | ||
iterator := sdk.KVStorePrefixIterator(store, []byte{}) | ||
|
||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
var nft types.NFT | ||
cdc.MustUnmarshal(iterator.Value(), &nft) | ||
|
||
nftOwnerStore := prefix.NewStore(ctx.KVStore(storeKey), types.KeyPrefix(types.NFTByOwnerKeyPrefix)) | ||
ownerBranchStore := prefix.NewStore(nftOwnerStore, types.KeyPrefix(nft.Owner)) | ||
ownerBranchStore.Delete(types.NFTOwnerKey( | ||
nft.Owner, | ||
)) | ||
|
||
data := cdc.MustMarshal(&types.Owner{ | ||
Address: nft.Owner, | ||
NftAddress: nft.Address, | ||
}) | ||
ownerBranchStore.Set(types.NFTOwnerKey(nft.Address), data) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters