github.com/okex/exchain@v1.8.0/libs/ibc-go/testing/simapp/adapter/staking/staking.go (about)

     1  package staking
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/okex/exchain/libs/cosmos-sdk/codec"
     6  	sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
     7  	"github.com/okex/exchain/libs/cosmos-sdk/x/params"
     8  	types2 "github.com/okex/exchain/libs/cosmos-sdk/x/staking/types"
     9  	"github.com/okex/exchain/x/common"
    10  	"github.com/okex/exchain/x/staking/keeper"
    11  	"github.com/okex/exchain/x/staking/types"
    12  	"time"
    13  )
    14  
    15  type StakingKeeper struct {
    16  	keeper.Keeper
    17  }
    18  
    19  func (k StakingKeeper) UnbondingTime(ctx sdk.Context) (res time.Duration) {
    20  	return types2.DefaultUnbondingTime
    21  }
    22  
    23  // NewKeeper creates a new staking Keeper instance
    24  func NewStakingKeeper(cdcMarshl *codec.CodecProxy, key sdk.StoreKey, supplyKeeper types.SupplyKeeper,
    25  	paramstore params.Subspace) *StakingKeeper {
    26  	// set KeyTable if it has not already been set
    27  	if !paramstore.HasKeyTable() {
    28  		paramstore = paramstore.WithKeyTable(ParamKeyTable())
    29  	}
    30  	// ensure bonded and not bonded module accounts are set
    31  	if addr := supplyKeeper.GetModuleAddress(types.BondedPoolName); addr == nil {
    32  		panic(fmt.Sprintf("%s module account has not been set", types.BondedPoolName))
    33  	}
    34  
    35  	if addr := supplyKeeper.GetModuleAddress(types.NotBondedPoolName); addr == nil {
    36  		panic(fmt.Sprintf("%s module account has not been set", types.NotBondedPoolName))
    37  	}
    38  	k := keeper.NewKeeperWithNoParam(cdcMarshl, key, supplyKeeper, paramstore)
    39  	return &StakingKeeper{
    40  		Keeper: k,
    41  	}
    42  }
    43  
    44  // ParamKeyTable returns param table for staking module
    45  func ParamKeyTable() params.KeyTable {
    46  	return params.NewKeyTable().RegisterParamSet(newTestParams())
    47  }
    48  
    49  type TestParams struct {
    50  	*types.Params
    51  }
    52  
    53  func newTestParams() *TestParams {
    54  	p := types.DefaultParams()
    55  	p.UnbondingTime = types2.DefaultUnbondingTime
    56  	ret := &TestParams{
    57  		Params: &p,
    58  	}
    59  	return ret
    60  }
    61  
    62  // ParamSetPairs is the implements params.ParamSet
    63  func (p *TestParams) ParamSetPairs() params.ParamSetPairs {
    64  	return params.ParamSetPairs{
    65  		{Key: types.KeyUnbondingTime, Value: &p.UnbondingTime, ValidatorFn: common.ValidateDurationPositive("unbonding time")},
    66  		{Key: types.KeyMaxValidators, Value: &p.MaxValidators, ValidatorFn: common.ValidateUint16Positive("max validators")},
    67  		{Key: types.KeyEpoch, Value: &p.Epoch, ValidatorFn: common.ValidateUint16Positive("epoch")},
    68  		{Key: types.KeyMaxValsToAddShares, Value: &p.MaxValsToAddShares, ValidatorFn: common.ValidateUint16Positive("max vals to add shares")},
    69  		{Key: types.KeyMinDelegation, Value: &p.MinDelegation, ValidatorFn: common.ValidateDecPositive("min delegation")},
    70  		{Key: types.KeyMinSelfDelegation, Value: &p.MinSelfDelegation, ValidatorFn: common.ValidateDecPositive("min self delegation")},
    71  		{Key: types.KeyHistoricalEntries, Value: &p.HistoricalEntries, ValidatorFn: validateHistoricalEntries},
    72  	}
    73  }
    74  
    75  func validateHistoricalEntries(i interface{}) error {
    76  	_, ok := i.(uint32)
    77  	if !ok {
    78  		return fmt.Errorf("invalid parameter type: %T", i)
    79  	}
    80  
    81  	return nil
    82  }