@@ -20,9 +20,10 @@ type SummaryResult struct {
2020}
2121
2222type SummaryData struct {
23- TotalAcceptedQuotesCount int64 `json:"totalAcceptedQuotesCount"`
24- ConfirmedQuotesCount int64 `json:"confirmedQuotesCount"`
25- TotalQuotedAmount * entities.Wei `json:"totalQuotedAmount"`
23+ TotalQuotesCount int64 `json:"totalQuotesCount"`
24+ AcceptedQuotesCount int64 `json:"acceptedQuotesCount"`
25+ PaidQuotesCount int64 `json:"paidQuotesCount"`
26+ PaidQuotesAmount * entities.Wei `json:"paidQuotesAmount"`
2627 TotalAcceptedQuotedAmount * entities.Wei `json:"totalAcceptedQuotedAmount"`
2728 TotalFeesCollected * entities.Wei `json:"totalFeesCollected"`
2829 RefundedQuotesCount int64 `json:"refundedQuotesCount"`
@@ -38,9 +39,8 @@ type feeAdapter struct {
3839}
3940
4041type quoteResultAdapter [Q any , R quote.RetainedQuote ] struct {
41- quotes []Q
42- retainedQuotes []R
43- quoteHashToIndex map [string ]int
42+ quotes []Q
43+ retainedQuotes []R
4444}
4545
4646type SummariesUseCase struct {
@@ -50,9 +50,10 @@ type SummariesUseCase struct {
5050
5151func NewSummaryData () SummaryData {
5252 return SummaryData {
53- TotalAcceptedQuotesCount : 0 ,
54- ConfirmedQuotesCount : 0 ,
55- TotalQuotedAmount : entities .NewWei (0 ),
53+ TotalQuotesCount : 0 ,
54+ AcceptedQuotesCount : 0 ,
55+ PaidQuotesCount : 0 ,
56+ PaidQuotesAmount : entities .NewWei (0 ),
5657 TotalAcceptedQuotedAmount : entities .NewWei (0 ),
5758 TotalFeesCollected : entities .NewWei (0 ),
5859 RefundedQuotesCount : 0 ,
@@ -116,39 +117,46 @@ func processQuoteData[Q any, R quote.RetainedQuote, F quote.FeeProvider](
116117 ctx context.Context ,
117118 quotes []Q ,
118119 retainedQuotes []R ,
119- quoteHashToIndex map [string ]int ,
120120 getQuote func (context.Context , string ) (* Q , error ),
121121 isPaid func (R ) bool ,
122122 isRefunded func (R ) bool ,
123123 feeProvider func (* Q ) F ,
124124) SummaryData {
125125 data := NewSummaryData ()
126126 totalAmount := calculateTotalAmount (quotes )
127+ data .TotalQuotesCount = int64 (len (quotes ))
127128 if len (retainedQuotes ) == 0 {
128- data .TotalAcceptedQuotesCount = int64 ( len ( quotes ))
129- data .TotalQuotedAmount = totalAmount
129+ data .PaidQuotesAmount = totalAmount
130+ data .PaidQuotesCount = 0
130131 return data
131132 }
132- data .TotalAcceptedQuotesCount = int64 (len (retainedQuotes ))
133- quotesByHash := createQuoteHashMap (quotes , quoteHashToIndex )
133+ data .AcceptedQuotesCount = int64 (len (retainedQuotes ))
134+ quotesByHash := make (map [string ]* Q )
135+ for i := range quotes {
136+ if retainedQuote , ok := any (& quotes [i ]).(quote.RetainedQuote ); ok {
137+ hash := retainedQuote .GetQuoteHash ()
138+ quoteCopy := quotes [i ]
139+ quotesByHash [hash ] = & quoteCopy
140+ }
141+ }
134142 fetchMissingQuotes (ctx , quotesByHash , retainedQuotes , totalAmount , getQuote )
135- data .TotalQuotedAmount = totalAmount
143+ data .PaidQuotesAmount = totalAmount
144+ data .PaidQuotesCount = 0
136145 acceptedTotalAmount := entities .NewWei (0 )
137146 totalFees := entities .NewWei (0 )
138147 callFees := entities .NewWei (0 )
139148 totalPenalty := entities .NewWei (0 )
140149 for _ , retained := range retainedQuotes {
141- quoteHash := retained .GetQuoteHash ()
142- quoteObj , exists := quotesByHash [quoteHash ]
150+ quoteObj , exists := quotesByHash [retained .GetQuoteHash ()]
143151 if ! exists {
144152 continue
145153 }
146154 fees := feeProvider (quoteObj )
147- data .ConfirmedQuotesCount ++
148155 if q , ok := any (quoteObj ).(quote.Quote ); ok {
149156 acceptedTotalAmount .Add (acceptedTotalAmount , q .Total ())
150157 }
151158 if isPaid (retained ) {
159+ data .PaidQuotesCount ++
152160 callFee := fees .GetCallFee ()
153161 callFees .Add (callFees , callFee )
154162 totalFees .Add (totalFees , callFee )
@@ -183,17 +191,6 @@ func calculateTotalAmount[T any](quotes []T) *entities.Wei {
183191 return totalAmount
184192}
185193
186- func createQuoteHashMap [T any ](quotes []T , quoteHashToIndex map [string ]int ) map [string ]* T {
187- quotesByHash := make (map [string ]* T , len (quoteHashToIndex ))
188- for hash , index := range quoteHashToIndex {
189- if index >= 0 && index < len (quotes ) {
190- quoteCopy := quotes [index ]
191- quotesByHash [hash ] = & quoteCopy
192- }
193- }
194- return quotesByHash
195- }
196-
197194func fetchMissingQuotes [Q any , R quote.RetainedQuote ](
198195 ctx context.Context ,
199196 quotesByHash map [string ]* Q ,
@@ -224,17 +221,15 @@ func fetchMissingQuotes[Q any, R quote.RetainedQuote](
224221
225222func adaptPeginResult (result quote.PeginQuoteResult ) quote.QuoteResult [quote.PeginQuote , quote.RetainedPeginQuote ] {
226223 return quoteResultAdapter [quote.PeginQuote , quote.RetainedPeginQuote ]{
227- quotes : result .Quotes ,
228- retainedQuotes : result .RetainedQuotes ,
229- quoteHashToIndex : result .QuoteHashToIndex ,
224+ quotes : result .Quotes ,
225+ retainedQuotes : result .RetainedQuotes ,
230226 }
231227}
232228
233229func adaptPegoutResult (result quote.PegoutQuoteResult ) quote.QuoteResult [quote.PegoutQuote , quote.RetainedPegoutQuote ] {
234230 return quoteResultAdapter [quote.PegoutQuote , quote.RetainedPegoutQuote ]{
235- quotes : result .Quotes ,
236- retainedQuotes : result .RetainedQuotes ,
237- quoteHashToIndex : result .QuoteHashToIndex ,
231+ quotes : result .Quotes ,
232+ retainedQuotes : result .RetainedQuotes ,
238233 }
239234}
240235
@@ -256,7 +251,6 @@ func aggregateData[Q any, RQ quote.RetainedQuote](
256251 ctx ,
257252 result .GetQuotes (),
258253 result .GetRetainedQuotes (),
259- result .GetQuoteHashToIndex (),
260254 getQuote ,
261255 isPaid ,
262256 isRefunded ,
@@ -328,7 +322,3 @@ func (a quoteResultAdapter[Q, R]) GetQuotes() []Q {
328322func (a quoteResultAdapter [Q , R ]) GetRetainedQuotes () []R {
329323 return a .retainedQuotes
330324}
331-
332- func (a quoteResultAdapter [Q , R ]) GetQuoteHashToIndex () map [string ]int {
333- return a .quoteHashToIndex
334- }
0 commit comments