github.com/cosmos/cosmos-sdk@v0.50.10/x/mint/types/genesis.go (about)

     1  package types
     2  
     3  import (
     4  	context "context"
     5  
     6  	"cosmossdk.io/math"
     7  )
     8  
     9  // InflationCalculationFn defines the function required to calculate inflation rate during
    10  // BeginBlock. It receives the minter and params stored in the keeper, along with the current
    11  // bondedRatio and returns the newly calculated inflation rate.
    12  // It can be used to specify a custom inflation calculation logic, instead of relying on the
    13  // default logic provided by the sdk.
    14  type InflationCalculationFn func(ctx context.Context, minter Minter, params Params, bondedRatio math.LegacyDec) math.LegacyDec
    15  
    16  // DefaultInflationCalculationFn is the default function used to calculate inflation.
    17  func DefaultInflationCalculationFn(_ context.Context, minter Minter, params Params, bondedRatio math.LegacyDec) math.LegacyDec {
    18  	return minter.NextInflationRate(params, bondedRatio)
    19  }
    20  
    21  // NewGenesisState creates a new GenesisState object
    22  func NewGenesisState(minter Minter, params Params) *GenesisState {
    23  	return &GenesisState{
    24  		Minter: minter,
    25  		Params: params,
    26  	}
    27  }
    28  
    29  // DefaultGenesisState creates a default GenesisState object
    30  func DefaultGenesisState() *GenesisState {
    31  	return &GenesisState{
    32  		Minter: DefaultInitialMinter(),
    33  		Params: DefaultParams(),
    34  	}
    35  }
    36  
    37  // ValidateGenesis validates the provided genesis state to ensure the
    38  // expected invariants holds.
    39  func ValidateGenesis(data GenesisState) error {
    40  	if err := data.Params.Validate(); err != nil {
    41  		return err
    42  	}
    43  
    44  	return ValidateMinter(data.Minter)
    45  }