github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/keeper/proposal_handler_distr_proposal.go (about) 1 package keeper 2 3 import ( 4 "fmt" 5 6 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 7 "github.com/fibonacci-chain/fbc/x/distribution/types" 8 stakingexported "github.com/fibonacci-chain/fbc/x/staking/exported" 9 ) 10 11 // HandleChangeDistributionTypeProposal is a handler for executing a passed change distribution type proposal 12 func HandleChangeDistributionTypeProposal(ctx sdk.Context, k Keeper, p types.ChangeDistributionTypeProposal) error { 13 logger := k.Logger(ctx) 14 15 //1.check if it's the same 16 if k.GetDistributionType(ctx) == p.Type { 17 logger.Debug(fmt.Sprintf("do nothing, same distribution type, %d", p.Type)) 18 return nil 19 } 20 21 //2. if on chain, iteration validators and init val which has not outstanding 22 if p.Type == types.DistributionTypeOnChain && !k.CheckInitExistedValidatorFlag(ctx) { 23 k.SetInitExistedValidatorFlag(ctx, true) 24 k.stakingKeeper.IterateValidators(ctx, func(index int64, validator stakingexported.ValidatorI) (stop bool) { 25 if validator != nil { 26 k.initExistedValidatorForDistrProposal(ctx, validator) 27 } 28 return false 29 }) 30 } 31 32 //3. set it 33 k.SetDistributionType(ctx, p.Type) 34 35 return nil 36 } 37 38 // HandleWithdrawRewardEnabledProposal is a handler for executing a passed set withdraw reward enabled proposal 39 func HandleWithdrawRewardEnabledProposal(ctx sdk.Context, k Keeper, p types.WithdrawRewardEnabledProposal) error { 40 logger := k.Logger(ctx) 41 logger.Debug(fmt.Sprintf("set withdraw reward enabled:%t", p.Enabled)) 42 k.SetWithdrawRewardEnabled(ctx, p.Enabled) 43 return nil 44 } 45 46 // HandleRewardTruncatePrecisionProposal is a handler for executing a passed reward truncate precision proposal 47 func HandleRewardTruncatePrecisionProposal(ctx sdk.Context, k Keeper, p types.RewardTruncatePrecisionProposal) error { 48 logger := k.Logger(ctx) 49 logger.Debug(fmt.Sprintf("set reward truncate retain precision :%d", p.Precision)) 50 k.SetRewardTruncatePrecision(ctx, p.Precision) 51 return nil 52 }