storagenode/payout: estimation payout values switched from int64 to float64 to avoid incorrect rounding.

float64 values rounding to 2nd sign after dot.

Change-Id: Ice49f6a0944231ea6adb3343545bf1a62ff6dbc1
This commit is contained in:
Qweder93 2020-09-30 19:02:29 +03:00 committed by Nikolai Siedov
parent f13084983d
commit 664b8f6821

View File

@ -16,37 +16,47 @@ type EstimatedPayout struct {
// PayoutMonthly contains usage and estimated payout date.
type PayoutMonthly struct {
EgressBandwidth int64 `json:"egressBandwidth"`
EgressBandwidthPayout int64 `json:"egressBandwidthPayout"`
EgressBandwidthPayout float64 `json:"egressBandwidthPayout"`
EgressRepairAudit int64 `json:"egressRepairAudit"`
EgressRepairAuditPayout int64 `json:"egressRepairAuditPayout"`
EgressRepairAuditPayout float64 `json:"egressRepairAuditPayout"`
DiskSpace float64 `json:"diskSpace"`
DiskSpacePayout int64 `json:"diskSpacePayout"`
DiskSpacePayout float64 `json:"diskSpacePayout"`
HeldRate int64 `json:"heldRate"`
Payout int64 `json:"payout"`
Held int64 `json:"held"`
Payout float64 `json:"payout"`
Held float64 `json:"held"`
}
// SetEgressBandwidthPayout counts egress bandwidth payout for PayoutMonthly object.
func (pm *PayoutMonthly) SetEgressBandwidthPayout(egressPrice int64) {
pm.EgressBandwidthPayout += int64(float64(pm.EgressBandwidth*egressPrice) / math.Pow10(12))
amount := float64(pm.EgressBandwidth*egressPrice) / math.Pow10(12)
pm.EgressBandwidthPayout += RoundFloat(amount)
}
// SetEgressRepairAuditPayout counts audit and repair payout for PayoutMonthly object.
func (pm *PayoutMonthly) SetEgressRepairAuditPayout(auditRepairPrice int64) {
pm.EgressRepairAuditPayout += int64(float64(pm.EgressRepairAudit*auditRepairPrice) / math.Pow10(12))
amount := float64(pm.EgressRepairAudit*auditRepairPrice) / math.Pow10(12)
pm.EgressRepairAuditPayout += RoundFloat(amount)
}
// SetDiskSpacePayout counts disk space payout for PayoutMonthly object.
func (pm *PayoutMonthly) SetDiskSpacePayout(diskSpacePrice int64) {
pm.DiskSpacePayout += int64(pm.DiskSpace * float64(diskSpacePrice) / math.Pow10(12))
amount := pm.DiskSpace * float64(diskSpacePrice) / math.Pow10(12)
pm.DiskSpacePayout += RoundFloat(amount)
}
// SetHeldAmount counts held amount for PayoutMonthly object.
func (pm *PayoutMonthly) SetHeldAmount() {
pm.Held = (pm.DiskSpacePayout + pm.EgressBandwidthPayout + pm.EgressRepairAuditPayout) * pm.HeldRate / 100
amount := (pm.DiskSpacePayout + pm.EgressBandwidthPayout + pm.EgressRepairAuditPayout) * float64(pm.HeldRate/100)
pm.Held = RoundFloat(amount)
}
// SetPayout counts payout amount for PayoutMonthly object.
func (pm *PayoutMonthly) SetPayout() {
pm.Payout = pm.DiskSpacePayout + pm.EgressBandwidthPayout + pm.EgressRepairAuditPayout - pm.Held
amount := pm.DiskSpacePayout + pm.EgressBandwidthPayout + pm.EgressRepairAuditPayout - pm.Held
pm.Payout = RoundFloat(amount)
}
// RoundFloat rounds float value till 2 signs after dot.
func RoundFloat(value float64) float64 {
return math.Round(value*100) / 100
}