Skip to content

Commit

Permalink
Added custommint keeper
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Sep 20, 2021
1 parent d3240e8 commit d912ba9
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
11 changes: 11 additions & 0 deletions x/mint/expected/keeper.go
Original file line number Diff line number Diff line change
@@ -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)
}
14 changes: 14 additions & 0 deletions x/mint/keeper/alias.go
Original file line number Diff line number Diff line change
@@ -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)
}
83 changes: 83 additions & 0 deletions x/mint/keeper/inflation.go
Original file line number Diff line number Diff line change
@@ -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++
}
}
32 changes: 32 additions & 0 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d912ba9

Please sign in to comment.