2019-08-28 07:58:25 -07:00
|
|
|
package types
|
|
|
|
|
2021-11-08 02:56:10 -08:00
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InflationCalculationFn defines the function required to calculate inflation rate during
|
|
|
|
// BeginBlock. It receives the minter and params stored in the keeper, along with the current
|
|
|
|
// bondedRatio and returns the newly calculated inflation rate.
|
|
|
|
// It can be used to specify a custom inflation calculation logic, instead of relying on the
|
|
|
|
// default logic provided by the sdk.
|
|
|
|
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec) sdk.Dec
|
|
|
|
|
|
|
|
// DefaultInflationCalculationFn is the default function used to calculate inflation.
|
|
|
|
func DefaultInflationCalculationFn(_ sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec) sdk.Dec {
|
|
|
|
return minter.NextInflationRate(params, bondedRatio)
|
|
|
|
}
|
|
|
|
|
2019-08-28 07:58:25 -07:00
|
|
|
// NewGenesisState creates a new GenesisState object
|
2020-08-11 07:22:30 -07:00
|
|
|
func NewGenesisState(minter Minter, params Params) *GenesisState {
|
|
|
|
return &GenesisState{
|
2019-08-28 07:58:25 -07:00
|
|
|
Minter: minter,
|
|
|
|
Params: params,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultGenesisState creates a default GenesisState object
|
2020-08-11 07:22:30 -07:00
|
|
|
func DefaultGenesisState() *GenesisState {
|
|
|
|
return &GenesisState{
|
2019-08-28 07:58:25 -07:00
|
|
|
Minter: DefaultInitialMinter(),
|
|
|
|
Params: DefaultParams(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateGenesis validates the provided genesis state to ensure the
|
|
|
|
// expected invariants holds.
|
|
|
|
func ValidateGenesis(data GenesisState) error {
|
2019-12-10 08:48:57 -08:00
|
|
|
if err := data.Params.Validate(); err != nil {
|
2019-08-28 07:58:25 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ValidateMinter(data.Minter)
|
|
|
|
}
|