@@ -10,7 +10,7 @@ use ethereum_types::U256;
10
10
use eventuals:: Eventual ;
11
11
use indexer_common:: prelude:: SubgraphClient ;
12
12
use jsonrpsee:: { core:: client:: ClientT , http_client:: HttpClientBuilder , rpc_params} ;
13
- use sqlx:: PgPool ;
13
+ use sqlx:: { types :: BigDecimal , PgPool } ;
14
14
use tap_aggregator:: jsonrpsee_helpers:: JsonRpcResponse ;
15
15
use tap_core:: {
16
16
eip_712_signed_message:: EIP712SignedMessage ,
@@ -219,7 +219,6 @@ impl SenderAllocationRelationship {
219
219
AND sender_address = $2
220
220
)
221
221
SELECT
222
- COUNT(*),
223
222
MAX(id),
224
223
SUM(value)
225
224
FROM
@@ -251,28 +250,17 @@ impl SenderAllocationRelationship {
251
250
252
251
let mut unaggregated_fees = inner. unaggregated_fees . lock ( ) . await ;
253
252
254
- // `COUNT(*)` will always return a value, so we don't need to check for `None`.
255
- match res. count . unwrap ( ) {
256
- 0 => {
257
- unaggregated_fees. last_id = 0 ;
258
- unaggregated_fees. value = 0 ;
259
- }
260
- // If the count is non-zero, then `MAX(id)` and `SUM(value)` will be non-null.
261
- // If they are null, then something is extremely wrong with the database.
262
- _ => {
263
- ensure ! (
264
- res. max. is_some( ) ,
265
- "MAX(id) is null but the receipt COUNT(*) is not zero"
266
- ) ;
267
- ensure ! (
268
- res. sum. is_some( ) ,
269
- "SUM(value) is null, but the receipt COUNT(*) is not zero"
270
- ) ;
253
+ ensure ! (
254
+ res. sum. is_none( ) == res. max. is_none( ) ,
255
+ "Exactly one of SUM(value) and MAX(id) is null. This should not happen."
256
+ ) ;
271
257
272
- unaggregated_fees. last_id = res. max . unwrap ( ) . try_into ( ) ?;
273
- unaggregated_fees. value = res. sum . unwrap ( ) . to_string ( ) . parse :: < u128 > ( ) ?;
274
- }
275
- }
258
+ unaggregated_fees. last_id = res. max . unwrap_or ( 0 ) . try_into ( ) ?;
259
+ unaggregated_fees. value = res
260
+ . sum
261
+ . unwrap_or ( BigDecimal :: from ( 0 ) )
262
+ . to_string ( )
263
+ . parse :: < u128 > ( ) ?;
276
264
277
265
// TODO: check if we need to run a RAV request here.
278
266
0 commit comments