-
Notifications
You must be signed in to change notification settings - Fork 126
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
Showing
4 changed files
with
71 additions
and
65 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
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 |
---|---|---|
@@ -1,77 +1,75 @@ | ||
package v164 | ||
|
||
import ( | ||
// storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
"strings" | ||
|
||
"cosmossdk.io/math" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
// paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
// coinomicstypes "github.com/haqq-network/haqq/x/coinomics/types" | ||
"github.com/haqq-network/haqq/utils" | ||
coinomicskeeper "github.com/haqq-network/haqq/x/coinomics/keeper" | ||
coinomicstypes "github.com/haqq-network/haqq/x/coinomics/types" | ||
) | ||
|
||
const ModuleName = "coinomics" | ||
|
||
// CreateUpgradeHandler creates an SDK upgrade handler for v1.6.4 | ||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
// storeKey storetypes.StoreKey, | ||
// paramsStoreKey storetypes.StoreKey, | ||
// paramsSubspace paramtypes.Subspace, | ||
storeKey storetypes.StoreKey, | ||
paramsStoreKey storetypes.StoreKey, | ||
dk distrkeeper.Keeper, | ||
ck coinomicskeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
logger := ctx.Logger() | ||
|
||
// logger.Info("start clean coinomics store") | ||
|
||
// // Используйте переданный ключ хранилища | ||
// store := ctx.KVStore(storeKey) | ||
MigrateStore(ctx, storeKey, paramsStoreKey, dk, ck) | ||
|
||
// iterator := sdk.KVStorePrefixIterator(store, nil) | ||
|
||
// for ; iterator.Valid(); iterator.Next() { | ||
// println("coinomics store key for delete") | ||
// println(string(iterator.Key())) | ||
|
||
// store.Delete(iterator.Key()) | ||
// } | ||
|
||
// iterator.Close() // Не забудьте закрыть итератор | ||
// logger.Info("cleared coinomics store") | ||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} | ||
|
||
// logger.Info("start cleaning params for module") | ||
// MigrateStore migrates the x/coinomics module state | ||
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, | ||
paramsStoreKey storetypes.StoreKey, dk distrkeeper.Keeper, | ||
ck coinomicskeeper.Keeper) { | ||
// clean module state | ||
store := ctx.KVStore(storeKey) | ||
iterator := sdk.KVStorePrefixIterator(store, nil) | ||
|
||
// keyTable := coinomicstypes.ParamKeyTable() | ||
// paramsSubspace = paramsSubspace.WithKeyTable(keyTable) | ||
for ; iterator.Valid(); iterator.Next() { | ||
println("coinomics store key for delete") | ||
println(string(iterator.Key())) | ||
|
||
// paramsSubspace.SetParamSet(ctx, &coinomicstypes.Params{}) | ||
store.Delete(iterator.Key()) | ||
} | ||
|
||
// if paramsSubspace.HasKeyTable() { | ||
// clean params | ||
paramsStore := ctx.KVStore(paramsStoreKey) | ||
paramsIterator := sdk.KVStorePrefixIterator(paramsStore, nil) | ||
|
||
// paramsSubspace.WithKeyTable(paramtypes.NewKeyTable()) | ||
// // paramsSubspace.IterateKeys(ctx, func(key []byte) bool { | ||
// // println(string(key)) | ||
for ; paramsIterator.Valid(); paramsIterator.Next() { | ||
if strings.Contains(string(paramsIterator.Key()), "coinomics/") { | ||
println("coinomics store key/value") | ||
|
||
// // paramsSubspace.Update(ctx, key, nil) | ||
// // return false | ||
// // }) | ||
// } | ||
println(string(paramsIterator.Key())) | ||
println(string(paramsIterator.Value())) | ||
|
||
// if !ps.HasKeyTable() { | ||
// ps = ps.WithKeyTable(types.ParamKeyTable()) | ||
// } | ||
paramsStore.Delete(paramsIterator.Key()) | ||
} | ||
} | ||
|
||
// paramsSubspace.Set(ctx, []byte(ModuleName), nil) // Получаем пространство параметров для модуля | ||
// iter := storeParams.Iterator(nil, nil) // Создаем итератор для всех ключей | ||
// defer iter.Close() | ||
// reset coinomics params | ||
defaultParams := coinomicstypes.DefaultParams() | ||
|
||
// for ; iter.Valid(); iter.Next() { | ||
// storeParams.Delete(iter.Key()) // Удаляем каждый ключ | ||
// } | ||
if utils.IsMainNetwork(ctx.ChainID()) { | ||
defaultParams.EnableCoinomics = false | ||
} | ||
|
||
logger.Info("start default sdk migration for v1.6.4") | ||
maxSupply := sdk.Coin{Denom: "aISLM", Amount: math.NewIntWithDecimal(100_000_000_000, 18)} // 100bn ISLM | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
ck.SetMaxSupply(ctx, maxSupply) | ||
ck.SetParams(ctx, defaultParams) | ||
} |
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