|
|
@ -519,7 +519,29 @@ func (hmy *Harmony) GetDelegationsByDelegatorByBlock( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UndelegationPayouts ..
|
|
|
|
// UndelegationPayouts ..
|
|
|
|
type UndelegationPayouts map[common.Address]map[common.Address]*big.Int |
|
|
|
type UndelegationPayouts struct { |
|
|
|
|
|
|
|
Data map[common.Address]map[common.Address]*big.Int |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewUndelegationPayouts() *UndelegationPayouts { |
|
|
|
|
|
|
|
return &UndelegationPayouts{ |
|
|
|
|
|
|
|
Data: make(map[common.Address]map[common.Address]*big.Int), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (u *UndelegationPayouts) SetPayoutByDelegatorAddrAndValidatorAddr( |
|
|
|
|
|
|
|
delegator, validator common.Address, amount *big.Int, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
if u.Data[delegator] == nil { |
|
|
|
|
|
|
|
u.Data[delegator] = make(map[common.Address]*big.Int) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if totalPayout, ok := u.Data[delegator][validator]; ok { |
|
|
|
|
|
|
|
u.Data[delegator][validator] = new(big.Int).Add(totalPayout, amount) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
u.Data[delegator][validator] = amount |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetUndelegationPayouts returns the undelegation payouts for each delegator
|
|
|
|
// GetUndelegationPayouts returns the undelegation payouts for each delegator
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -528,16 +550,17 @@ type UndelegationPayouts map[common.Address]map[common.Address]*big.Int |
|
|
|
// This not a problem if a full (archival) DB is used.
|
|
|
|
// This not a problem if a full (archival) DB is used.
|
|
|
|
func (hmy *Harmony) GetUndelegationPayouts( |
|
|
|
func (hmy *Harmony) GetUndelegationPayouts( |
|
|
|
ctx context.Context, epoch *big.Int, |
|
|
|
ctx context.Context, epoch *big.Int, |
|
|
|
) (UndelegationPayouts, error) { |
|
|
|
) (*UndelegationPayouts, error) { |
|
|
|
if !hmy.IsPreStakingEpoch(epoch) { |
|
|
|
if !hmy.IsPreStakingEpoch(epoch) { |
|
|
|
return nil, fmt.Errorf("not pre-staking epoch or later") |
|
|
|
return nil, fmt.Errorf("not pre-staking epoch or later") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
payouts, ok := hmy.undelegationPayoutsCache.Get(epoch.Uint64()) |
|
|
|
payouts, ok := hmy.undelegationPayoutsCache.Get(epoch.Uint64()) |
|
|
|
if ok { |
|
|
|
if ok { |
|
|
|
return payouts.(UndelegationPayouts), nil |
|
|
|
result := payouts.(UndelegationPayouts) |
|
|
|
|
|
|
|
return &result, nil |
|
|
|
} |
|
|
|
} |
|
|
|
undelegationPayouts := UndelegationPayouts{} |
|
|
|
undelegationPayouts := NewUndelegationPayouts() |
|
|
|
// require second to last block as saved undelegations are AFTER undelegations are payed out
|
|
|
|
// require second to last block as saved undelegations are AFTER undelegations are payed out
|
|
|
|
blockNumber := shard.Schedule.EpochLastBlock(epoch.Uint64()) - 1 |
|
|
|
blockNumber := shard.Schedule.EpochLastBlock(epoch.Uint64()) - 1 |
|
|
|
undelegationPayoutBlock, err := hmy.BlockByNumber(ctx, rpc.BlockNumber(blockNumber)) |
|
|
|
undelegationPayoutBlock, err := hmy.BlockByNumber(ctx, rpc.BlockNumber(blockNumber)) |
|
|
@ -556,14 +579,7 @@ func (hmy *Harmony) GetUndelegationPayouts( |
|
|
|
for _, delegation := range wrapper.Delegations { |
|
|
|
for _, delegation := range wrapper.Delegations { |
|
|
|
withdraw := delegation.RemoveUnlockedUndelegations(epoch, wrapper.LastEpochInCommittee, lockingPeriod, noEarlyUnlock) |
|
|
|
withdraw := delegation.RemoveUnlockedUndelegations(epoch, wrapper.LastEpochInCommittee, lockingPeriod, noEarlyUnlock) |
|
|
|
if withdraw.Cmp(bigZero) == 1 { |
|
|
|
if withdraw.Cmp(bigZero) == 1 { |
|
|
|
if undelegationPayouts[delegation.DelegatorAddress] == nil { |
|
|
|
undelegationPayouts.SetPayoutByDelegatorAddrAndValidatorAddr(validator, delegation.DelegatorAddress, withdraw) |
|
|
|
undelegationPayouts[delegation.DelegatorAddress] = make(map[common.Address]*big.Int) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if totalPayout, ok := undelegationPayouts[delegation.DelegatorAddress][validator]; ok { |
|
|
|
|
|
|
|
undelegationPayouts[delegation.DelegatorAddress][validator] = new(big.Int).Add(totalPayout, withdraw) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
undelegationPayouts[delegation.DelegatorAddress][validator] = withdraw |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|