From 122d7a9d4a63b346f99287f964b08199f037bba3 Mon Sep 17 00:00:00 2001 From: hopeyen <60078528+hopeyen@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:21:37 +0000 Subject: [PATCH] refactor: early handle bytes for protobuf def getPaymentState --- disperser/apiserver/server_v2.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index 2aadb961c..32cbb6155 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "math/big" "net" "sync/atomic" "time" @@ -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 @@ -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{ @@ -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 }