From 3d6688a9f568f0ea0ab4660ea6b6073c91fccecf Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 28 Feb 2024 14:56:40 +0100 Subject: [PATCH] sdk.context -> context.context --- app/app.go | 10 +-- app/app_config.go | 7 +- x/epochs/keeper/epoch_info.go | 23 +++--- x/epochs/keeper/epoch_info_test.go | 3 +- x/furnace/keeper/burn_amount.go | 42 +++++----- x/furnace/keeper/burn_amount_test.go | 3 +- x/furnace/keeper/epoch_burn_config.go | 17 +++-- x/furnace/keeper/epoch_burn_config_test.go | 5 +- x/furnace/keeper/events.go | 8 +- x/furnace/keeper/params.go | 1 + x/furnace/keeper/query_burn_amount.go | 2 +- x/furnace/module/autocli.go | 6 +- x/furnace/module/module.go | 12 +-- x/furnace/module/simulation.go | 4 +- x/furnace/types/expected_keepers.go | 2 +- x/furnace/types/keys.go | 4 +- x/registry/keeper/domain_ownership.go | 27 +++---- x/registry/keeper/domain_ownership_test.go | 5 +- x/registry/keeper/events.go | 25 ++++-- x/registry/keeper/keeper.go | 4 +- x/registry/keeper/params.go | 1 + x/registry/keeper/second_level_domain.go | 76 ++++++++++--------- x/registry/keeper/second_level_domain_test.go | 7 +- x/registry/keeper/top_level_domain.go | 75 +++++++++--------- x/registry/keeper/top_level_domain_fee.go | 15 ++-- x/registry/keeper/top_level_domain_test.go | 7 +- x/registry/types/expected_keepers.go | 2 +- 27 files changed, 208 insertions(+), 185 deletions(-) diff --git a/app/app.go b/app/app.go index 5a58ec04..48bd7ade 100644 --- a/app/app.go +++ b/app/app.go @@ -85,7 +85,7 @@ import ( // Mycel Modules epochsmodulekeeper "github.com/mycel-domain/mycel/x/epochs/keeper" furnacemodulekeeper "github.com/mycel-domain/mycel/x/furnace/keeper" - registrymodulekeeper "github.com/mycel-domain/mycel/x/registry/keeper" + registrymodulekeeper "github.com/mycel-domain/mycel/x/registry/keeper" ) const ( @@ -151,9 +151,9 @@ type App struct { // WasmKeeper wasmkeeper.Keeper // Mycel modules - EpochsKeeper epochsmodulekeeper.Keeper - FurnaceKeeper furnacemodulekeeper.Keeper - RegistryKeeper registrymodulekeeper.Keeper + EpochsKeeper epochsmodulekeeper.Keeper + FurnaceKeeper furnacemodulekeeper.Keeper + RegistryKeeper registrymodulekeeper.Keeper // sm is the simulation manager sm *module.SimulationManager @@ -295,7 +295,7 @@ func New( // Mycel Keepers &app.EpochsKeeper, &app.FurnaceKeeper, - &app.RegistryKeeper, + &app.RegistryKeeper, // this line is used by starport scaffolding # stargate/app/keeperDefinition ); err != nil { panic(err) diff --git a/app/app_config.go b/app/app_config.go index eaa99398..1b94222c 100644 --- a/app/app_config.go +++ b/app/app_config.go @@ -56,17 +56,16 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - appparams "github.com/mycel-domain/mycel/app/params" - // Mycel modules // Epochs epochsmodulev1 "github.com/mycel-domain/mycel/api/mycel/epochs/module/v1" - epochsmoduletypes "github.com/mycel-domain/mycel/x/epochs/types" // Furnace furnacemodulev1 "github.com/mycel-domain/mycel/api/mycel/furnace/module/v1" - furnacemoduletypes "github.com/mycel-domain/mycel/x/furnace/types" // Registry registrymodulev1 "github.com/mycel-domain/mycel/api/mycel/registry/module/v1" + appparams "github.com/mycel-domain/mycel/app/params" + epochsmoduletypes "github.com/mycel-domain/mycel/x/epochs/types" + furnacemoduletypes "github.com/mycel-domain/mycel/x/furnace/types" registrymoduletypes "github.com/mycel-domain/mycel/x/registry/types" ) diff --git a/x/epochs/keeper/epoch_info.go b/x/epochs/keeper/epoch_info.go index 529ae77d..e4212d11 100644 --- a/x/epochs/keeper/epoch_info.go +++ b/x/epochs/keeper/epoch_info.go @@ -1,18 +1,19 @@ package keeper import ( + "context" + "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/mycel-domain/mycel/x/epochs/types" ) // SetEpochInfo set a specific epochInfo in the store from its index -func (k Keeper) SetEpochInfo(ctx sdk.Context, epochInfo types.EpochInfo) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) SetEpochInfo(goCtx context.Context, epochInfo types.EpochInfo) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.EpochInfoKeyPrefix)) b := k.cdc.MustMarshal(&epochInfo) store.Set(types.EpochInfoKey( @@ -22,10 +23,10 @@ func (k Keeper) SetEpochInfo(ctx sdk.Context, epochInfo types.EpochInfo) { // GetEpochInfo returns a epochInfo from its index func (k Keeper) GetEpochInfo( - ctx sdk.Context, + goCtx context.Context, identifier string, ) (val types.EpochInfo, found bool) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.EpochInfoKeyPrefix)) b := store.Get(types.EpochInfoKey( @@ -41,10 +42,10 @@ func (k Keeper) GetEpochInfo( // RemoveEpochInfo removes a epochInfo from the store func (k Keeper) RemoveEpochInfo( - ctx sdk.Context, + goCtx context.Context, identifier string, ) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.EpochInfoKeyPrefix)) store.Delete(types.EpochInfoKey( @@ -53,8 +54,8 @@ func (k Keeper) RemoveEpochInfo( } // GetAllEpochInfo returns all epochInfo -func (k Keeper) GetAllEpochInfo(ctx sdk.Context) (list []types.EpochInfo) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) GetAllEpochInfo(goCtx context.Context) (list []types.EpochInfo) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.EpochInfoKeyPrefix)) iterator := storetypes.KVStorePrefixIterator(store, []byte{}) @@ -71,8 +72,8 @@ func (k Keeper) GetAllEpochInfo(ctx sdk.Context) (list []types.EpochInfo) { } // Iterate though epochs -func (k Keeper) IterateEpochInfo(ctx sdk.Context, fn func(index int64, epochInfo types.EpochInfo) (stop bool)) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) IterateEpochInfo(goCtx context.Context, fn func(index int64, epochInfo types.EpochInfo) (stop bool)) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.EpochInfoKeyPrefix)) iterator := storetypes.KVStorePrefixIterator(store, nil) diff --git a/x/epochs/keeper/epoch_info_test.go b/x/epochs/keeper/epoch_info_test.go index 21f64324..9b1a16a1 100644 --- a/x/epochs/keeper/epoch_info_test.go +++ b/x/epochs/keeper/epoch_info_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "strconv" "testing" @@ -17,7 +18,7 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize -func createNEpochInfo(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.EpochInfo { +func createNEpochInfo(keeper *keeper.Keeper, ctx context.Context, n int) []types.EpochInfo { items := make([]types.EpochInfo, n) for i := range items { items[i].Identifier = strconv.Itoa(i) diff --git a/x/furnace/keeper/burn_amount.go b/x/furnace/keeper/burn_amount.go index 9b432e2d..3289c48b 100644 --- a/x/furnace/keeper/burn_amount.go +++ b/x/furnace/keeper/burn_amount.go @@ -1,11 +1,13 @@ package keeper import ( + "context" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/mycel-domain/mycel/app/params" @@ -13,8 +15,8 @@ import ( ) // SetBurnAmount set a specific burnAmount in the store from its index -func (k Keeper) SetBurnAmount(ctx sdk.Context, burnAmount types.BurnAmount) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) SetBurnAmount(goCtx context.Context, burnAmount types.BurnAmount) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.BurnAmountKeyPrefix)) b := k.cdc.MustMarshal(&burnAmount) store.Set(types.BurnAmountKey( @@ -24,10 +26,10 @@ func (k Keeper) SetBurnAmount(ctx sdk.Context, burnAmount types.BurnAmount) { // GetBurnAmount returns a burnAmount from its index func (k Keeper) GetBurnAmount( - ctx sdk.Context, + goCtx context.Context, index uint64, ) (val types.BurnAmount, found bool) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.BurnAmountKeyPrefix)) b := store.Get(types.BurnAmountKey( @@ -43,10 +45,10 @@ func (k Keeper) GetBurnAmount( // RemoveBurnAmount removes a burnAmount from the store func (k Keeper) RemoveBurnAmount( - ctx sdk.Context, + goCtx context.Context, index uint64, ) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.BurnAmountKeyPrefix)) store.Delete(types.BurnAmountKey( @@ -55,8 +57,8 @@ func (k Keeper) RemoveBurnAmount( } // GetAllBurnAmount returns all burnAmount -func (k Keeper) GetAllBurnAmount(ctx sdk.Context) (list []types.BurnAmount) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) GetAllBurnAmount(goCtx context.Context) (list []types.BurnAmount) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.BurnAmountKeyPrefix)) iterator := storetypes.KVStorePrefixIterator(store, []byte{}) @@ -71,47 +73,47 @@ func (k Keeper) GetAllBurnAmount(ctx sdk.Context) (list []types.BurnAmount) { } // Create a next burnAmount -func (k Keeper) NewBurnAmount(ctx sdk.Context, config types.EpochBurnConfig, index uint64) (burnAmount types.BurnAmount) { +func (k Keeper) NewBurnAmount(goCtx context.Context, config types.EpochBurnConfig, index uint64) (burnAmount types.BurnAmount) { // Create burn amount burnAmount = types.NewBurnAmount(config, index) - k.SetBurnAmount(ctx, burnAmount) + k.SetBurnAmount(goCtx, burnAmount) // Emit event - EmitBurnAmountCreatedEvent(ctx, &burnAmount) + EmitBurnAmountCreatedEvent(goCtx, &burnAmount) return burnAmount } // Add to total burn BurnAmount -func (k Keeper) AddToTotalBurnAmount(ctx sdk.Context, index uint64, amount sdk.Coin) (newBurnAmount types.BurnAmount) { +func (k Keeper) AddToTotalBurnAmount(goCtx context.Context, index uint64, amount sdk.Coin) (newBurnAmount types.BurnAmount) { // Get burn amount - burnAmount, found := k.GetBurnAmount(ctx, index) + burnAmount, found := k.GetBurnAmount(goCtx, index) if !found { panic("burn amount not found") } // Update burn amount burnAmount.TotalBurnAmount = burnAmount.TotalBurnAmount.Add(amount) - k.SetBurnAmount(ctx, burnAmount) + k.SetBurnAmount(goCtx, burnAmount) return burnAmount } // Add registration fee to burnAmounts -func (k Keeper) AddRegistrationFeeToBurnAmounts(ctx sdk.Context, registrationPeriodInYear uint64, amount sdk.Coin) (burnAmounts []types.BurnAmount, err error) { +func (k Keeper) AddRegistrationFeeToBurnAmounts(goCtx context.Context, registrationPeriodInYear uint64, amount sdk.Coin) (burnAmounts []types.BurnAmount, err error) { // Check registrationPeriodInYear if registrationPeriodInYear == 0 { return nil, errorsmod.Wrapf(types.ErrInvalidRegistrationPeriod, "%d", registrationPeriodInYear) } - epochBurnConfig, found := k.GetEpochBurnConfig(ctx) + epochBurnConfig, found := k.GetEpochBurnConfig(goCtx) if !found { panic("epoch burn config not found") } remainDays := registrationPeriodInYear * params.OneYearInDays for i := epochBurnConfig.CurrentBurnAmountIndex + 1; remainDays > 0; i++ { - burnAmount, found := k.GetBurnAmount(ctx, i) + burnAmount, found := k.GetBurnAmount(goCtx, i) // Create new burn amount if not found if !found { - burnAmount = k.NewBurnAmount(ctx, epochBurnConfig, i) + burnAmount = k.NewBurnAmount(goCtx, epochBurnConfig, i) } burnAmounts = append(burnAmounts, burnAmount) @@ -134,7 +136,7 @@ func (k Keeper) AddRegistrationFeeToBurnAmounts(ctx sdk.Context, registrationPer amount = sdk.NewCoin(amount.Denom, quotient) } burnAmounts[i].TotalBurnAmount = amount - k.AddToTotalBurnAmount(ctx, burnAmount.Index, amount) + k.AddToTotalBurnAmount(goCtx, burnAmount.Index, amount) } return burnAmounts, err } diff --git a/x/furnace/keeper/burn_amount_test.go b/x/furnace/keeper/burn_amount_test.go index a7a1d264..f7dba1a9 100644 --- a/x/furnace/keeper/burn_amount_test.go +++ b/x/furnace/keeper/burn_amount_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "fmt" "strconv" "testing" @@ -21,7 +22,7 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize -func createNBurnAmount(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.BurnAmount { +func createNBurnAmount(keeper *keeper.Keeper, ctx context.Context, n int) []types.BurnAmount { items := make([]types.BurnAmount, n) for i := range items { items[i].Index = uint64(i) diff --git a/x/furnace/keeper/epoch_burn_config.go b/x/furnace/keeper/epoch_burn_config.go index ec390756..75b9acad 100644 --- a/x/furnace/keeper/epoch_burn_config.go +++ b/x/furnace/keeper/epoch_burn_config.go @@ -1,17 +1,18 @@ package keeper import ( + "context" + "cosmossdk.io/store/prefix" - "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/mycel-domain/mycel/x/furnace/types" ) // SetEpochBurnConfig set epochBurnConfig in the store -func (k Keeper) SetEpochBurnConfig(ctx sdk.Context, epochBurnConfig types.EpochBurnConfig) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) SetEpochBurnConfig(goCtx context.Context, epochBurnConfig types.EpochBurnConfig) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.BurnAmountKeyPrefix)) b := k.cdc.MustMarshal(&epochBurnConfig) @@ -19,8 +20,8 @@ func (k Keeper) SetEpochBurnConfig(ctx sdk.Context, epochBurnConfig types.EpochB } // GetEpochBurnConfig returns epochBurnConfig -func (k Keeper) GetEpochBurnConfig(ctx sdk.Context) (val types.EpochBurnConfig, found bool) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) GetEpochBurnConfig(goCtx context.Context) (val types.EpochBurnConfig, found bool) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.BurnAmountKeyPrefix)) b := store.Get([]byte{0}) @@ -33,8 +34,8 @@ func (k Keeper) GetEpochBurnConfig(ctx sdk.Context) (val types.EpochBurnConfig, } // RemoveEpochBurnConfig removes epochBurnConfig from the store -func (k Keeper) RemoveEpochBurnConfig(ctx sdk.Context) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) RemoveEpochBurnConfig(goCtx context.Context) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.BurnAmountKeyPrefix)) store.Delete([]byte{0}) diff --git a/x/furnace/keeper/epoch_burn_config_test.go b/x/furnace/keeper/epoch_burn_config_test.go index dc9ed518..6627c111 100644 --- a/x/furnace/keeper/epoch_burn_config_test.go +++ b/x/furnace/keeper/epoch_burn_config_test.go @@ -1,19 +1,18 @@ package keeper_test import ( + "context" "testing" "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" - keepertest "github.com/mycel-domain/mycel/testutil/keeper" "github.com/mycel-domain/mycel/testutil/nullify" "github.com/mycel-domain/mycel/x/furnace/keeper" "github.com/mycel-domain/mycel/x/furnace/types" ) -func createTestEpochBurnConfig(keeper *keeper.Keeper, ctx sdk.Context) types.EpochBurnConfig { //nolint:unparam +func createTestEpochBurnConfig(keeper *keeper.Keeper, ctx context.Context) types.EpochBurnConfig { //nolint:unparam item := types.EpochBurnConfig{} keeper.SetEpochBurnConfig(ctx, item) return item diff --git a/x/furnace/keeper/events.go b/x/furnace/keeper/events.go index 9b4d4e14..7fda66bc 100644 --- a/x/furnace/keeper/events.go +++ b/x/furnace/keeper/events.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -8,7 +10,8 @@ import ( "github.com/mycel-domain/mycel/x/furnace/types" ) -func EmitEpochBurnEvent(ctx sdk.Context, epochIdentifier string, epochNumber int64, burnAmount *types.BurnAmount, burnt sdk.Coin) { +func EmitEpochBurnEvent(goCtx context.Context, epochIdentifier string, epochNumber int64, burnAmount *types.BurnAmount, burnt sdk.Coin) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeEpochBurn, @@ -24,7 +27,8 @@ func EmitEpochBurnEvent(ctx sdk.Context, epochIdentifier string, epochNumber int ) } -func EmitBurnAmountCreatedEvent(ctx sdk.Context, burnAmount *types.BurnAmount) { +func EmitBurnAmountCreatedEvent(goCtx context.Context, burnAmount *types.BurnAmount) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeBurnAmountCreated, diff --git a/x/furnace/keeper/params.go b/x/furnace/keeper/params.go index bef3393c..4a28bbe4 100644 --- a/x/furnace/keeper/params.go +++ b/x/furnace/keeper/params.go @@ -4,6 +4,7 @@ import ( "context" "github.com/cosmos/cosmos-sdk/runtime" + "github.com/mycel-domain/mycel/x/furnace/types" ) diff --git a/x/furnace/keeper/query_burn_amount.go b/x/furnace/keeper/query_burn_amount.go index 115b76b2..b2ee7d34 100644 --- a/x/furnace/keeper/query_burn_amount.go +++ b/x/furnace/keeper/query_burn_amount.go @@ -7,8 +7,8 @@ import ( "google.golang.org/grpc/status" "cosmossdk.io/store/prefix" - "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" diff --git a/x/furnace/module/autocli.go b/x/furnace/module/autocli.go index 115b2f2a..20657e3f 100644 --- a/x/furnace/module/autocli.go +++ b/x/furnace/module/autocli.go @@ -23,9 +23,9 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { Short: "Shows the burn amounts", }, { - RpcMethod: "BurnAmount", - Use: "burn-amount [index]", - Short: "Shows the burn amount", + RpcMethod: "BurnAmount", + Use: "burn-amount [index]", + Short: "Shows the burn amount", PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "index"}}, }, { diff --git a/x/furnace/module/module.go b/x/furnace/module/module.go index 6215ee8a..8e76bbf7 100644 --- a/x/furnace/module/module.go +++ b/x/furnace/module/module.go @@ -96,10 +96,10 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r type AppModule struct { AppModuleBasic - keeper keeper.Keeper + keeper keeper.Keeper accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - epochsKeeper types.EpochsKeeper + bankKeeper types.BankKeeper + epochsKeeper types.EpochsKeeper } func NewAppModule( @@ -184,8 +184,8 @@ type ModuleInputs struct { Logger log.Logger AccountKeeper types.AccountKeeper - BankKeeper types.BankKeeper - EpochsKeeper types.EpochsKeeper + BankKeeper types.BankKeeper + EpochsKeeper types.EpochsKeeper } type ModuleOutputs struct { @@ -212,7 +212,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { m := NewAppModule( in.Cdc, *k, - in.AccountKeeper, + in.AccountKeeper, in.BankKeeper, in.EpochsKeeper, ) diff --git a/x/furnace/module/simulation.go b/x/furnace/module/simulation.go index e37c22df..4224db39 100644 --- a/x/furnace/module/simulation.go +++ b/x/furnace/module/simulation.go @@ -33,8 +33,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { accs[i] = acc.Address.String() } furnaceGenesis := types.GenesisState{ - EpochBurnConfig: types.DefaultGenesis().GetEpochBurnConfig(), - BurnAmounts: types.DefaultGenesis().BurnAmounts, + EpochBurnConfig: types.DefaultGenesis().GetEpochBurnConfig(), + BurnAmounts: types.DefaultGenesis().BurnAmounts, // this line is used by starport scaffolding # simapp/module/genesisState } simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&furnaceGenesis) diff --git a/x/furnace/types/expected_keepers.go b/x/furnace/types/expected_keepers.go index 6d6c2928..e480c7ba 100644 --- a/x/furnace/types/expected_keepers.go +++ b/x/furnace/types/expected_keepers.go @@ -10,7 +10,7 @@ import ( type EpochsKeeper interface { // Methods imported from epochs should be defined here - GetEpochInfo(ctx sdk.Context, identifier string) (val epochstypes.EpochInfo, found bool) + GetEpochInfo(ctx context.Context, identifier string) (val epochstypes.EpochInfo, found bool) } // AccountKeeper defines the expected account keeper used for simulations (noalias) diff --git a/x/furnace/types/keys.go b/x/furnace/types/keys.go index b445771e..66492e89 100644 --- a/x/furnace/types/keys.go +++ b/x/furnace/types/keys.go @@ -18,9 +18,7 @@ func KeyPrefix(p string) []byte { return []byte(p) } -var ( - ParamsKey = []byte("p_furnace") -) +var ParamsKey = []byte("p_furnace") const ( EpochBurnConfigKey = "EpochBurnConfig/value/" diff --git a/x/registry/keeper/domain_ownership.go b/x/registry/keeper/domain_ownership.go index d9932fa9..5d39c80c 100644 --- a/x/registry/keeper/domain_ownership.go +++ b/x/registry/keeper/domain_ownership.go @@ -1,18 +1,19 @@ package keeper import ( + "context" + "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/runtime" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/mycel-domain/mycel/x/registry/types" ) // SetDomainOwnership set a specific domainOwnership in the store from its index -func (k Keeper) SetDomainOwnership(ctx sdk.Context, domainOwnership types.DomainOwnership) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) SetDomainOwnership(goCtx context.Context, domainOwnership types.DomainOwnership) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) b := k.cdc.MustMarshal(&domainOwnership) @@ -23,10 +24,10 @@ func (k Keeper) SetDomainOwnership(ctx sdk.Context, domainOwnership types.Domain // GetDomainOwnership returns a domainOwnership from its index func (k Keeper) GetDomainOwnership( - ctx sdk.Context, + goCtx context.Context, owner string, ) (val types.DomainOwnership, found bool) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) b := store.Get(types.DomainOwnershipKey( @@ -42,10 +43,10 @@ func (k Keeper) GetDomainOwnership( // RemoveDomainOwnership removes a domainOwnership from the store func (k Keeper) RemoveDomainOwnership( - ctx sdk.Context, + goCtx context.Context, owner string, ) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) store.Delete(types.DomainOwnershipKey( @@ -54,8 +55,8 @@ func (k Keeper) RemoveDomainOwnership( } // GetAllDomainOwnership returns all domainOwnership -func (k Keeper) GetAllDomainOwnership(ctx sdk.Context) (list []types.DomainOwnership) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) GetAllDomainOwnership(goCtx context.Context) (list []types.DomainOwnership) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) iterator := storetypes.KVStorePrefixIterator(store, []byte{}) @@ -72,12 +73,12 @@ func (k Keeper) GetAllDomainOwnership(ctx sdk.Context) (list []types.DomainOwner } // Append to owned domain -func (k Keeper) AppendToOwnedDomain(ctx sdk.Context, owner string, name string, parent string) { - domainOwnership, found := k.GetDomainOwnership(ctx, owner) +func (k Keeper) AppendToOwnedDomain(goCtx context.Context, owner string, name string, parent string) { + domainOwnership, found := k.GetDomainOwnership(goCtx, owner) if found { domainOwnership.Domains = append(domainOwnership.Domains, &types.OwnedDomain{Name: name, Parent: parent}) - k.SetDomainOwnership(ctx, domainOwnership) + k.SetDomainOwnership(goCtx, domainOwnership) } else { - k.SetDomainOwnership(ctx, types.DomainOwnership{Owner: owner, Domains: []*types.OwnedDomain{{Name: name, Parent: parent}}}) + k.SetDomainOwnership(goCtx, types.DomainOwnership{Owner: owner, Domains: []*types.OwnedDomain{{Name: name, Parent: parent}}}) } } diff --git a/x/registry/keeper/domain_ownership_test.go b/x/registry/keeper/domain_ownership_test.go index 5548007d..511e0661 100644 --- a/x/registry/keeper/domain_ownership_test.go +++ b/x/registry/keeper/domain_ownership_test.go @@ -1,13 +1,12 @@ package keeper_test import ( + "context" "strconv" "testing" "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" - keepertest "github.com/mycel-domain/mycel/testutil/keeper" "github.com/mycel-domain/mycel/testutil/nullify" "github.com/mycel-domain/mycel/x/registry/keeper" @@ -17,7 +16,7 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize -func createNDomainOwnership(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.DomainOwnership { +func createNDomainOwnership(keeper *keeper.Keeper, ctx context.Context, n int) []types.DomainOwnership { items := make([]types.DomainOwnership, n) for i := range items { items[i].Owner = strconv.Itoa(i) diff --git a/x/registry/keeper/events.go b/x/registry/keeper/events.go index 8be2aef7..8e708400 100644 --- a/x/registry/keeper/events.go +++ b/x/registry/keeper/events.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -9,7 +10,8 @@ import ( ) // Register top-level-domain event -func EmitRegisterTopLevelDomainEvent(ctx sdk.Context, domain types.TopLevelDomain, fee types.TopLevelDomainFee) { +func EmitRegisterTopLevelDomainEvent(goCtx context.Context, domain types.TopLevelDomain, fee types.TopLevelDomainFee) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeRegisterTopLevelDomain, @@ -25,7 +27,8 @@ func EmitRegisterTopLevelDomainEvent(ctx sdk.Context, domain types.TopLevelDomai } // Register second-level-domain event -func EmitRegisterSecondLevelDomainEvent(ctx sdk.Context, domain types.SecondLevelDomain, fee sdk.Coin) { +func EmitRegisterSecondLevelDomainEvent(goCtx context.Context, domain types.SecondLevelDomain, fee sdk.Coin) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeRegisterSecondLevelDomain, sdk.NewAttribute(types.AttributeRegisterSecondLevelDomainEventName, domain.Name), @@ -37,7 +40,8 @@ func EmitRegisterSecondLevelDomainEvent(ctx sdk.Context, domain types.SecondLeve } // Update wallet record event -func EmitUpdateWalletRecordEvent(ctx sdk.Context, msg types.MsgUpdateWalletRecord) { +func EmitUpdateWalletRecordEvent(goCtx context.Context, msg types.MsgUpdateWalletRecord) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeUpdateWalletRecord, sdk.NewAttribute(types.AttributeUpdateWalletRecordEventDomainName, msg.Name), @@ -49,7 +53,8 @@ func EmitUpdateWalletRecordEvent(ctx sdk.Context, msg types.MsgUpdateWalletRecor } // Update dns record event -func EmitUpdateDnsRecordEvent(ctx sdk.Context, msg types.MsgUpdateDnsRecord) { +func EmitUpdateDnsRecordEvent(goCtx context.Context, msg types.MsgUpdateDnsRecord) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeUpdateDnsRecord, sdk.NewAttribute(types.AttributeUpdateDnsRecordEventDomainName, msg.Name), @@ -61,7 +66,8 @@ func EmitUpdateDnsRecordEvent(ctx sdk.Context, msg types.MsgUpdateDnsRecord) { } // Update dns record event -func EmitUpdateTextRecordEvent(ctx sdk.Context, msg types.MsgUpdateTextRecord) { +func EmitUpdateTextRecordEvent(goCtx context.Context, msg types.MsgUpdateTextRecord) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeUpdateTextRecord, sdk.NewAttribute(types.AttributeUpdateTextRecordEventDomainName, msg.Name), @@ -73,7 +79,8 @@ func EmitUpdateTextRecordEvent(ctx sdk.Context, msg types.MsgUpdateTextRecord) { } // Withdraw fees event -func EmitWithdrawRegistrationFeeEvent(ctx sdk.Context, msg types.MsgWithdrawRegistrationFee, fee sdk.Coins) { +func EmitWithdrawRegistrationFeeEvent(goCtx context.Context, msg types.MsgWithdrawRegistrationFee, fee sdk.Coins) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeWithdrawRegistrationFee, sdk.NewAttribute(types.AttributeWithdrawRegistrationFeeEventDomainName, msg.Name), @@ -83,7 +90,8 @@ func EmitWithdrawRegistrationFeeEvent(ctx sdk.Context, msg types.MsgWithdrawRegi } // Extend top-level-domain expiration date event -func EmitExtendTopLevelDomainExpirationDateEvent(ctx sdk.Context, domain types.TopLevelDomain, fee types.TopLevelDomainFee) { +func EmitExtendTopLevelDomainExpirationDateEvent(goCtx context.Context, domain types.TopLevelDomain, fee types.TopLevelDomainFee) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeExtendTopLevelDomainExpirationDate, sdk.NewAttribute(types.AttributeExtendTopLevelDomainExpirationDateEventDomainName, domain.Name), @@ -97,7 +105,8 @@ func EmitExtendTopLevelDomainExpirationDateEvent(ctx sdk.Context, domain types.T } // Update top-level-domain registration policy -func EmitUpdateTopLevelDomainRegistrationPolicyEvent(ctx sdk.Context, domain types.TopLevelDomain) { +func EmitUpdateTopLevelDomainRegistrationPolicyEvent(goCtx context.Context, domain types.TopLevelDomain) { + ctx := sdk.UnwrapSDKContext(goCtx) ctx.EventManager().EmitEvent( sdk.NewEvent(types.EventTypeUpdateTopLevelDomainRegistrationPolicy, sdk.NewAttribute(types.AttributeUpdateTopLevelDomainRegistrationPolicyEventDomainName, domain.Name), diff --git a/x/registry/keeper/keeper.go b/x/registry/keeper/keeper.go index 06cb9d04..67a47d8b 100644 --- a/x/registry/keeper/keeper.go +++ b/x/registry/keeper/keeper.go @@ -21,7 +21,7 @@ type ( bankKeeper types.BankKeeper distributionKeeper types.DistributionKeeper - mintKeeper types.MintKeeper + mintKeeper types.MintKeeper furnaceKeeper types.FurnaceKeeper } ) @@ -49,7 +49,7 @@ func NewKeeper( bankKeeper: bankKeeper, distributionKeeper: distributionKeeper, - mintKeeper: mintKeeper, + mintKeeper: mintKeeper, furnaceKeeper: furnaceKeeper, } } diff --git a/x/registry/keeper/params.go b/x/registry/keeper/params.go index e8c35106..444cab63 100644 --- a/x/registry/keeper/params.go +++ b/x/registry/keeper/params.go @@ -4,6 +4,7 @@ import ( "context" "github.com/cosmos/cosmos-sdk/runtime" + "github.com/mycel-domain/mycel/x/registry/types" ) diff --git a/x/registry/keeper/second_level_domain.go b/x/registry/keeper/second_level_domain.go index ebf63a0d..3fcb2cfd 100644 --- a/x/registry/keeper/second_level_domain.go +++ b/x/registry/keeper/second_level_domain.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "time" errorsmod "cosmossdk.io/errors" @@ -14,8 +15,8 @@ import ( ) // SetSecondLevelDomain set a specific second-level-domain in the store from its index -func (k Keeper) SetSecondLevelDomain(ctx sdk.Context, domain types.SecondLevelDomain) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) SetSecondLevelDomain(goCtx context.Context, domain types.SecondLevelDomain) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.SecondLevelDomainKeyPrefix)) b := k.cdc.MustMarshal(&domain) @@ -27,11 +28,11 @@ func (k Keeper) SetSecondLevelDomain(ctx sdk.Context, domain types.SecondLevelDo // GetSecondLevelDomain returns a second-level-domain from its index func (k Keeper) GetSecondLevelDomain( - ctx sdk.Context, + goCtx context.Context, name string, parent string, ) (val types.SecondLevelDomain, found bool) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.SecondLevelDomainKeyPrefix)) b := store.Get(types.SecondLevelDomainKey( @@ -48,11 +49,11 @@ func (k Keeper) GetSecondLevelDomain( // RemoveSecondLevelDomain removes a second-level-domain from the store func (k Keeper) RemoveSecondLevelDomain( - ctx sdk.Context, + goCtx context.Context, name string, parent string, ) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.SecondLevelDomainKeyPrefix)) store.Delete(types.SecondLevelDomainKey( @@ -62,8 +63,8 @@ func (k Keeper) RemoveSecondLevelDomain( } // GetAllSecondLevelDomain returns all second-level-domain -func (k Keeper) GetAllSecondLevelDomain(ctx sdk.Context) (list []types.SecondLevelDomain) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) GetAllSecondLevelDomain(goCtx context.Context) (list []types.SecondLevelDomain) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.SecondLevelDomainKeyPrefix)) iterator := storetypes.KVStorePrefixIterator(store, []byte{}) @@ -80,13 +81,13 @@ func (k Keeper) GetAllSecondLevelDomain(ctx sdk.Context) (list []types.SecondLev } // Get is second-level-domain already taken -func (k Keeper) GetIsSecondLevelDomainAlreadyTaken(ctx sdk.Context, domain types.SecondLevelDomain) (isDomainAlreadyTaken bool) { - _, isDomainAlreadyTaken = k.GetSecondLevelDomain(ctx, domain.Name, domain.Parent) +func (k Keeper) GetIsSecondLevelDomainAlreadyTaken(goCtx context.Context, domain types.SecondLevelDomain) (isDomainAlreadyTaken bool) { + _, isDomainAlreadyTaken = k.GetSecondLevelDomain(goCtx, domain.Name, domain.Parent) return isDomainAlreadyTaken } // Get valid second-level-domain -func (k Keeper) GetValidSecondLevelDomain(ctx sdk.Context, name string, parent string) (secondLevelDomain types.SecondLevelDomain, err error) { +func (k Keeper) GetValidSecondLevelDomain(goCtx context.Context, name string, parent string) (secondLevelDomain types.SecondLevelDomain, err error) { // Regex validation err = types.ValidateSecondLevelDomainName(name) if err != nil { @@ -98,18 +99,19 @@ func (k Keeper) GetValidSecondLevelDomain(ctx sdk.Context, name string, parent s } // Get parent domain - _, err = k.GetValidTopLevelDomain(ctx, parent) + _, err = k.GetValidTopLevelDomain(goCtx, parent) if err != nil { return types.SecondLevelDomain{}, err } // Get second-level-domain - secondLevelDomain, isFound := k.GetSecondLevelDomain(ctx, name, parent) + secondLevelDomain, isFound := k.GetSecondLevelDomain(goCtx, name, parent) if !isFound { return types.SecondLevelDomain{}, errorsmod.Wrapf(types.ErrSecondLevelDomainNotFound, "%s.%s", name, parent) } // Check if second-level-domain is not expired + ctx := sdk.UnwrapSDKContext(goCtx) if ctx.BlockTime().After(secondLevelDomain.ExpirationDate) && secondLevelDomain.ExpirationDate != (time.Time{}) { return types.SecondLevelDomain{}, errorsmod.Wrapf(types.ErrSecondLevelDomainExpired, "%s", name) } @@ -118,17 +120,17 @@ func (k Keeper) GetValidSecondLevelDomain(ctx sdk.Context, name string, parent s } // Get parent domain -func (k Keeper) GetSecondLevelDomainParent(ctx sdk.Context, domain types.SecondLevelDomain) (parentDomain types.TopLevelDomain, found bool) { +func (k Keeper) GetSecondLevelDomainParent(goCtx context.Context, domain types.SecondLevelDomain) (parentDomain types.TopLevelDomain, found bool) { // Get parent domain parent := domain.ParseParent() - parentDomain, found = k.GetTopLevelDomain(ctx, parent) + parentDomain, found = k.GetTopLevelDomain(goCtx, parent) return parentDomain, found } // Get parent domain's subdomain config -func (k Keeper) GetSecondLevelDomainParentsSubdomainConfig(ctx sdk.Context, domain types.SecondLevelDomain) types.SubdomainConfig { +func (k Keeper) GetSecondLevelDomainParentsSubdomainConfig(goCtx context.Context, domain types.SecondLevelDomain) types.SubdomainConfig { // Get parent domain - parentDomain, found := k.GetSecondLevelDomainParent(ctx, domain) + parentDomain, found := k.GetSecondLevelDomainParent(goCtx, domain) if !found || parentDomain.SubdomainConfig == nil { panic("parent domain or config not found") } @@ -136,8 +138,8 @@ func (k Keeper) GetSecondLevelDomainParentsSubdomainConfig(ctx sdk.Context, doma } // Get Role of the second-level domain -func (k Keeper) GetSecondLevelDomainRole(ctx sdk.Context, name, parent, address string) (role types.DomainRole, found bool) { - sld, found := k.GetSecondLevelDomain(ctx, name, parent) +func (k Keeper) GetSecondLevelDomainRole(goCtx context.Context, name, parent, address string) (role types.DomainRole, found bool) { + sld, found := k.GetSecondLevelDomain(goCtx, name, parent) if !found { return types.DomainRole_NO_ROLE, false } @@ -146,20 +148,20 @@ func (k Keeper) GetSecondLevelDomainRole(ctx sdk.Context, name, parent, address } // Increment parents subdomain count -func (k Keeper) IncrementParentsSubdomainCount(ctx sdk.Context, domain types.SecondLevelDomain) { +func (k Keeper) IncrementParentsSubdomainCount(goCtx context.Context, domain types.SecondLevelDomain) { // Increment parent's subdomain count parent := domain.ParseParent() - parentDomain, found := k.GetTopLevelDomain(ctx, parent) + parentDomain, found := k.GetTopLevelDomain(goCtx, parent) if !found { panic("parent not found") } parentDomain.SubdomainCount++ - k.SetTopLevelDomain(ctx, parentDomain) + k.SetTopLevelDomain(goCtx, parentDomain) } // Pay SLD registration fee -func (k Keeper) PaySecondLevelDomainRegstrationFee(ctx sdk.Context, payer sdk.AccAddress, domain types.SecondLevelDomain, registrationPeriodInYear uint64) (fee sdk.Coin, err error) { - config := k.GetSecondLevelDomainParentsSubdomainConfig(ctx, domain) +func (k Keeper) PaySecondLevelDomainRegstrationFee(goCtx context.Context, payer sdk.AccAddress, domain types.SecondLevelDomain, registrationPeriodInYear uint64) (fee sdk.Coin, err error) { + config := k.GetSecondLevelDomainParentsSubdomainConfig(goCtx, domain) fee, err = config.GetRegistrationFee(domain.Name, registrationPeriodInYear) if err != nil { @@ -167,37 +169,37 @@ func (k Keeper) PaySecondLevelDomainRegstrationFee(ctx sdk.Context, payer sdk.Ac } // Send coins from payer to module account - err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, payer, types.ModuleName, sdk.NewCoins(fee)) + err = k.bankKeeper.SendCoinsFromAccountToModule(goCtx, payer, types.ModuleName, sdk.NewCoins(fee)) if err != nil { return fee, err } // Update store - parent, found := k.GetTopLevelDomain(ctx, domain.Parent) + parent, found := k.GetTopLevelDomain(goCtx, domain.Parent) if !found { panic("parent not found") } parent.TotalWithdrawalAmount = parent.TotalWithdrawalAmount.Add(fee) - k.SetTopLevelDomain(ctx, parent) + k.SetTopLevelDomain(goCtx, parent) return fee, err } // Validate second-level-domain is registrable -func (k Keeper) ValidateSecondLevelDomainIsRegistrable(ctx sdk.Context, secondLevelDomain types.SecondLevelDomain, sldOwner sdk.AccAddress) error { +func (k Keeper) ValidateSecondLevelDomainIsRegistrable(goCtx context.Context, secondLevelDomain types.SecondLevelDomain, sldOwner sdk.AccAddress) error { // Validate second-level-domain err := secondLevelDomain.Validate() if err != nil { return err } // Check if second-level-domain is already taken - isTaken := k.GetIsSecondLevelDomainAlreadyTaken(ctx, secondLevelDomain) + isTaken := k.GetIsSecondLevelDomainAlreadyTaken(goCtx, secondLevelDomain) if isTaken { return errorsmod.Wrapf(types.ErrSecondLevelDomainAlreadyTaken, "%s.%s", secondLevelDomain.Name, secondLevelDomain.Parent) } // Get parent domain of second-level-domain - parentDomain, found := k.GetSecondLevelDomainParent(ctx, secondLevelDomain) + parentDomain, found := k.GetSecondLevelDomainParent(goCtx, secondLevelDomain) if !found { return errorsmod.Wrapf(types.ErrSecondLevelDomainParentDoesNotExist, "%s", secondLevelDomain.Parent) } @@ -219,30 +221,30 @@ func (k Keeper) ValidateSecondLevelDomainIsRegistrable(ctx sdk.Context, secondLe } // Register second level domain -func (k Keeper) RegisterSecondLevelDomain(ctx sdk.Context, secondLevelDomain types.SecondLevelDomain, owner sdk.AccAddress, registrationPeriodIYear uint64) (err error) { +func (k Keeper) RegisterSecondLevelDomain(goCtx context.Context, secondLevelDomain types.SecondLevelDomain, owner sdk.AccAddress, registrationPeriodIYear uint64) (err error) { // Validate second-level-domain is registrable - err = k.ValidateSecondLevelDomainIsRegistrable(ctx, secondLevelDomain, owner) + err = k.ValidateSecondLevelDomainIsRegistrable(goCtx, secondLevelDomain, owner) if err != nil { return err } // Increment parents subdomain SubdomainCount - k.IncrementParentsSubdomainCount(ctx, secondLevelDomain) + k.IncrementParentsSubdomainCount(goCtx, secondLevelDomain) // Pay SLD registration fee - fee, err := k.PaySecondLevelDomainRegstrationFee(ctx, owner, secondLevelDomain, registrationPeriodIYear) + fee, err := k.PaySecondLevelDomainRegstrationFee(goCtx, owner, secondLevelDomain, registrationPeriodIYear) if err != nil { return err } // Append to owned domain - k.AppendToOwnedDomain(ctx, owner.String(), secondLevelDomain.Name, secondLevelDomain.Parent) + k.AppendToOwnedDomain(goCtx, owner.String(), secondLevelDomain.Name, secondLevelDomain.Parent) // Set domain - k.SetSecondLevelDomain(ctx, secondLevelDomain) + k.SetSecondLevelDomain(goCtx, secondLevelDomain) // Emit event - EmitRegisterSecondLevelDomainEvent(ctx, secondLevelDomain, fee) + EmitRegisterSecondLevelDomainEvent(goCtx, secondLevelDomain, fee) return err } diff --git a/x/registry/keeper/second_level_domain_test.go b/x/registry/keeper/second_level_domain_test.go index 5e1b52d9..ce406ab4 100644 --- a/x/registry/keeper/second_level_domain_test.go +++ b/x/registry/keeper/second_level_domain_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "fmt" "strconv" "testing" @@ -22,7 +23,7 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize -func createNSecondLevelDomain(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.SecondLevelDomain { +func createNSecondLevelDomain(keeper *keeper.Keeper, ctx context.Context, n int) []types.SecondLevelDomain { items := make([]types.SecondLevelDomain, n) for i := range items { items[i].Name = strconv.Itoa(i) @@ -33,7 +34,7 @@ func createNSecondLevelDomain(keeper *keeper.Keeper, ctx sdk.Context, n int) []t return items } -func createNSecondLevelDomainResponse(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.SecondLevelDomainResponse { +func createNSecondLevelDomainResponse(keeper *keeper.Keeper, ctx context.Context, n int) []types.SecondLevelDomainResponse { items := createNSecondLevelDomain(keeper, ctx, n) responses := make([]types.SecondLevelDomainResponse, n) for i := range responses { @@ -47,7 +48,7 @@ func createNSecondLevelDomainResponse(keeper *keeper.Keeper, ctx sdk.Context, n // Register top-level domains with k.RegisterSecondLevelDomain() // Domain name is set to `n` (n is a incremantal number) // e.g.) `1`, `2`, `n`... -func registerNSecondLevelDomain(k *keeper.Keeper, ctx sdk.Context, creatorAddr string, n int) ([]types.SecondLevelDomain, error) { +func registerNSecondLevelDomain(k *keeper.Keeper, ctx context.Context, creatorAddr string, n int) ([]types.SecondLevelDomain, error) { items := make([]types.SecondLevelDomain, n) for i := range items { creator, err := sdk.AccAddressFromBech32(creatorAddr) diff --git a/x/registry/keeper/top_level_domain.go b/x/registry/keeper/top_level_domain.go index d80f3396..fd23f278 100644 --- a/x/registry/keeper/top_level_domain.go +++ b/x/registry/keeper/top_level_domain.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "time" errorsmod "cosmossdk.io/errors" @@ -16,8 +17,8 @@ import ( ) // SetTopLevelDomain set a specific topLevelDomain in the store from its index -func (k Keeper) SetTopLevelDomain(ctx sdk.Context, topLevelDomain types.TopLevelDomain) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) SetTopLevelDomain(goCtx context.Context, topLevelDomain types.TopLevelDomain) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) b := k.cdc.MustMarshal(&topLevelDomain) @@ -28,10 +29,10 @@ func (k Keeper) SetTopLevelDomain(ctx sdk.Context, topLevelDomain types.TopLevel // GetTopLevelDomain returns a topLevelDomain from its index func (k Keeper) GetTopLevelDomain( - ctx sdk.Context, + goCtx context.Context, name string, ) (val types.TopLevelDomain, found bool) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) b := store.Get(types.TopLevelDomainKey( @@ -47,10 +48,10 @@ func (k Keeper) GetTopLevelDomain( // RemoveTopLevelDomain removes a topLevelDomain from the store func (k Keeper) RemoveTopLevelDomain( - ctx sdk.Context, + goCtx context.Context, name string, ) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) store.Delete(types.TopLevelDomainKey( @@ -59,8 +60,8 @@ func (k Keeper) RemoveTopLevelDomain( } // GetAllTopLevelDomain returns all topLevelDomain -func (k Keeper) GetAllTopLevelDomain(ctx sdk.Context) (list []types.TopLevelDomain) { - storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) +func (k Keeper) GetAllTopLevelDomain(goCtx context.Context) (list []types.TopLevelDomain) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(goCtx)) store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.DomainOwnershipKeyPrefix)) iterator := storetypes.KVStorePrefixIterator(store, []byte{}) @@ -77,13 +78,13 @@ func (k Keeper) GetAllTopLevelDomain(ctx sdk.Context) (list []types.TopLevelDoma } // Get is top-level-domain already taken -func (k Keeper) GetIsTopLevelDomainAlreadyTaken(ctx sdk.Context, domain types.TopLevelDomain) (isDomainAlreadyTaken bool) { - _, isDomainAlreadyTaken = k.GetTopLevelDomain(ctx, domain.Name) +func (k Keeper) GetIsTopLevelDomainAlreadyTaken(goCtx context.Context, domain types.TopLevelDomain) (isDomainAlreadyTaken bool) { + _, isDomainAlreadyTaken = k.GetTopLevelDomain(goCtx, domain.Name) return isDomainAlreadyTaken } // Get valid-top-level domain -func (k Keeper) GetValidTopLevelDomain(ctx sdk.Context, name string) (topLevelDomain types.TopLevelDomain, err error) { +func (k Keeper) GetValidTopLevelDomain(goCtx context.Context, name string) (topLevelDomain types.TopLevelDomain, err error) { // Regex validation err = types.ValidateTopLevelDomainName(name) if err != nil { @@ -91,12 +92,13 @@ func (k Keeper) GetValidTopLevelDomain(ctx sdk.Context, name string) (topLevelDo } // Get top level domain - topLevelDomain, found := k.GetTopLevelDomain(ctx, name) + topLevelDomain, found := k.GetTopLevelDomain(goCtx, name) if !found { return topLevelDomain, errorsmod.Wrapf(types.ErrTopLevelDomainNotFound, "%s", name) } // Check if domain is not expired + ctx := sdk.UnwrapSDKContext(goCtx) if ctx.BlockTime().After(topLevelDomain.ExpirationDate) && topLevelDomain.ExpirationDate != (time.Time{}) { return topLevelDomain, errorsmod.Wrapf(types.ErrTopLevelDomainExpired, "%s", name) } @@ -105,8 +107,8 @@ func (k Keeper) GetValidTopLevelDomain(ctx sdk.Context, name string) (topLevelDo } // Get Role of the domain -func (k Keeper) GetTopLevelDomainRole(ctx sdk.Context, name, address string) (role types.DomainRole, found bool) { - tld, found := k.GetTopLevelDomain(ctx, name) +func (k Keeper) GetTopLevelDomainRole(goCtx context.Context, name, address string) (role types.DomainRole, found bool) { + tld, found := k.GetTopLevelDomain(goCtx, name) if !found { return types.DomainRole_NO_ROLE, false } @@ -115,26 +117,26 @@ func (k Keeper) GetTopLevelDomainRole(ctx sdk.Context, name, address string) (ro } // Pay top-level-domain registration fee -func (k Keeper) PayTopLevelDomainFee(ctx sdk.Context, payer sdk.AccAddress, domain types.TopLevelDomain, registrationPeriodInYear uint64) (registrationFee types.TopLevelDomainFee, err error) { +func (k Keeper) PayTopLevelDomainFee(goCtx context.Context, payer sdk.AccAddress, domain types.TopLevelDomain, registrationPeriodInYear uint64) (registrationFee types.TopLevelDomainFee, err error) { // Get registration fee - registrationFee, err = k.GetTopLevelDomainFee(ctx, domain, registrationPeriodInYear) + registrationFee, err = k.GetTopLevelDomainFee(goCtx, domain, registrationPeriodInYear) if err != nil { return types.TopLevelDomainFee{}, err } // Send coins to treasury - err = k.distributionKeeper.FundCommunityPool(ctx, sdk.NewCoins(registrationFee.FeeToTreasury), payer) + err = k.distributionKeeper.FundCommunityPool(goCtx, sdk.NewCoins(registrationFee.FeeToTreasury), payer) if err != nil { return types.TopLevelDomainFee{}, err } // Send coins to furnace module - err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, payer, furnacetypes.ModuleName, sdk.NewCoins(registrationFee.FeeToBurn)) + err = k.bankKeeper.SendCoinsFromAccountToModule(goCtx, payer, furnacetypes.ModuleName, sdk.NewCoins(registrationFee.FeeToBurn)) if err != nil { return types.TopLevelDomainFee{}, err } // Store burn amount - _, err = k.furnaceKeeper.AddRegistrationFeeToBurnAmounts(ctx, registrationPeriodInYear, registrationFee.FeeToBurn) + _, err = k.furnaceKeeper.AddRegistrationFeeToBurnAmounts(goCtx, registrationPeriodInYear, registrationFee.FeeToBurn) if err != nil { return types.TopLevelDomainFee{}, err } @@ -149,14 +151,14 @@ func (k Keeper) PayTopLevelDomainFee(ctx sdk.Context, payer sdk.AccAddress, doma return registrationFee, nil } -func (k Keeper) ValidateTopLevelDomainIsRegistrable(ctx sdk.Context, topLevelDomain types.TopLevelDomain) error { +func (k Keeper) ValidateTopLevelDomainIsRegistrable(goCtx context.Context, topLevelDomain types.TopLevelDomain) error { // Validate top-level-domain err := topLevelDomain.Validate() if err != nil { return err } // Check if top-level-domain is already taken - isTaken := k.GetIsTopLevelDomainAlreadyTaken(ctx, topLevelDomain) + isTaken := k.GetIsTopLevelDomainAlreadyTaken(goCtx, topLevelDomain) if isTaken { return errorsmod.Wrapf(types.ErrTopLevelDomainAlreadyTaken, "%s", topLevelDomain.Name) } @@ -165,8 +167,9 @@ func (k Keeper) ValidateTopLevelDomainIsRegistrable(ctx sdk.Context, topLevelDom } // Register top-level-domain -func (k Keeper) RegisterTopLevelDomain(ctx sdk.Context, creator string, domainName string, registrationPeriodInYear uint64) (topLevelDomain types.TopLevelDomain, fee types.TopLevelDomainFee, err error) { +func (k Keeper) RegisterTopLevelDomain(goCtx context.Context, creator string, domainName string, registrationPeriodInYear uint64) (topLevelDomain types.TopLevelDomain, fee types.TopLevelDomainFee, err error) { // Create top-level-domain + ctx := sdk.UnwrapSDKContext(goCtx) currentTime := ctx.BlockTime() expirationDate := currentTime.AddDate(0, 0, params.OneYearInDays*int(registrationPeriodInYear)) accessControl := types.AccessControl{ @@ -183,7 +186,7 @@ func (k Keeper) RegisterTopLevelDomain(ctx sdk.Context, creator string, domainNa } // Validate top-level-domain is registrable - err = k.ValidateTopLevelDomainIsRegistrable(ctx, topLevelDomain) + err = k.ValidateTopLevelDomainIsRegistrable(goCtx, topLevelDomain) if err != nil { return types.TopLevelDomain{}, types.TopLevelDomainFee{}, err } @@ -193,27 +196,27 @@ func (k Keeper) RegisterTopLevelDomain(ctx sdk.Context, creator string, domainNa if err != nil { return types.TopLevelDomain{}, types.TopLevelDomainFee{}, err } - fee, err = k.PayTopLevelDomainFee(ctx, creatorAddress, topLevelDomain, registrationPeriodInYear) + fee, err = k.PayTopLevelDomainFee(goCtx, creatorAddress, topLevelDomain, registrationPeriodInYear) if err != nil { return types.TopLevelDomain{}, types.TopLevelDomainFee{}, err } // Set domain - k.SetTopLevelDomain(ctx, topLevelDomain) + k.SetTopLevelDomain(goCtx, topLevelDomain) // Append to owned domain - k.AppendToOwnedDomain(ctx, creator, topLevelDomain.Name, "") + k.AppendToOwnedDomain(goCtx, creator, topLevelDomain.Name, "") // Emit event - EmitRegisterTopLevelDomainEvent(ctx, topLevelDomain, fee) + EmitRegisterTopLevelDomainEvent(goCtx, topLevelDomain, fee) return topLevelDomain, fee, nil } // Extend expiration date -func (k Keeper) ExtendTopLevelDomainExpirationDate(ctx sdk.Context, creator string, domainName string, extensionPeriodInYear uint64) (topLevelDomain types.TopLevelDomain, fee types.TopLevelDomainFee, err error) { +func (k Keeper) ExtendTopLevelDomainExpirationDate(goCtx context.Context, creator string, domainName string, extensionPeriodInYear uint64) (topLevelDomain types.TopLevelDomain, fee types.TopLevelDomainFee, err error) { // Get domain - topLevelDomain, found := k.GetTopLevelDomain(ctx, domainName) + topLevelDomain, found := k.GetTopLevelDomain(goCtx, domainName) if !found { return types.TopLevelDomain{}, types.TopLevelDomainFee{}, errorsmod.Wrapf(types.ErrTopLevelDomainNotFound, "%s", domainName) } @@ -235,24 +238,24 @@ func (k Keeper) ExtendTopLevelDomainExpirationDate(ctx sdk.Context, creator stri } // Pay TLD extend fee - fee, err = k.PayTopLevelDomainFee(ctx, creatorAddress, topLevelDomain, extensionPeriodInYear) + fee, err = k.PayTopLevelDomainFee(goCtx, creatorAddress, topLevelDomain, extensionPeriodInYear) if err != nil { return types.TopLevelDomain{}, types.TopLevelDomainFee{}, err } // Update domain store topLevelDomain.ExtendExpirationDate(topLevelDomain.ExpirationDate, extensionPeriodInYear) - k.SetTopLevelDomain(ctx, topLevelDomain) + k.SetTopLevelDomain(goCtx, topLevelDomain) // Emit event - EmitExtendTopLevelDomainExpirationDateEvent(ctx, topLevelDomain, fee) + EmitExtendTopLevelDomainExpirationDateEvent(goCtx, topLevelDomain, fee) return topLevelDomain, fee, err } -func (k Keeper) UpdateTopLevelDomainRegistrationPolicy(ctx sdk.Context, creator string, domainName string, registrationPolicy string) (err error) { +func (k Keeper) UpdateTopLevelDomainRegistrationPolicy(goCtx context.Context, creator string, domainName string, registrationPolicy string) (err error) { // Get domain - topLevelDomain, found := k.GetTopLevelDomain(ctx, domainName) + topLevelDomain, found := k.GetTopLevelDomain(goCtx, domainName) if !found { return errorsmod.Wrapf(types.ErrTopLevelDomainNotFound, "%s", domainName) } @@ -271,10 +274,10 @@ func (k Keeper) UpdateTopLevelDomainRegistrationPolicy(ctx sdk.Context, creator // Update domain store topLevelDomain.UpdateRegistrationPolicy(rp) - k.SetTopLevelDomain(ctx, topLevelDomain) + k.SetTopLevelDomain(goCtx, topLevelDomain) // Emit event - EmitUpdateTopLevelDomainRegistrationPolicyEvent(ctx, topLevelDomain) + EmitUpdateTopLevelDomainRegistrationPolicyEvent(goCtx, topLevelDomain) return nil } diff --git a/x/registry/keeper/top_level_domain_fee.go b/x/registry/keeper/top_level_domain_fee.go index af456c25..2c7408f7 100644 --- a/x/registry/keeper/top_level_domain_fee.go +++ b/x/registry/keeper/top_level_domain_fee.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "cosmossdk.io/math" @@ -12,22 +13,22 @@ import ( ) // Get burn weight -func (k Keeper) GetBurnWeight(ctx sdk.Context) (weight math.LegacyDec, err error) { +func (k Keeper) GetBurnWeight(goCtx context.Context) (weight math.LegacyDec, err error) { // TODO: Get inflation from minter - // minter, err := k.mintKeeper.Minter.Get(ctx) + // minter, err := k.mintKeeper.Minter.Get(goCtx) // if err != nil { // return math.LegacyDec{}, err // } // inflation := minter.Inflation inflation := math.LegacyMustNewDecFromStr(fmt.Sprintf("%f", 0.20)) - bondedRatio, err := k.mintKeeper.BondedRatio(ctx) + bondedRatio, err := k.mintKeeper.BondedRatio(goCtx) if err != nil { return math.LegacyDec{}, err } // TODO: Get alpha from params - mintInflationRatio := k.GetParams(ctx).StakingInflationRatio + mintInflationRatio := k.GetParams(goCtx).StakingInflationRatio alpha := math.LegacyMustNewDecFromStr(fmt.Sprintf("%f", mintInflationRatio)) w1 := alpha.Mul(bondedRatio) @@ -37,12 +38,12 @@ func (k Keeper) GetBurnWeight(ctx sdk.Context) (weight math.LegacyDec, err error } // Get top-level-domain fee -func (k Keeper) GetTopLevelDomainFee(ctx sdk.Context, topLevelDomain types.TopLevelDomain, registrationPeriodInYear uint64) (topLevelDomainFee types.TopLevelDomainFee, err error) { +func (k Keeper) GetTopLevelDomainFee(goCtx context.Context, topLevelDomain types.TopLevelDomain, registrationPeriodInYear uint64) (topLevelDomainFee types.TopLevelDomainFee, err error) { // TODO: Support other denoms denom := params.DefaultBondDenom // Get base fee - baseFeeInUsd := k.GetParams(ctx).TopLevelDomainBaseFeeInUsd + baseFeeInUsd := k.GetParams(goCtx).TopLevelDomainBaseFeeInUsd if baseFeeInUsd == 0 { panic("base fee is not set") } @@ -55,7 +56,7 @@ func (k Keeper) GetTopLevelDomainFee(ctx sdk.Context, topLevelDomain types.TopLe topLevelDomainFee.TotalFee = sdk.NewCoins(sdk.NewCoin(denom, fee)) // Get burn weight (=W) - weight, err := k.GetBurnWeight(ctx) + weight, err := k.GetBurnWeight(goCtx) if err != nil { return types.TopLevelDomainFee{}, err } diff --git a/x/registry/keeper/top_level_domain_test.go b/x/registry/keeper/top_level_domain_test.go index 0e06fab2..2e76e09e 100644 --- a/x/registry/keeper/top_level_domain_test.go +++ b/x/registry/keeper/top_level_domain_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "fmt" "strconv" "testing" @@ -10,8 +11,6 @@ import ( errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/mycel-domain/mycel/testutil" keepertest "github.com/mycel-domain/mycel/testutil/keeper" "github.com/mycel-domain/mycel/testutil/nullify" @@ -22,7 +21,7 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize -func createNTopLevelDomain(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.TopLevelDomain { +func createNTopLevelDomain(keeper *keeper.Keeper, ctx context.Context, n int) []types.TopLevelDomain { items := make([]types.TopLevelDomain, n) for i := range items { items[i].Name = strconv.Itoa(i) @@ -35,7 +34,7 @@ func createNTopLevelDomain(keeper *keeper.Keeper, ctx sdk.Context, n int) []type // Register top-level domains with k.RegisterTopLevelDomain() // Domain name is set to `celn` (n is a incremantal number) // e.g.) `cel1`, `cel2`, `celn`... -func registerNTopLevelDomain(k *keeper.Keeper, ctx sdk.Context, creatorAddr string, n int) ([]types.TopLevelDomain, error) { +func registerNTopLevelDomain(k *keeper.Keeper, ctx context.Context, creatorAddr string, n int) ([]types.TopLevelDomain, error) { items := make([]types.TopLevelDomain, n) for i := range items { name := "cel" + strconv.Itoa(i) diff --git a/x/registry/types/expected_keepers.go b/x/registry/types/expected_keepers.go index 8ecc0c5f..194e8ad2 100644 --- a/x/registry/types/expected_keepers.go +++ b/x/registry/types/expected_keepers.go @@ -30,7 +30,7 @@ type BankKeeper interface { } type FurnaceKeeper interface { - AddRegistrationFeeToBurnAmounts(ctx sdk.Context, registrationPeriodInYear uint64, amount sdk.Coin) (burnAmounts []furnacetypes.BurnAmount, err error) + AddRegistrationFeeToBurnAmounts(ctx context.Context, registrationPeriodInYear uint64, amount sdk.Coin) (burnAmounts []furnacetypes.BurnAmount, err error) } type MintKeeper interface {