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