2021-01-07 19:17:46 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package multinode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-05 18:10:58 +01:00
|
|
|
"time"
|
2021-01-07 19:17:46 +00:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"storj.io/common/rpc/rpcstatus"
|
|
|
|
"storj.io/storj/private/multinodepb"
|
|
|
|
"storj.io/storj/storagenode/apikeys"
|
2021-01-14 16:41:36 +00:00
|
|
|
"storj.io/storj/storagenode/payouts"
|
2021-05-05 18:10:58 +01:00
|
|
|
"storj.io/storj/storagenode/payouts/estimatedpayouts"
|
2021-01-07 19:17:46 +00:00
|
|
|
)
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
var _ multinodepb.DRPCPayoutsServer = (*PayoutEndpoint)(nil)
|
2021-01-07 19:17:46 +00:00
|
|
|
|
2021-01-14 16:41:36 +00:00
|
|
|
// PayoutEndpoint implements multinode payouts endpoint.
|
2021-01-07 19:17:46 +00:00
|
|
|
//
|
|
|
|
// architecture: Endpoint
|
|
|
|
type PayoutEndpoint struct {
|
2021-05-25 17:48:45 +01:00
|
|
|
multinodepb.DRPCPayoutsUnimplementedServer
|
2021-03-29 09:58:04 +01:00
|
|
|
|
2021-05-05 18:10:58 +01:00
|
|
|
log *zap.Logger
|
|
|
|
apiKeys *apikeys.Service
|
|
|
|
db payouts.DB
|
2021-04-22 19:50:42 +01:00
|
|
|
service *payouts.Service
|
|
|
|
estimatedPayouts *estimatedpayouts.Service
|
2021-01-07 19:17:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 16:41:36 +00:00
|
|
|
// NewPayoutEndpoint creates new multinode payouts endpoint.
|
2021-04-22 19:50:42 +01:00
|
|
|
func NewPayoutEndpoint(log *zap.Logger, apiKeys *apikeys.Service, db payouts.DB, estimatedPayouts *estimatedpayouts.Service, service *payouts.Service) *PayoutEndpoint {
|
2021-01-07 19:17:46 +00:00
|
|
|
return &PayoutEndpoint{
|
2021-05-05 18:10:58 +01:00
|
|
|
log: log,
|
|
|
|
apiKeys: apiKeys,
|
|
|
|
db: db,
|
2021-04-22 19:50:42 +01:00
|
|
|
service: service,
|
|
|
|
estimatedPayouts: estimatedPayouts,
|
2021-01-07 19:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Earned returns total earned amount.
|
|
|
|
func (payout *PayoutEndpoint) Earned(ctx context.Context, req *multinodepb.EarnedRequest) (_ *multinodepb.EarnedResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
earned, err := payout.db.GetTotalEarned(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &multinodepb.EarnedResponse{
|
|
|
|
Total: earned,
|
|
|
|
}, nil
|
|
|
|
}
|
2021-02-04 15:44:31 +00:00
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// EarnedSatellite returns total earned amount per satellite.
|
|
|
|
func (payout *PayoutEndpoint) EarnedSatellite(ctx context.Context, req *multinodepb.EarnedSatelliteRequest) (_ *multinodepb.EarnedSatelliteResponse, err error) {
|
2021-02-04 15:44:31 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
var resp multinodepb.EarnedSatelliteResponse
|
2021-02-04 15:44:31 +00:00
|
|
|
satelliteIDs, err := payout.db.GetPayingSatellitesIDs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
2021-05-14 23:03:38 +01:00
|
|
|
for _, id := range satelliteIDs {
|
|
|
|
earned, err := payout.db.GetEarnedAtSatellite(ctx, id)
|
2021-02-04 15:44:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.EarnedSatellite = append(resp.EarnedSatellite, &multinodepb.EarnedSatellite{
|
|
|
|
Total: earned,
|
2021-05-14 23:03:38 +01:00
|
|
|
SatelliteId: id,
|
2021-02-04 15:44:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return &resp, nil
|
|
|
|
}
|
2021-05-05 18:10:58 +01:00
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// EstimatedPayout returns estimated earnings for current month from all satellites.
|
|
|
|
func (payout *PayoutEndpoint) EstimatedPayout(ctx context.Context, req *multinodepb.EstimatedPayoutRequest) (_ *multinodepb.EstimatedPayoutResponse, err error) {
|
2021-05-05 18:10:58 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
estimated, err := payout.estimatedPayouts.GetAllSatellitesEstimatedPayout(ctx, time.Now())
|
|
|
|
if err != nil {
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.EstimatedPayoutResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
2021-05-05 18:10:58 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.EstimatedPayoutResponse{EstimatedEarnings: estimated.CurrentMonthExpectations}, nil
|
2021-05-05 18:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// EstimatedPayoutSatellite returns estimated earnings for current month from specific satellite.
|
|
|
|
func (payout *PayoutEndpoint) EstimatedPayoutSatellite(ctx context.Context, req *multinodepb.EstimatedPayoutSatelliteRequest) (_ *multinodepb.EstimatedPayoutSatelliteResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
estimated, err := payout.estimatedPayouts.GetSatelliteEstimatedPayout(ctx, req.SatelliteId, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
return &multinodepb.EstimatedPayoutSatelliteResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &multinodepb.EstimatedPayoutSatelliteResponse{EstimatedEarnings: estimated.CurrentMonthExpectations}, nil
|
|
|
|
}
|
2021-05-05 18:34:10 +01:00
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// Summary returns all satellites all time payout summary.
|
|
|
|
func (payout *PayoutEndpoint) Summary(ctx context.Context, req *multinodepb.SummaryRequest) (_ *multinodepb.SummaryResponse, err error) {
|
2021-05-05 18:34:10 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var totalPaid, totalHeld int64
|
|
|
|
satelliteIDs, err := payout.db.GetPayingSatellitesIDs(ctx)
|
|
|
|
if err != nil {
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummaryResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
2021-05-05 18:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range satelliteIDs {
|
|
|
|
paid, held, err := payout.db.GetSatelliteSummary(ctx, id)
|
|
|
|
if err != nil {
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummaryResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
2021-05-05 18:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
totalHeld += held
|
|
|
|
totalPaid += paid
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummaryResponse{PayoutInfo: &multinodepb.PayoutInfo{Paid: totalPaid, Held: totalHeld}}, nil
|
2021-05-05 18:34:10 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// SummaryPeriod returns all satellites period payout summary.
|
|
|
|
func (payout *PayoutEndpoint) SummaryPeriod(ctx context.Context, req *multinodepb.SummaryPeriodRequest) (_ *multinodepb.SummaryPeriodResponse, err error) {
|
2021-05-05 18:34:10 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var totalPaid, totalHeld int64
|
|
|
|
satelliteIDs, err := payout.db.GetPayingSatellitesIDs(ctx)
|
|
|
|
if err != nil {
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummaryPeriodResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
2021-05-05 18:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range satelliteIDs {
|
|
|
|
paid, held, err := payout.db.GetSatellitePeriodSummary(ctx, id, req.Period)
|
|
|
|
if err != nil {
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummaryPeriodResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
2021-05-05 18:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
totalHeld += held
|
|
|
|
totalPaid += paid
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummaryPeriodResponse{PayoutInfo: &multinodepb.PayoutInfo{Held: totalHeld, Paid: totalPaid}}, nil
|
2021-05-05 18:34:10 +01:00
|
|
|
}
|
2021-05-05 21:01:16 +01:00
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// SummarySatellite returns satellite all time payout summary.
|
|
|
|
func (payout *PayoutEndpoint) SummarySatellite(ctx context.Context, req *multinodepb.SummarySatelliteRequest) (_ *multinodepb.SummarySatelliteResponse, err error) {
|
2021-05-05 21:01:16 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var totalPaid, totalHeld int64
|
|
|
|
|
|
|
|
totalPaid, totalHeld, err = payout.db.GetSatelliteSummary(ctx, req.SatelliteId)
|
|
|
|
if err != nil {
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummarySatelliteResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
2021-05-05 21:01:16 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummarySatelliteResponse{PayoutInfo: &multinodepb.PayoutInfo{Held: totalHeld, Paid: totalPaid}}, nil
|
2021-05-05 21:01:16 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// SummarySatellitePeriod returns satellite period payout summary.
|
|
|
|
func (payout *PayoutEndpoint) SummarySatellitePeriod(ctx context.Context, req *multinodepb.SummarySatellitePeriodRequest) (_ *multinodepb.SummarySatellitePeriodResponse, err error) {
|
2021-05-05 21:01:16 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var totalPaid, totalHeld int64
|
|
|
|
|
|
|
|
totalPaid, totalHeld, err = payout.db.GetSatellitePeriodSummary(ctx, req.SatelliteId, req.Period)
|
|
|
|
if err != nil {
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummarySatellitePeriodResponse{}, rpcstatus.Wrap(rpcstatus.Internal, err)
|
2021-05-05 21:01:16 +01:00
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.SummarySatellitePeriodResponse{PayoutInfo: &multinodepb.PayoutInfo{Held: totalHeld, Paid: totalPaid}}, nil
|
2021-05-05 21:01:16 +01:00
|
|
|
}
|
2021-05-14 23:03:38 +01:00
|
|
|
|
|
|
|
// Undistributed returns total undistributed amount.
|
|
|
|
func (payout *PayoutEndpoint) Undistributed(ctx context.Context, req *multinodepb.UndistributedRequest) (_ *multinodepb.UndistributedResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
earned, err := payout.db.GetUndistributed(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &multinodepb.UndistributedResponse{Total: earned}, nil
|
|
|
|
}
|
2021-05-25 13:02:20 +01:00
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// PaystubSatellite returns summed amounts of all values from paystubs from all satellites.
|
|
|
|
func (payout *PayoutEndpoint) PaystubSatellite(ctx context.Context, req *multinodepb.PaystubSatelliteRequest) (_ *multinodepb.PaystubSatelliteResponse, err error) {
|
2021-05-25 13:02:20 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
paystub, err := payout.db.GetSatellitePaystubs(ctx, req.SatelliteId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.PaystubSatelliteResponse{Paystub: &multinodepb.Paystub{
|
2021-05-25 13:02:20 +01:00
|
|
|
UsageAtRest: paystub.UsageAtRest,
|
|
|
|
UsageGet: paystub.UsageGet,
|
|
|
|
UsageGetRepair: paystub.UsageGetRepair,
|
|
|
|
UsageGetAudit: paystub.UsageGetAudit,
|
|
|
|
CompAtRest: paystub.CompAtRest,
|
|
|
|
CompGet: paystub.CompGet,
|
|
|
|
CompGetRepair: paystub.CompGetRepair,
|
|
|
|
CompGetAudit: paystub.CompGetAudit,
|
|
|
|
Held: paystub.Held,
|
|
|
|
Paid: paystub.Paid,
|
|
|
|
Distributed: paystub.Distributed,
|
2021-06-01 16:02:50 +01:00
|
|
|
Disposed: paystub.Disposed,
|
2021-05-25 13:02:20 +01:00
|
|
|
}}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paystub returns summed amounts of all values from paystubs from all satellites.
|
|
|
|
func (payout *PayoutEndpoint) Paystub(ctx context.Context, req *multinodepb.PaystubRequest) (_ *multinodepb.PaystubResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
paystub, err := payout.db.GetPaystubs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &multinodepb.PaystubResponse{Paystub: &multinodepb.Paystub{
|
|
|
|
UsageAtRest: paystub.UsageAtRest,
|
|
|
|
UsageGet: paystub.UsageGet,
|
|
|
|
UsageGetRepair: paystub.UsageGetRepair,
|
|
|
|
UsageGetAudit: paystub.UsageGetAudit,
|
|
|
|
CompAtRest: paystub.CompAtRest,
|
|
|
|
CompGet: paystub.CompGet,
|
|
|
|
CompGetRepair: paystub.CompGetRepair,
|
|
|
|
CompGetAudit: paystub.CompGetAudit,
|
|
|
|
Held: paystub.Held,
|
|
|
|
Paid: paystub.Paid,
|
|
|
|
Distributed: paystub.Distributed,
|
2021-06-01 16:02:50 +01:00
|
|
|
Disposed: paystub.Disposed,
|
2021-05-25 13:02:20 +01:00
|
|
|
}}, nil
|
|
|
|
}
|
2021-05-24 21:40:31 +01:00
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// PaystubPeriod returns summed amounts of all values from paystubs from all satellites for specific period.
|
|
|
|
func (payout *PayoutEndpoint) PaystubPeriod(ctx context.Context, req *multinodepb.PaystubPeriodRequest) (_ *multinodepb.PaystubPeriodResponse, err error) {
|
2021-05-24 21:40:31 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
paystub, err := payout.db.GetPeriodPaystubs(ctx, req.Period)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.PaystubPeriodResponse{Paystub: &multinodepb.Paystub{
|
2021-05-24 21:40:31 +01:00
|
|
|
UsageAtRest: paystub.UsageAtRest,
|
|
|
|
UsageGet: paystub.UsageGet,
|
|
|
|
UsageGetRepair: paystub.UsageGetRepair,
|
|
|
|
UsageGetAudit: paystub.UsageGetAudit,
|
|
|
|
CompAtRest: paystub.CompAtRest,
|
|
|
|
CompGet: paystub.CompGet,
|
|
|
|
CompGetRepair: paystub.CompGetRepair,
|
|
|
|
CompGetAudit: paystub.CompGetAudit,
|
|
|
|
Held: paystub.Held,
|
|
|
|
Paid: paystub.Paid,
|
|
|
|
Distributed: paystub.Distributed,
|
2021-06-01 16:02:50 +01:00
|
|
|
Disposed: paystub.Disposed,
|
2021-05-24 21:40:31 +01:00
|
|
|
}}, nil
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
// PaystubPeriodSatellite returns summed amounts of all values from paystubs from all satellites for specific period.
|
|
|
|
func (payout *PayoutEndpoint) PaystubPeriodSatellite(ctx context.Context, req *multinodepb.PaystubSatellitePeriodRequest) (_ *multinodepb.PaystubSatellitePeriodResponse, err error) {
|
2021-05-24 21:40:31 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
paystub, err := payout.db.GetSatellitePeriodPaystubs(ctx, req.Period, req.SatelliteId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:48:45 +01:00
|
|
|
return &multinodepb.PaystubSatellitePeriodResponse{Paystub: &multinodepb.Paystub{
|
2021-05-24 21:40:31 +01:00
|
|
|
UsageAtRest: paystub.UsageAtRest,
|
|
|
|
UsageGet: paystub.UsageGet,
|
|
|
|
UsageGetRepair: paystub.UsageGetRepair,
|
|
|
|
UsageGetAudit: paystub.UsageGetAudit,
|
|
|
|
CompAtRest: paystub.CompAtRest,
|
|
|
|
CompGet: paystub.CompGet,
|
|
|
|
CompGetRepair: paystub.CompGetRepair,
|
|
|
|
CompGetAudit: paystub.CompGetAudit,
|
|
|
|
Held: paystub.Held,
|
|
|
|
Paid: paystub.Paid,
|
|
|
|
Distributed: paystub.Distributed,
|
2021-06-01 16:02:50 +01:00
|
|
|
Disposed: paystub.Disposed,
|
2021-05-24 21:40:31 +01:00
|
|
|
}}, nil
|
|
|
|
}
|
2021-04-22 19:50:42 +01:00
|
|
|
|
|
|
|
// HeldAmountHistory returns held amount history for all satellites.
|
|
|
|
func (payout *PayoutEndpoint) HeldAmountHistory(ctx context.Context, req *multinodepb.HeldAmountHistoryRequest) (_ *multinodepb.HeldAmountHistoryResponse, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
heldHistory, err := payout.service.HeldAmountHistory(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcstatus.Wrap(rpcstatus.Internal, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(multinodepb.HeldAmountHistoryResponse)
|
|
|
|
|
|
|
|
for _, satelliteHeldHistory := range heldHistory {
|
|
|
|
var pbHeldAmount []*multinodepb.HeldAmountHistoryResponse_HeldAmount
|
|
|
|
|
|
|
|
for _, heldAmount := range satelliteHeldHistory.HeldAmounts {
|
|
|
|
pbHeldAmount = append(pbHeldAmount, &multinodepb.HeldAmountHistoryResponse_HeldAmount{
|
|
|
|
Period: heldAmount.Period,
|
|
|
|
Amount: heldAmount.Amount,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.History = append(resp.History, &multinodepb.HeldAmountHistoryResponse_HeldAmountHistory{
|
|
|
|
SatelliteId: satelliteHeldHistory.SatelliteID,
|
|
|
|
HeldAmounts: pbHeldAmount,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|