Skip to content

Commit

Permalink
fix ci somehow
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Dec 18, 2024
1 parent 4188dda commit 3390b83
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 36 deletions.
13 changes: 11 additions & 2 deletions x/auction/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import (

// Loads module state from genesis
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
err := k.SetParams(ctx, genState.Params)
if err != nil {
panic(err)
}

for _, auction := range genState.Auctions {
if err := k.SetAuction(ctx, &auction); err != nil {
panic(err)
Expand All @@ -18,8 +22,13 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {

// Export's module state into genesis file
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params, err := k.GetParams(ctx)
if err != nil {
panic(err)
}

genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.Params = params
genesis.Auctions = k.GetAllAuctions(ctx)
return genesis
}
4 changes: 2 additions & 2 deletions x/auction/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
)

type Keeper struct {
cdc codec.BinaryCodec
cdc codec.Codec
storeKey storetypes.StoreKey
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
icqoracleKeeper types.IcqOracleKeeper
}

func NewKeeper(
cdc codec.BinaryCodec,
cdc codec.Codec,
storeKey storetypes.StoreKey,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
Expand Down
24 changes: 13 additions & 11 deletions x/auction/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import (
"github.com/Stride-Labs/stride/v24/x/auction/types"
)

// Writes params to the store
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
// GetParams get params
func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) {
store := ctx.KVStore(k.storeKey)
paramsBz := k.cdc.MustMarshal(&params)
store.Set([]byte(types.ParamsPrefix), paramsBz)
bz := store.Get([]byte(types.ParamsKey))
params := types.Params{}
err := k.cdc.UnmarshalJSON(bz, &params)
return params, err
}

// Retrieves the module parameters
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
// SetParams set params
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
store := ctx.KVStore(k.storeKey)
paramsBz := store.Get([]byte(types.ParamsPrefix))
if len(paramsBz) == 0 {
panic("module parameters not set")
bz, err := k.cdc.MarshalJSON(&params)
if err != nil {
return err
}
k.cdc.MustUnmarshal(paramsBz, &params)
return params
store.Set([]byte(types.ParamsKey), bz)
return nil
}
2 changes: 1 addition & 1 deletion x/auction/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
// RouterKey defines the routing key
RouterKey = ModuleName

ParamsPrefix = "params"
ParamsKey = "params"
KeyAuctionPrefix = "auction"
)

Expand Down
8 changes: 7 additions & 1 deletion x/icqoracle/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import (

func (k Keeper) BeginBlocker(ctx sdk.Context) {
// Get all token prices
params := k.GetParams(ctx)
params, err := k.GetParams(ctx)
if err != nil {
// Can't really do anything but log
// A panic would halt the chain
ctx.Logger().Error("failed to get icqoracle params: %w", err)
return
}

currentTime := ctx.BlockTime()

Expand Down
13 changes: 11 additions & 2 deletions x/icqoracle/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (

// Loads module state from genesis
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
err := k.SetParams(ctx, genState.Params)
if err != nil {
panic(err)
}

for _, tokenPrice := range genState.TokenPrices {
tokenPrice.SpotPrice = math.LegacyZeroDec()
tokenPrice.UpdatedAt = time.Time{}
Expand All @@ -25,8 +29,13 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {

// Export's module state into genesis file
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params, err := k.GetParams(ctx)
if err != nil {
panic(err)
}

genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.Params = params
genesis.TokenPrices = k.GetAllTokenPrices(ctx)
return genesis
}
6 changes: 5 additions & 1 deletion x/icqoracle/keeper/icq.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func (k Keeper) SubmitOsmosisClPoolICQ(
) error {
k.Logger(ctx).Info(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Submitting OsmosisClPool ICQ"))

params := k.GetParams(ctx)
params, err := k.GetParams(ctx)
if err != nil {
k.Logger(ctx).Error(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Error getting module params: %s", err.Error()))
return err
}

osmosisPoolId, err := strconv.ParseUint(tokenPrice.OsmosisPoolId, 10, 64)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions x/icqoracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
)

type Keeper struct {
cdc codec.BinaryCodec
cdc codec.Codec
storeKey storetypes.StoreKey
icqKeeper interchainquerykeeper.Keeper
}

func NewKeeper(
cdc codec.BinaryCodec,
cdc codec.Codec,
storeKey storetypes.StoreKey,
) *Keeper {
return &Keeper{
Expand Down Expand Up @@ -154,7 +154,11 @@ func (k Keeper) GetTokenPriceForQuoteDenom(ctx sdk.Context, baseDenom string, qu
}

// Get price expiration timeout
priceExpirationTimeoutSec := int64(k.GetParams(ctx).PriceExpirationTimeoutSec)
params, err := k.GetParams(ctx)
if err != nil {
return math.LegacyDec{}, fmt.Errorf("error getting params: %w", err)
}
priceExpirationTimeoutSec := int64(params.PriceExpirationTimeoutSec)

// Init price
price = math.LegacyZeroDec()
Expand Down
24 changes: 13 additions & 11 deletions x/icqoracle/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import (
"github.com/Stride-Labs/stride/v24/x/icqoracle/types"
)

// Writes params to the store
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
// GetParams get params
func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) {
store := ctx.KVStore(k.storeKey)
paramsBz := k.cdc.MustMarshal(&params)
store.Set([]byte(types.ParamsPrefix), paramsBz)
bz := store.Get([]byte(types.ParamsKey))
params := types.Params{}
err := k.cdc.UnmarshalJSON(bz, &params)
return params, err
}

// Retrieves the module parameters
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
// SetParams set params
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
store := ctx.KVStore(k.storeKey)
paramsBz := store.Get([]byte(types.ParamsPrefix))
if len(paramsBz) == 0 {
panic("module parameters not set")
bz, err := k.cdc.MarshalJSON(&params)
if err != nil {
return err
}
k.cdc.MustUnmarshal(paramsBz, &params)
return params
store.Set([]byte(types.ParamsKey), bz)
return nil
}
5 changes: 4 additions & 1 deletion x/icqoracle/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*t

ctx := sdk.UnwrapSDKContext(goCtx)

params := k.GetParams(ctx)
params, err := k.GetParams(ctx)
if err != nil {
return nil, err
}

return &types.QueryParamsResponse{
Params: params,
Expand Down
2 changes: 1 addition & 1 deletion x/icqoracle/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
// RouterKey defines the routing key
RouterKey = ModuleName

ParamsPrefix = "params"
ParamsKey = "params"
KeyPricePrefix = "price"
)

Expand Down

0 comments on commit 3390b83

Please sign in to comment.