storj/satellite/compensation/payment.go
Jeff Wendling e2ff2ce672 satellite: compensation package and commands
Change-Id: I7fd6399837e45ff48e5f3d47a95192a01d58e125
2020-03-30 14:08:14 -06:00

47 lines
1.1 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package compensation
import (
"io"
"os"
"storj.io/common/strictcsv"
"storj.io/storj/private/currency"
)
// Payment represents an actual payment that happened.
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"`
}
// LoadPayments loads a collection of Payments from a file on disk containing
// them in CSV form.
func LoadPayments(path string) ([]Payment, error) {
f, err := os.Open(path)
if err != nil {
return nil, Error.Wrap(err)
}
defer func() { _ = f.Close() }()
return ReadPayments(f)
}
// ReadPayments reads a collection of Payments in CSV form.
func ReadPayments(r io.Reader) ([]Payment, error) {
var payments []Payment
if err := strictcsv.Read(r, &payments); err != nil {
return nil, err
}
return payments, nil
}
// WritePayments writes a collection of payments in CSV form.
func WritePayments(w io.Writer, payments []Payment) error {
return strictcsv.Write(w, payments)
}