Skip to content

Commit

Permalink
refactor: early handle bytes for protobuf def getPaymentState
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 18, 2024
1 parent 5121f7c commit 122d7a9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions disperser/apiserver/server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"math/big"
"net"
"sync/atomic"
"time"
Expand Down Expand Up @@ -285,9 +284,13 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym
if err != nil {
s.logger.Debug("failed to get reservation records, use placeholders", "err", err, "accountID", accountID)
}
var largestCumulativePaymentBytes []byte
largestCumulativePayment, err := s.meterer.OffchainStore.GetLargestCumulativePayment(ctx, req.AccountId)
if err != nil {
s.logger.Debug("failed to get largest cumulative payment, use zero value", "err", err, "accountID", accountID)

} else {
largestCumulativePaymentBytes = largestCumulativePayment.Bytes()
}
// on-Chain account state
var pbReservation *pb.Reservation
Expand All @@ -313,13 +316,12 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym
}
}

var onchainCumulativePayment *big.Int
var onchainCumulativePaymentBytes []byte
onDemandPayment, err := s.meterer.ChainPaymentState.GetOnDemandPaymentByAccount(ctx, accountID)
if err != nil {
s.logger.Debug("failed to get ondemand payment, use zero value", "err", err, "accountID", accountID)
onchainCumulativePayment =
} else {
onchainCumulativePayment = onDemandPayment.CumulativePayment
onchainCumulativePaymentBytes = onDemandPayment.CumulativePayment.Bytes()
}

paymentGlobalParams := pb.PaymentGlobalParams{
Expand All @@ -334,8 +336,8 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym
PaymentGlobalParams: &paymentGlobalParams,
BinRecords: binRecords[:],
Reservation: pbReservation,
CumulativePayment: largestCumulativePayment.Bytes(),
OnchainCumulativePayment: onchainCumulativePayment.Bytes(),
CumulativePayment: largestCumulativePaymentBytes,
OnchainCumulativePayment: onchainCumulativePaymentBytes,
}
return reply, nil
}

0 comments on commit 122d7a9

Please sign in to comment.