diff --git a/x/mint/expected/keeper.go b/x/mint/expected/keeper.go new file mode 100644 index 00000000..dd15ec80 --- /dev/null +++ b/x/mint/expected/keeper.go @@ -0,0 +1,11 @@ +package expected + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" +) + +type MintKeeper interface { + GetParams(ctx sdk.Context) minttypes.Params + SetParams(ctx sdk.Context, params minttypes.Params) +} diff --git a/x/mint/keeper/alias.go b/x/mint/keeper/alias.go new file mode 100644 index 00000000..4514a38f --- /dev/null +++ b/x/mint/keeper/alias.go @@ -0,0 +1,14 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" +) + +func (k *Keeper) GetParams(ctx sdk.Context) minttypes.Params { + return k.mint.GetParams(ctx) +} + +func (k *Keeper) SetParams(ctx sdk.Context, params minttypes.Params) { + k.mint.SetParams(ctx, params) +} diff --git a/x/mint/keeper/inflation.go b/x/mint/keeper/inflation.go new file mode 100644 index 00000000..b0651108 --- /dev/null +++ b/x/mint/keeper/inflation.go @@ -0,0 +1,83 @@ +package keeper + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + hubtypes "github.com/sentinel-official/hub/types" + "github.com/sentinel-official/hub/x/mint/types" +) + +func (k *Keeper) SetInflation(ctx sdk.Context, inflation types.Inflation) { + var ( + store = k.Store(ctx) + key = types.InflationKey(inflation.Timestamp) + value = k.cdc.MustMarshalBinaryBare(&inflation) + ) + + store.Set(key, value) +} + +func (k *Keeper) GetInflation(ctx sdk.Context, timestamp time.Time) (inflation types.Inflation, found bool) { + var ( + store = k.Store(ctx) + key = types.InflationKey(timestamp) + value = store.Get(key) + ) + + if value == nil { + return inflation, false + } + + k.cdc.MustUnmarshalBinaryBare(value, &inflation) + return inflation, true +} + +func (k *Keeper) DeleteInflation(ctx sdk.Context, timestamp time.Time) { + var ( + store = k.Store(ctx) + key = types.InflationKey(timestamp) + ) + + store.Delete(key) +} + +func (k *Keeper) GetInflations(ctx sdk.Context, skip, limit int64) (items []types.Inflation) { + var ( + store = k.Store(ctx) + iter = hubtypes.NewPaginatedIterator( + sdk.KVStorePrefixIterator(store, types.InflationKeyPrefix), + ) + ) + + defer iter.Close() + + iter.Skip(skip) + iter.Limit(limit, func(iter sdk.Iterator) { + var item types.Inflation + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &item) + items = append(items, item) + }) + + return items +} + +func (k *Keeper) IterateInflations(ctx sdk.Context, fn func(index int, item types.Inflation) (stop bool)) { + var ( + store = k.Store(ctx) + iter = sdk.KVStorePrefixIterator(store, types.InflationKeyPrefix) + ) + + defer iter.Close() + + for i := 0; iter.Valid(); iter.Next() { + var item types.Inflation + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &item) + + if stop := fn(i, item); stop { + break + } + i++ + } +} diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go new file mode 100644 index 00000000..a7e84aee --- /dev/null +++ b/x/mint/keeper/keeper.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/libs/log" + + "github.com/sentinel-official/hub/x/mint/expected" + "github.com/sentinel-official/hub/x/mint/types" +) + +type Keeper struct { + cdc codec.BinaryMarshaler + key sdk.StoreKey + mint expected.MintKeeper +} + +func NewKeeper(cdc codec.BinaryMarshaler, key sdk.StoreKey, mint expected.MintKeeper) Keeper { + return Keeper{ + cdc: cdc, + key: key, + mint: mint, + } +} + +func (k *Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", "x/"+types.ModuleName) +} + +func (k *Keeper) Store(ctx sdk.Context) sdk.KVStore { + return ctx.KVStore(k.key) +}