2020-09-08 16:15:08 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package estimatedpayout
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EstimatedPayout contains usage and estimated payout data for current and previous months.
|
|
|
|
type EstimatedPayout struct {
|
|
|
|
CurrentMonth PayoutMonthly `json:"currentMonth"`
|
|
|
|
PreviousMonth PayoutMonthly `json:"previousMonth"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PayoutMonthly contains usage and estimated payout date.
|
|
|
|
type PayoutMonthly struct {
|
|
|
|
EgressBandwidth int64 `json:"egressBandwidth"`
|
2020-09-30 17:02:29 +01:00
|
|
|
EgressBandwidthPayout float64 `json:"egressBandwidthPayout"`
|
2020-09-08 16:15:08 +01:00
|
|
|
EgressRepairAudit int64 `json:"egressRepairAudit"`
|
2020-09-30 17:02:29 +01:00
|
|
|
EgressRepairAuditPayout float64 `json:"egressRepairAuditPayout"`
|
2020-09-08 16:15:08 +01:00
|
|
|
DiskSpace float64 `json:"diskSpace"`
|
2020-09-30 17:02:29 +01:00
|
|
|
DiskSpacePayout float64 `json:"diskSpacePayout"`
|
2020-09-04 13:05:13 +01:00
|
|
|
HeldRate float64 `json:"heldRate"`
|
2020-09-30 17:02:29 +01:00
|
|
|
Payout float64 `json:"payout"`
|
|
|
|
Held float64 `json:"held"`
|
2020-09-08 16:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetEgressBandwidthPayout counts egress bandwidth payout for PayoutMonthly object.
|
|
|
|
func (pm *PayoutMonthly) SetEgressBandwidthPayout(egressPrice int64) {
|
2020-09-30 17:02:29 +01:00
|
|
|
amount := float64(pm.EgressBandwidth*egressPrice) / math.Pow10(12)
|
|
|
|
pm.EgressBandwidthPayout += RoundFloat(amount)
|
2020-09-08 16:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetEgressRepairAuditPayout counts audit and repair payout for PayoutMonthly object.
|
|
|
|
func (pm *PayoutMonthly) SetEgressRepairAuditPayout(auditRepairPrice int64) {
|
2020-09-30 17:02:29 +01:00
|
|
|
amount := float64(pm.EgressRepairAudit*auditRepairPrice) / math.Pow10(12)
|
|
|
|
pm.EgressRepairAuditPayout += RoundFloat(amount)
|
2020-09-08 16:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetDiskSpacePayout counts disk space payout for PayoutMonthly object.
|
|
|
|
func (pm *PayoutMonthly) SetDiskSpacePayout(diskSpacePrice int64) {
|
2020-09-30 17:02:29 +01:00
|
|
|
amount := pm.DiskSpace * float64(diskSpacePrice) / math.Pow10(12)
|
|
|
|
pm.DiskSpacePayout += RoundFloat(amount)
|
2020-09-08 16:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetHeldAmount counts held amount for PayoutMonthly object.
|
|
|
|
func (pm *PayoutMonthly) SetHeldAmount() {
|
2020-09-04 13:05:13 +01:00
|
|
|
amount := (pm.DiskSpacePayout + pm.EgressBandwidthPayout + pm.EgressRepairAuditPayout) * pm.HeldRate / 100
|
2020-09-30 17:02:29 +01:00
|
|
|
pm.Held = RoundFloat(amount)
|
2020-09-08 16:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetPayout counts payout amount for PayoutMonthly object.
|
|
|
|
func (pm *PayoutMonthly) SetPayout() {
|
2020-09-30 17:02:29 +01:00
|
|
|
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
|
2020-09-08 16:15:08 +01:00
|
|
|
}
|