storagenode/payouts: payoutHistoryMonthly surge reworked, empty receipt now won't return error

Change-Id: If99f8aec102550cd30e5906f986a4417903100be
This commit is contained in:
Qweder93 2020-09-14 17:40:52 +03:00
parent 5b9fd4e50a
commit 528aa76ae6
2 changed files with 18 additions and 11 deletions

View File

@ -80,3 +80,16 @@ type Payment struct {
Receipt string `json:"receipt"`
Notes string `json:"notes"`
}
// GetEarnedWithSurge returns paystub's total earned and surge.
func (paystub *PayStub) GetEarnedWithSurge() (earned int64, surge int64) {
earned = paystub.CompGetAudit + paystub.CompGet + paystub.CompGetRepair + paystub.CompAtRest
surge = earned * paystub.SurgePercent / 100
return earned, surge
}
// UsageAtRestTbM converts paystub's usage_at_rest from tbh to tbm.
func (paystub *PayStub) UsageAtRestTbM() {
paystub.UsageAtRest /= 720
}

View File

@ -260,10 +260,10 @@ func (service *Service) PayoutHistoryMonthly(ctx context.Context, period string)
receipt, err := service.db.GetReceipt(ctx, satelliteIDs[i], period)
if err != nil {
if ErrNoPayStubForPeriod.Has(err) {
continue
if !ErrNoPayStubForPeriod.Has(err) {
return nil, ErrHeldAmountService.Wrap(err)
}
return nil, ErrHeldAmountService.Wrap(err)
receipt = "no receipt for this period"
}
stats, err := service.reputationDB.Get(ctx, satelliteIDs[i])
@ -293,8 +293,7 @@ func (service *Service) PayoutHistoryMonthly(ctx context.Context, period string)
paystub.SurgePercent = 100
}
surge := paystub.CompGetAudit + paystub.CompGet + paystub.CompGetRepair + paystub.CompAtRest
earned := surge / paystub.SurgePercent * 100
earned, surge := paystub.GetEarnedWithSurge()
heldPercent, err := service.getHeldRate(stats.JoinedAt, paystub.Period)
if err != nil {
@ -304,7 +303,7 @@ func (service *Service) PayoutHistoryMonthly(ctx context.Context, period string)
payoutHistory.Held = paystub.Held
payoutHistory.Receipt = receipt
payoutHistory.Surge = surge
payoutHistory.AfterHeld = surge - paystub.Held
payoutHistory.AfterHeld = payoutHistory.Surge - paystub.Held
payoutHistory.Age = int64(date.MonthsCountSince(stats.JoinedAt))
payoutHistory.Disposed = paystub.Disposed
payoutHistory.Earned = earned
@ -375,11 +374,6 @@ func parsePeriodRange(periodStart, periodEnd string) (periods []string, err erro
return periods, nil
}
// UsageAtRestTbM converts paystub's usage_at_rest from tbh to tbm.
func (paystub *PayStub) UsageAtRestTbM() {
paystub.UsageAtRest /= 720
}
func (service *Service) getHeldRate(joinedAt time.Time, period string) (heldRate int64, err error) {
layout := "2006-01-02T15:04:05.000Z"
periodTime, err := time.Parse(layout, period+"-12T11:45:26.371Z")