Documentation ¶
Index ¶
- Variables
- func NodeWithheldPercent(withheldPercents []int, nodeCreatedAt, endDate time.Time) (int, bool)
- func PercentOf(v, percent decimal.Decimal) decimal.Decimal
- func WriteInvoices(w io.Writer, invoices []Invoice) error
- func WritePayments(w io.Writer, payments []Payment) error
- type Code
- type Codes
- type Config
- type DB
- type Invoice
- type NodeID
- type NodeInfo
- type Payment
- type Paystub
- type Percents
- type Period
- type PeriodInfo
- type Rate
- type Rates
- type Statement
- type UTCDate
- type WithheldAmounts
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultWithheldPercents contains the standard withholding schedule. DefaultWithheldPercents = []int{75, 75, 75, 50, 50, 50, 25, 25, 25} // DefaultRates contains the standard operation rates. DefaultRates = Rates{ AtRestGBHours: RequireRateFromString("0.00000205"), GetTB: RequireRateFromString("20.00"), PutTB: RequireRateFromString("0.00"), GetRepairTB: RequireRateFromString("10.00"), PutRepairTB: RequireRateFromString("0.00"), GetAuditTB: RequireRateFromString("10.0"), } )
var ( // Error wraps common errors from this package Error = errs.Class("compensation") )
Functions ¶
func NodeWithheldPercent ¶
NodeWithheldPercent returns the percentage that should be withheld and if the node is still in the withholding period based on its creation date.
func PercentOf ¶
PercentOf sets v to a percentage of itself. For example if v was 200 and percent was 20, v would be set to 40.
func WriteInvoices ¶
WriteInvoices writes a collection of Invoice values in CSV form.
Types ¶
type Code ¶
type Code string
Code is an enumeration of states some billing entry could be in.
const ( // Disqualified is included if the node is disqualified. Disqualified Code = "D" // Sanctioned is included if payment is withheld because the node is in // a sanctioned country. Sanctioned Code = "S" // No1099 is included if payment is withheld because the node has not // filed a 1099 and payment would put it over limits. No1099 Code = "T" // InWithholding is included if the node is in the initial held amount // period. InWithholding Code = "E" // GracefulExit is included if the node has gracefully exited. GracefulExit Code = "X" )
func CodeFromString ¶
CodeFromString parses the string into a Code.
type Codes ¶
type Codes []Code
Codes represents a collection of Code values.
func CodesFromString ¶
CodesFromString parses the list of codes into a Codes.
func (Codes) MarshalCSV ¶
MarshalCSV does the custom marshaling of Codes.
func (*Codes) UnmarshalCSV ¶
UnmarshalCSV does the custom unmarshaling of Codes.
type Config ¶
type Config struct { Rates struct { AtRestGBHours Rate `user:"true" help:"rate for data at rest per GB/hour" default:"0.00000205"` GetTB Rate `user:"true" help:"rate for egress bandwidth per TB" default:"20.00"` PutTB Rate `user:"true" help:"rate for ingress bandwidth per TB" default:"0"` GetRepairTB Rate `user:"true" help:"rate for repair egress bandwidth per TB" default:"10.00"` PutRepairTB Rate `user:"true" help:"rate for repair ingress bandwidth per TB" default:"0"` GetAuditTB Rate `user:"true" help:"rate for audit egress bandwidth per TB" default:"10.00"` } WithheldPercents Percents `user:"true" help:"comma separated monthly withheld percentage rates" default:"75,75,75,50,50,50,25,25,25,0,0,0,0,0,0"` DisposePercent int `user:"true" help:"percent of held amount disposed to node after leaving withheld" default:"50"` }
Config contains configuration for the calculations this package performs.
type DB ¶
type DB interface { // QueryWithheldAmounts queries the WithheldAmounts for the given nodeID. QueryWithheldAmounts(ctx context.Context, nodeID storj.NodeID) (WithheldAmounts, error) // QueryPaidInYear returns the total amount paid to the nodeID in the provided year. QueryPaidInYear(ctx context.Context, nodeID storj.NodeID, year int) (currency.MicroUnit, error) // RecordPeriod records a set of paystubs and payments for some time period. RecordPeriod(ctx context.Context, paystubs []Paystub, payments []Payment) error // RecordPayments records one off individual payments. RecordPayments(ctx context.Context, payments []Payment) error }
DB is the interface we need to source the data to calculate compensation.
type Invoice ¶
type Invoice struct { Period Period `csv:"period"` // The payment period NodeID NodeID `csv:"node-id"` // The node ID NodeCreatedAt UTCDate `csv:"node-created-at"` // When the node was created NodeDisqualified *UTCDate `csv:"node-disqualified"` // When and if the node was disqualified NodeGracefulExit *UTCDate `csv:"node-gracefulexit"` // When and if the node finished a graceful exit NodeWallet string `csv:"node-wallet"` // The node's wallet address NodeAddress string `csv:"node-address"` // The node's TODO NodeLastIP string `csv:"node-last-ip"` // The last known ip the node had Codes Codes `csv:"codes"` // Any codes providing context to the invoice UsageAtRest float64 `csv:"usage-at-rest"` // Byte-hours provided during the payment period UsageGet int64 `csv:"usage-get"` // Number of bytes served in GET requests UsagePut int64 `csv:"usage-put"` // Number of bytes served in PUT requests UsageGetRepair int64 `csv:"usage-get-repair"` // Number of bytes served in GET_REPAIR requests UsagePutRepair int64 `csv:"usage-put-repair"` // Number of bytes served in PUT_REPAIR requests UsageGetAudit int64 `csv:"usage-get-audit"` // Number of bytes served in GET_AUDIT requests CompAtRest currency.MicroUnit `csv:"comp-at-rest"` // Compensation for usage-at-rest CompGet currency.MicroUnit `csv:"comp-get"` // Compensation for usage-get CompPut currency.MicroUnit `csv:"comp-put"` // Compensation for usage-put CompGetRepair currency.MicroUnit `csv:"comp-get-repair"` // Compensation for usage-get-repair CompPutRepair currency.MicroUnit `csv:"comp-put-repair"` // Compensation for usage-put-repair CompGetAudit currency.MicroUnit `csv:"comp-get-audit"` // Compensation for usage-get-audit SurgePercent int64 `csv:"surge-percent"` // Surge percent used to calculate compensation, or 0 if no surge Owed currency.MicroUnit `csv:"owed"` // Amount we intend to pay to the node (sum(comp-*) - held + disposed) Held currency.MicroUnit `csv:"held"` // Amount held from sum(comp-*) for this period Disposed currency.MicroUnit `csv:"disposed"` // Amount of owed that is due to graceful-exit or held period ending TotalHeld currency.MicroUnit `csv:"total-held"` // Total amount ever held from the node TotalDisposed currency.MicroUnit `csv:"total-disposed"` // Total amount ever disposed to the node PaidYTD currency.MicroUnit `csv:"paid-ytd"` // Total amount paid so far this year (not including this period) }
Invoice holds the calculations for the amount required to pay to a node for a given pay period.
func ReadInvoices ¶
ReadInvoices reads a collection of Invoice values in CSV form.
func (*Invoice) MergeNodeInfo ¶
MergeNodeInfo updates the fields representing the node information into the invoice.
func (*Invoice) MergeStatement ¶
MergeStatement updates the fields representing the calculation of the payment amounts into the invoice.
type NodeID ¶
NodeID is a wrapper type around storj.NodeID that implements CSV helpers.
func (NodeID) MarshalCSV ¶
MarshalCSV writes the storj.NodeID into a CSV entry.
func (*NodeID) UnmarshalCSV ¶
UnmarshalCSV reads the csv entry into a storj.NodeID.
type NodeInfo ¶
type NodeInfo struct { ID storj.NodeID CreatedAt time.Time Disqualified *time.Time GracefulExit *time.Time UsageAtRest float64 UsageGet int64 UsagePut int64 UsageGetRepair int64 UsagePutRepair int64 UsageGetAudit int64 TotalHeld currency.MicroUnit TotalDisposed currency.MicroUnit }
NodeInfo contains all of the information about a node and the operations it performed in some period.
type Payment ¶
type Payment struct { Period Period `csv:"period"` NodeID NodeID `csv:"node-id"` Amount currency.MicroUnit `csv:"amount"` Receipt *string `csv:"receipt"` Notes *string `csv:"notes"` }
Payment represents an actual payment that happened.
func LoadPayments ¶
LoadPayments loads a collection of Payments from a file on disk containing them in CSV form.
type Paystub ¶
type Paystub struct { Period Period `csv:"period"` NodeID NodeID `csv:"node-id"` Codes Codes `csv:"codes"` UsageAtRest float64 `csv:"usage-at-rest"` UsageGet int64 `csv:"usage-get"` UsagePut int64 `csv:"usage-put"` UsageGetRepair int64 `csv:"usage-get-repair"` UsagePutRepair int64 `csv:"usage-put-repair"` UsageGetAudit int64 `csv:"usage-get-audit"` CompAtRest currency.MicroUnit `csv:"comp-at-rest"` CompGet currency.MicroUnit `csv:"comp-get"` CompPut currency.MicroUnit `csv:"comp-put"` CompGetRepair currency.MicroUnit `csv:"comp-get-repair"` CompPutRepair currency.MicroUnit `csv:"comp-put-repair"` CompGetAudit currency.MicroUnit `csv:"comp-get-audit"` SurgePercent int64 `csv:"surge-percent"` Owed currency.MicroUnit `csv:"owed"` Held currency.MicroUnit `csv:"held"` Disposed currency.MicroUnit `csv:"disposed"` Paid currency.MicroUnit `csv:"paid"` }
Paystub contains the basic information about a payment that is to be made.
func LoadPaystubs ¶
LoadPaystubs loads a collection of Paystubs in CSV form from the provided file.
type Percents ¶
type Percents []int
Percents is used to hold a list of percentages, typically for the withheld schedule.
type Period ¶
Period represents a monthly payment period.
func PeriodFromString ¶
PeriodFromString parses the YYYY-MM string into a Period.
func PeriodFromTime ¶
PeriodFromTime takes a time.Time and returns a Period that contains it.
func (Period) EndDateExclusive ¶
EndDateExclusive returns a time.Time that is greater than any time in the period.
func (Period) MarshalCSV ¶
MarshalCSV returns the CSV form of the Period.
func (Period) StartDate ¶
StartDate returns a time.Time that is less than or equal to any time in the period.
func (*Period) UnmarshalCSV ¶
UnmarshalCSV reads the Period in CSV form.
type PeriodInfo ¶
type PeriodInfo struct { // Period is the period. Period Period // Nodes is usage and other related information for nodes for this period. Nodes []NodeInfo // Rates is the compensation rates for different operations. If nil, the // default rates are used. Rates *Rates // WithheldPercents is the percent to withhold from the total, after surge // adjustments, for each month in the node's lifetime. For example, to // withhold 75% in the first month, 50% in the second month, 0% in the third // month and to leave withheld thereafter, set to [75,50,0]. If nil, // DefaultWithheldPercents is used. WithheldPercents []int // DisposePercent is the percent to dispose to the node after it has left // withholding. The remaining amount is kept until the node performs a graceful // exit. DisposePercent int // SurgePercent is the percent to adjust final amounts owed. For example, // to pay 150%, set to 150. Zero means no surge. SurgePercent int64 }
PeriodInfo contains configuration about the payment info to generate the statements.
type Rate ¶
Rate is a wrapper type around a decimal.Decimal.
func RateFromString ¶
RateFromString parses the string form of the rate into a Rate.
func RequireRateFromString ¶
RequireRateFromString parses the Rate from the string or panics.
type Rates ¶
type Rates struct { AtRestGBHours Rate // For data at rest in dollars per gigabyte-hour. GetTB Rate // For data the node has sent for reads in dollars per terabyte. PutTB Rate // For data the node has received for writes in dollars per terabyte. GetRepairTB Rate // For data the node has sent for repairs in dollars per terabyte. PutRepairTB Rate // For data the node has received for repairs in dollars per terabyte. GetAuditTB Rate // For data the node has sent for audits in dollars per terabyte. }
Rates configures the payment rates for network operations.
type Statement ¶
type Statement struct { NodeID storj.NodeID Codes Codes AtRest currency.MicroUnit Get currency.MicroUnit Put currency.MicroUnit GetRepair currency.MicroUnit PutRepair currency.MicroUnit GetAudit currency.MicroUnit SurgePercent int64 Owed currency.MicroUnit Held currency.MicroUnit Disposed currency.MicroUnit }
Statement is the computed amounts and codes from a node.
func GenerateStatements ¶
func GenerateStatements(info PeriodInfo) ([]Statement, error)
GenerateStatements generates all of the Statements for the given PeriodInfo.
type UTCDate ¶
UTCDate is a wrapper type around time.Time that implements CSV helpers.
func (UTCDate) MarshalCSV ¶
MarshalCSV writes out a CSV row containing the YYYY-MM-DD of the time.
func (*UTCDate) UnmarshalCSV ¶
UnmarshalCSV reads the YYYY-MM-DD date into the date.