github.com/cosmos/cosmos-sdk@v0.50.10/x/staking/keeper/params.go (about)

     1  package keeper
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"cosmossdk.io/math"
     8  
     9  	sdk "github.com/cosmos/cosmos-sdk/types"
    10  	"github.com/cosmos/cosmos-sdk/x/staking/types"
    11  )
    12  
    13  // UnbondingTime - The time duration for unbonding
    14  func (k Keeper) UnbondingTime(ctx context.Context) (time.Duration, error) {
    15  	params, err := k.GetParams(ctx)
    16  	return params.UnbondingTime, err
    17  }
    18  
    19  // MaxValidators - Maximum number of validators
    20  func (k Keeper) MaxValidators(ctx context.Context) (uint32, error) {
    21  	params, err := k.GetParams(ctx)
    22  	return params.MaxValidators, err
    23  }
    24  
    25  // MaxEntries - Maximum number of simultaneous unbonding
    26  // delegations or redelegations (per pair/trio)
    27  func (k Keeper) MaxEntries(ctx context.Context) (uint32, error) {
    28  	params, err := k.GetParams(ctx)
    29  	return params.MaxEntries, err
    30  }
    31  
    32  // HistoricalEntries = number of historical info entries
    33  // to persist in store
    34  func (k Keeper) HistoricalEntries(ctx context.Context) (uint32, error) {
    35  	params, err := k.GetParams(ctx)
    36  	return params.HistoricalEntries, err
    37  }
    38  
    39  // BondDenom - Bondable coin denomination
    40  func (k Keeper) BondDenom(ctx context.Context) (string, error) {
    41  	params, err := k.GetParams(ctx)
    42  	return params.BondDenom, err
    43  }
    44  
    45  // PowerReduction - is the amount of staking tokens required for 1 unit of consensus-engine power.
    46  // Currently, this returns a global variable that the app developer can tweak.
    47  // TODO: we might turn this into an on-chain param:
    48  // https://github.com/cosmos/cosmos-sdk/issues/8365
    49  func (k Keeper) PowerReduction(ctx context.Context) math.Int {
    50  	return sdk.DefaultPowerReduction
    51  }
    52  
    53  // MinCommissionRate - Minimum validator commission rate
    54  func (k Keeper) MinCommissionRate(ctx context.Context) (math.LegacyDec, error) {
    55  	params, err := k.GetParams(ctx)
    56  	return params.MinCommissionRate, err
    57  }
    58  
    59  // SetParams sets the x/staking module parameters.
    60  // CONTRACT: This method performs no validation of the parameters.
    61  func (k Keeper) SetParams(ctx context.Context, params types.Params) error {
    62  	store := k.storeService.OpenKVStore(ctx)
    63  	bz, err := k.cdc.Marshal(&params)
    64  	if err != nil {
    65  		return err
    66  	}
    67  	return store.Set(types.ParamsKey, bz)
    68  }
    69  
    70  // GetParams gets the x/staking module parameters.
    71  func (k Keeper) GetParams(ctx context.Context) (params types.Params, err error) {
    72  	store := k.storeService.OpenKVStore(ctx)
    73  	bz, err := store.Get(types.ParamsKey)
    74  	if err != nil {
    75  		return params, err
    76  	}
    77  
    78  	if bz == nil {
    79  		return params, nil
    80  	}
    81  
    82  	err = k.cdc.Unmarshal(bz, &params)
    83  	return params, err
    84  }