Skip to content

Commit

Permalink
sdk.context -> context.context
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Feb 28, 2024
1 parent 8a64606 commit 3d6688a
Show file tree
Hide file tree
Showing 27 changed files with 208 additions and 185 deletions.
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions app/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
23 changes: 12 additions & 11 deletions x/epochs/keeper/epoch_info.go
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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{})
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion x/epochs/keeper/epoch_info_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"context"
"strconv"
"testing"

Expand All @@ -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)
Expand Down
42 changes: 22 additions & 20 deletions x/furnace/keeper/burn_amount.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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"
"github.com/mycel-domain/mycel/x/furnace/types"
)

// 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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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{})

Expand All @@ -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)
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion x/furnace/keeper/burn_amount_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"context"
"fmt"
"strconv"
"testing"
Expand All @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions x/furnace/keeper/epoch_burn_config.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
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)
store.Set([]byte{0}, b)
}

// 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})
Expand All @@ -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})
Expand Down
5 changes: 2 additions & 3 deletions x/furnace/keeper/epoch_burn_config_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions x/furnace/keeper/events.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package keeper

import (
"context"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"

"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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions x/furnace/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/cosmos/cosmos-sdk/runtime"

"github.com/mycel-domain/mycel/x/furnace/types"
)

Expand Down
Loading

0 comments on commit 3d6688a

Please sign in to comment.