mnd/payouts: estimated payouts per satellite changed to per node
Change-Id: I231e95ece1f52accb17839a00bfc1588b6e2a658
This commit is contained in:
parent
515f9b54ff
commit
83e82eb473
@ -53,8 +53,8 @@ func (controller *Payouts) GetAllNodesTotalEarned(w http.ResponseWriter, r *http
|
||||
}
|
||||
}
|
||||
|
||||
// SatelliteEstimations handles nodes estimated earnings from satellite.
|
||||
func (controller *Payouts) SatelliteEstimations(w http.ResponseWriter, r *http.Request) {
|
||||
// NodeEstimations handles node's estimated.
|
||||
func (controller *Payouts) NodeEstimations(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
var err error
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
@ -62,25 +62,25 @@ func (controller *Payouts) SatelliteEstimations(w http.ResponseWriter, r *http.R
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
segmentParams := mux.Vars(r)
|
||||
|
||||
id, ok := segmentParams["satelliteID"]
|
||||
id, ok := segmentParams["nodeID"]
|
||||
if !ok {
|
||||
controller.serveError(w, http.StatusBadRequest, ErrPayouts.New("couldn't receive route variable satelliteID"))
|
||||
controller.serveError(w, http.StatusBadRequest, ErrPayouts.New("couldn't receive route variable nodeID"))
|
||||
return
|
||||
}
|
||||
|
||||
satelliteID, err := storj.NodeIDFromString(id)
|
||||
nodeID, err := storj.NodeIDFromString(id)
|
||||
if err != nil {
|
||||
controller.serveError(w, http.StatusBadRequest, ErrPayouts.Wrap(err))
|
||||
return
|
||||
}
|
||||
|
||||
estimatedEarnings, err := controller.service.NodesSatelliteEstimations(ctx, satelliteID)
|
||||
estimations, err := controller.service.NodeEstimations(ctx, nodeID)
|
||||
if err != nil {
|
||||
controller.serveError(w, http.StatusInternalServerError, ErrPayouts.Wrap(err))
|
||||
return
|
||||
}
|
||||
|
||||
if err = json.NewEncoder(w).Encode(estimatedEarnings); err != nil {
|
||||
if err = json.NewEncoder(w).Encode(estimations); err != nil {
|
||||
controller.log.Error("failed to write json response", zap.Error(err))
|
||||
return
|
||||
}
|
||||
@ -94,13 +94,13 @@ func (controller *Payouts) Estimations(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
estimatedEarnings, err := controller.service.NodesEstimations(ctx)
|
||||
estimations, err := controller.service.Estimations(ctx)
|
||||
if err != nil {
|
||||
controller.serveError(w, http.StatusInternalServerError, ErrPayouts.Wrap(err))
|
||||
return
|
||||
}
|
||||
|
||||
if err = json.NewEncoder(w).Encode(estimatedEarnings); err != nil {
|
||||
if err = json.NewEncoder(w).Encode(estimations); err != nil {
|
||||
controller.log.Error("failed to write json response", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func NewServer(log *zap.Logger, config Config, nodes *nodes.Service, payouts *pa
|
||||
payoutsRouter.HandleFunc("/summary/{period}", payoutsController.PeriodSummary).Methods(http.MethodGet)
|
||||
payoutsRouter.HandleFunc("/summary", payoutsController.Summary).Methods(http.MethodGet)
|
||||
payoutsRouter.HandleFunc("/total-earned", payoutsController.GetAllNodesTotalEarned).Methods(http.MethodGet)
|
||||
payoutsRouter.HandleFunc("/estimations/{satelliteID}", payoutsController.SatelliteEstimations).Methods(http.MethodGet)
|
||||
payoutsRouter.HandleFunc("/estimations/{nodeID}", payoutsController.NodeEstimations).Methods(http.MethodGet)
|
||||
payoutsRouter.HandleFunc("/estimations", payoutsController.Estimations).Methods(http.MethodGet)
|
||||
|
||||
if server.config.StaticDir != "" {
|
||||
|
@ -308,34 +308,28 @@ func (service *Service) getAllSatellitesAllTime(ctx context.Context, node nodes.
|
||||
return response.PayoutInfo, nil
|
||||
}
|
||||
|
||||
// NodesSatelliteEstimations returns specific satellite all time estimated earnings.
|
||||
func (service *Service) NodesSatelliteEstimations(ctx context.Context, satelliteID storj.NodeID) (_ int64, err error) {
|
||||
// NodeEstimations returns node's estimated earnings.
|
||||
func (service *Service) NodeEstimations(ctx context.Context, nodeID storj.NodeID) (_ int64, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
var estimatedEarnings int64
|
||||
|
||||
list, err := service.nodes.List(ctx)
|
||||
node, err := service.nodes.Get(ctx, nodeID)
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
|
||||
for _, node := range list {
|
||||
estimation, err := service.nodeSatelliteEstimations(ctx, node, satelliteID)
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
|
||||
estimatedEarnings += estimation
|
||||
est, err := service.nodeEstimations(ctx, node)
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
|
||||
return estimatedEarnings, nil
|
||||
return est, nil
|
||||
}
|
||||
|
||||
// NodesEstimations returns all satellites all time estimated earnings.
|
||||
func (service *Service) NodesEstimations(ctx context.Context) (_ int64, err error) {
|
||||
// Estimations returns all nodes estimated earnings.
|
||||
func (service *Service) Estimations(ctx context.Context) (_ int64, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
var estimatedEarnings int64
|
||||
var estimations int64
|
||||
|
||||
list, err := service.nodes.List(ctx)
|
||||
if err != nil {
|
||||
@ -343,19 +337,19 @@ func (service *Service) NodesEstimations(ctx context.Context) (_ int64, err erro
|
||||
}
|
||||
|
||||
for _, node := range list {
|
||||
estimation, err := service.nodeEstimations(ctx, node)
|
||||
est, err := service.nodeEstimations(ctx, node)
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
|
||||
estimatedEarnings += estimation
|
||||
estimations += est
|
||||
}
|
||||
|
||||
return estimatedEarnings, nil
|
||||
return estimations, nil
|
||||
}
|
||||
|
||||
// nodeEstimations retrieves data from a single node.
|
||||
func (service *Service) nodeEstimations(ctx context.Context, node nodes.Node) (estimation int64, err error) {
|
||||
func (service *Service) nodeEstimations(ctx context.Context, node nodes.Node) (_ int64, err error) {
|
||||
conn, err := service.dialer.DialNodeURL(ctx, storj.NodeURL{
|
||||
ID: node.ID,
|
||||
Address: node.PublicAddress,
|
||||
@ -373,38 +367,15 @@ func (service *Service) nodeEstimations(ctx context.Context, node nodes.Node) (e
|
||||
ApiKey: node.APISecret,
|
||||
}
|
||||
|
||||
response, err := payoutClient.EstimatedPayoutTotal(ctx, &multinodepb.EstimatedPayoutTotalRequest{Header: header})
|
||||
estimated, err := payoutClient.EstimatedPayoutTotal(ctx, &multinodepb.EstimatedPayoutTotalRequest{Header: header})
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
|
||||
return response.EstimatedEarnings, nil
|
||||
}
|
||||
|
||||
// nodeSatelliteEstimations retrieves data from a single node.
|
||||
func (service *Service) nodeSatelliteEstimations(ctx context.Context, node nodes.Node, satelliteID storj.NodeID) (estimation int64, err error) {
|
||||
conn, err := service.dialer.DialNodeURL(ctx, storj.NodeURL{
|
||||
ID: node.ID,
|
||||
Address: node.PublicAddress,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err = errs.Combine(err, conn.Close())
|
||||
}()
|
||||
payoutClient := multinodepb.NewDRPCPayoutClient(conn)
|
||||
header := &multinodepb.RequestHeader{
|
||||
ApiKey: node.APISecret,
|
||||
}
|
||||
response, err := payoutClient.EstimatedPayoutSatellite(ctx, &multinodepb.EstimatedPayoutSatelliteRequest{Header: header, SatelliteId: satelliteID})
|
||||
if err != nil {
|
||||
return 0, Error.Wrap(err)
|
||||
}
|
||||
return response.EstimatedEarnings, nil
|
||||
return estimated.EstimatedEarnings, nil
|
||||
}
|
||||
|
||||
// getAmount returns earned from node.
|
||||
func (service *Service) getAmount(ctx context.Context, node nodes.Node) (_ int64, err error) {
|
||||
conn, err := service.dialer.DialNodeURL(ctx, storj.NodeURL{
|
||||
ID: node.ID,
|
||||
@ -431,6 +402,7 @@ func (service *Service) getAmount(ctx context.Context, node nodes.Node) (_ int64
|
||||
return amount.Total, nil
|
||||
}
|
||||
|
||||
// getEarnedOnSatellite returns earned split by satellites.
|
||||
func (service *Service) getEarnedOnSatellite(ctx context.Context, node nodes.Node) (_ multinodepb.EarnedPerSatelliteResponse, err error) {
|
||||
conn, err := service.dialer.DialNodeURL(ctx, storj.NodeURL{
|
||||
ID: node.ID,
|
||||
|
Loading…
Reference in New Issue
Block a user