From 1e328f3c30340d4b9210cda0d1e6989e5fd99833 Mon Sep 17 00:00:00 2001 From: Yaroslav Vorobiov Date: Tue, 26 Jan 2021 22:28:35 +0200 Subject: [PATCH] satellite/compensation: add wallet features to invoice csv Change-Id: I90a72c0a4c8d07604096913b6680263b6defc0a2 --- cmd/satellite/compensation.go | 11 +++--- satellite/compensation/invoice.go | 59 +++++++++++++++--------------- satellite/compensation/operator.go | 37 +++++++++++++++++++ 3 files changed, 73 insertions(+), 34 deletions(-) create mode 100644 satellite/compensation/operator.go diff --git a/cmd/satellite/compensation.go b/cmd/satellite/compensation.go index c36070797..7f0b721c9 100644 --- a/cmd/satellite/compensation.go +++ b/cmd/satellite/compensation.go @@ -95,11 +95,12 @@ func generateInvoicesCSV(ctx context.Context, period compensation.Period, out io } invoice := compensation.Invoice{ - Period: period, - NodeID: compensation.NodeID(usage.NodeID), - NodeWallet: node.Operator.Wallet, - NodeAddress: nodeAddress, - NodeLastIP: nodeLastIP, + Period: period, + NodeID: compensation.NodeID(usage.NodeID), + NodeWallet: node.Operator.Wallet, + NodeWalletFeatures: node.Operator.WalletFeatures, + NodeAddress: nodeAddress, + NodeLastIP: nodeLastIP, } if err := invoice.MergeNodeInfo(nodeInfo); err != nil { diff --git a/satellite/compensation/invoice.go b/satellite/compensation/invoice.go index c2382a931..590c07e29 100644 --- a/satellite/compensation/invoice.go +++ b/satellite/compensation/invoice.go @@ -13,35 +13,36 @@ import ( // Invoice holds the calculations for the amount required to pay to a node // for a given pay period. 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 - TotalPaid currency.MicroUnit `csv:"total-paid"` // Total amount ever paid to the node (but not necessarily dispensed) - TotalDistributed currency.MicroUnit `csv:"total-distributed"` // Total amount ever distributed to the node (always less than or equal to paid) + 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 + NodeWalletFeatures WalletFeatures `csv:"node-wallet-features"` // The node's wallet features + 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 + TotalPaid currency.MicroUnit `csv:"total-paid"` // Total amount ever paid to the node (but not necessarily dispensed) + TotalDistributed currency.MicroUnit `csv:"total-distributed"` // Total amount ever distributed to the node (always less than or equal to paid) } // MergeNodeInfo updates the fields representing the node information into the invoice. diff --git a/satellite/compensation/operator.go b/satellite/compensation/operator.go new file mode 100644 index 000000000..e81fb7cba --- /dev/null +++ b/satellite/compensation/operator.go @@ -0,0 +1,37 @@ +// Copyright (C) 2021 Storj Labs, Inc. +// See LICENSE for copying information. + +package compensation + +import "strings" + +// WalletFeatures represents wallet features list. +type WalletFeatures []string + +// DecodeWalletFeatures decodes wallet features list string separated by "|". +func DecodeWalletFeatures(s string) (WalletFeatures, error) { + if s == "" { + return nil, nil + } + return strings.Split(s, "|"), nil +} + +// String outputs . +func (features WalletFeatures) String() string { + return strings.Join(features, "|") +} + +// UnmarshalCSV reads the WalletFeatures in CSV form. +func (features *WalletFeatures) UnmarshalCSV(s string) error { + v, err := DecodeWalletFeatures(s) + if err != nil { + return err + } + *features = v + return nil +} + +// MarshalCSV returns the CSV form of the WalletFeatures. +func (features WalletFeatures) MarshalCSV() (string, error) { + return features.String(), nil +}