-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3240e8
commit d912ba9
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |