mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25:47 +00:00
feat: add validator PoP reward calculation between distributions
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
390aefa002
commit
4f80793fcd
@ -49,7 +49,10 @@ func (k Keeper) ComputeDistribution(ctx sdk.Context, lastReissuance int64, block
|
||||
distribution.PopAddr = k.GetParams(ctx).DistributionAddressPop
|
||||
|
||||
// PoP rewards subtracted from DaoAmount and added to PoPAmount for later distribution
|
||||
validatorPoPRewards := k.GetValidatorPoPReward(ctx)
|
||||
validatorPoPRewards, err := k.accumulateValidatorPoPRewardsForDistribution(ctx, lastReissuance, blockHeight)
|
||||
if err != nil {
|
||||
util.GetAppLogger().Error(ctx, "error calculating Validator PoP rewards from height %v to %v", lastReissuance, blockHeight)
|
||||
}
|
||||
|
||||
distribution.DaoAmount = util.UintValueToRDDLTokenString(uint64(float64(amount)*types.PercentageDao) - validatorPoPRewards)
|
||||
distribution.EarlyInvAmount = util.UintValueToRDDLTokenString(uint64(float64(amount) * types.PercentageEarlyInvestor))
|
||||
@ -60,6 +63,20 @@ func (k Keeper) ComputeDistribution(ctx sdk.Context, lastReissuance int64, block
|
||||
return distribution
|
||||
}
|
||||
|
||||
func (k Keeper) accumulateValidatorPoPRewardsForDistribution(ctx sdk.Context, firstPop int64, lastPop int64) (amount uint64, err error) {
|
||||
challenges, err := k.GetChallengeRange(ctx, firstPop, lastPop)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for _, challenge := range challenges {
|
||||
reward, found := k.getChallengeInitiatorReward(ctx, challenge.GetHeight())
|
||||
if found {
|
||||
amount += reward
|
||||
}
|
||||
}
|
||||
return amount, nil
|
||||
}
|
||||
|
||||
func getUint64FromTxString(ctx sdk.Context, tx string) (amount uint64, err error) {
|
||||
subStrings := strings.Split(tx, " ")
|
||||
if len(subStrings) < 3 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user