@@ -126,6 +126,24 @@ impl PhotonIndexer {
126
126
result. ok_or_else ( || IndexerError :: missing_result ( context, "value not present" ) )
127
127
}
128
128
129
+ fn extract_result_with_error_check < T > (
130
+ context : & str ,
131
+ error : Option < Box < photon_api:: models:: GetBatchAddressUpdateInfoPost200ResponseError > > ,
132
+ result : Option < T > ,
133
+ ) -> Result < T , IndexerError > {
134
+ if let Some ( error) = error {
135
+ let error_message = error
136
+ . message
137
+ . unwrap_or_else ( || "Unknown API error" . to_string ( ) ) ;
138
+ return Err ( IndexerError :: ApiError ( format ! (
139
+ "API error in {} (code: {:?}): {}" ,
140
+ context, error. code, error_message
141
+ ) ) ) ;
142
+ }
143
+
144
+ Self :: extract_result ( context, result)
145
+ }
146
+
129
147
fn build_account_params (
130
148
& self ,
131
149
address : Option < Address > ,
@@ -174,7 +192,11 @@ impl Indexer for PhotonIndexer {
174
192
request,
175
193
)
176
194
. await ?;
177
- let api_response = Self :: extract_result ( "get_compressed_account" , result. result ) ?;
195
+ let api_response = Self :: extract_result_with_error_check (
196
+ "get_compressed_account" ,
197
+ result. error ,
198
+ result. result . map ( |r| * r) ,
199
+ ) ?;
178
200
if api_response. context . slot < config. slot {
179
201
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
180
202
}
@@ -212,7 +234,11 @@ impl Indexer for PhotonIndexer {
212
234
request,
213
235
)
214
236
. await ?;
215
- let api_response = Self :: extract_result ( "get_compressed_account" , result. result ) ?;
237
+ let api_response = Self :: extract_result_with_error_check (
238
+ "get_compressed_account_by_hash" ,
239
+ result. error ,
240
+ result. result . map ( |r| * r) ,
241
+ ) ?;
216
242
if api_response. context . slot < config. slot {
217
243
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
218
244
}
@@ -359,8 +385,11 @@ impl Indexer for PhotonIndexer {
359
385
)
360
386
. await ?;
361
387
362
- let api_response =
363
- Self :: extract_result ( "get_compressed_account_balance" , result. result ) ?;
388
+ let api_response = Self :: extract_result_with_error_check (
389
+ "get_compressed_account_balance" ,
390
+ result. error ,
391
+ result. result . map ( |r| * r) ,
392
+ ) ?;
364
393
if api_response. context . slot < config. slot {
365
394
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
366
395
}
@@ -396,8 +425,11 @@ impl Indexer for PhotonIndexer {
396
425
)
397
426
. await ?;
398
427
399
- let api_response =
400
- Self :: extract_result ( "get_compressed_balance_by_owner" , result. result ) ?;
428
+ let api_response = Self :: extract_result_with_error_check (
429
+ "get_compressed_balance_by_owner" ,
430
+ result. error ,
431
+ result. result . map ( |r| * r) ,
432
+ ) ?;
401
433
if api_response. context . slot < config. slot {
402
434
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
403
435
}
@@ -436,8 +468,11 @@ impl Indexer for PhotonIndexer {
436
468
)
437
469
. await ?;
438
470
439
- let api_response =
440
- Self :: extract_result ( "get_compressed_mint_token_holders" , result. result ) ?;
471
+ let api_response = Self :: extract_result_with_error_check (
472
+ "get_compressed_mint_token_holders" ,
473
+ result. error ,
474
+ result. result . map ( |r| * r) ,
475
+ ) ?;
441
476
if api_response. context . slot < config. slot {
442
477
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
443
478
}
@@ -485,8 +520,11 @@ impl Indexer for PhotonIndexer {
485
520
)
486
521
. await ?;
487
522
488
- let api_response =
489
- Self :: extract_result ( "get_compressed_token_account_balance" , result. result ) ?;
523
+ let api_response = Self :: extract_result_with_error_check (
524
+ "get_compressed_token_account_balance" ,
525
+ result. error ,
526
+ result. result . map ( |r| * r) ,
527
+ ) ?;
490
528
if api_response. context . slot < config. slot {
491
529
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
492
530
}
@@ -677,8 +715,11 @@ impl Indexer for PhotonIndexer {
677
715
)
678
716
. await ?;
679
717
680
- let response =
681
- Self :: extract_result ( "get_compressed_token_accounts_by_owner" , result. result ) ?;
718
+ let response = Self :: extract_result_with_error_check (
719
+ "get_compressed_token_accounts_by_owner" ,
720
+ result. error ,
721
+ result. result . map ( |r| * r) ,
722
+ ) ?;
682
723
if response. context . slot < config. slot {
683
724
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
684
725
}
@@ -737,9 +778,10 @@ impl Indexer for PhotonIndexer {
737
778
)
738
779
. await ?;
739
780
740
- let api_response = Self :: extract_result (
781
+ let api_response = Self :: extract_result_with_error_check (
741
782
"get_compressed_token_balances_by_owner_v2" ,
742
- result. result ,
783
+ result. error ,
784
+ result. result . map ( |r| * r) ,
743
785
) ?;
744
786
if api_response. context . slot < config. slot {
745
787
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
@@ -786,8 +828,11 @@ impl Indexer for PhotonIndexer {
786
828
)
787
829
. await ?;
788
830
789
- let api_response =
790
- Self :: extract_result ( "get_compressed_token_balances_by_owner" , result. result ) ?;
831
+ let api_response = Self :: extract_result_with_error_check (
832
+ "get_compressed_token_balances_by_owner" ,
833
+ result. error ,
834
+ result. result . map ( |r| * r) ,
835
+ ) ?;
791
836
if api_response. context . slot < config. slot {
792
837
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
793
838
}
@@ -836,8 +881,11 @@ impl Indexer for PhotonIndexer {
836
881
)
837
882
. await ?;
838
883
839
- let api_response =
840
- Self :: extract_result ( "get_compression_signatures_for_account" , result. result ) ?;
884
+ let api_response = Self :: extract_result_with_error_check (
885
+ "get_compression_signatures_for_account" ,
886
+ result. error ,
887
+ result. result . map ( |r| * r) ,
888
+ ) ?;
841
889
if api_response. context . slot < config. slot {
842
890
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
843
891
}
@@ -884,8 +932,11 @@ impl Indexer for PhotonIndexer {
884
932
)
885
933
. await ?;
886
934
887
- let api_response =
888
- Self :: extract_result ( "get_compression_signatures_for_address" , result. result ) ?;
935
+ let api_response = Self :: extract_result_with_error_check (
936
+ "get_compression_signatures_for_address" ,
937
+ result. error ,
938
+ result. result . map ( |r| * r) ,
939
+ ) ?;
889
940
if api_response. context . slot < config. slot {
890
941
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
891
942
}
@@ -937,8 +988,11 @@ impl Indexer for PhotonIndexer {
937
988
)
938
989
. await ?;
939
990
940
- let api_response =
941
- Self :: extract_result ( "get_compression_signatures_for_owner" , result. result ) ?;
991
+ let api_response = Self :: extract_result_with_error_check (
992
+ "get_compression_signatures_for_owner" ,
993
+ result. error ,
994
+ result. result . map ( |r| * r) ,
995
+ ) ?;
942
996
if api_response. context . slot < config. slot {
943
997
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
944
998
}
@@ -991,8 +1045,11 @@ impl Indexer for PhotonIndexer {
991
1045
)
992
1046
. await ?;
993
1047
994
- let api_response =
995
- Self :: extract_result ( "get_compression_signatures_for_token_owner" , result. result ) ?;
1048
+ let api_response = Self :: extract_result_with_error_check (
1049
+ "get_compression_signatures_for_token_owner" ,
1050
+ result. error ,
1051
+ result. result . map ( |r| * r) ,
1052
+ ) ?;
996
1053
if api_response. context . slot < config. slot {
997
1054
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
998
1055
}
@@ -1032,7 +1089,11 @@ impl Indexer for PhotonIndexer {
1032
1089
)
1033
1090
. await ?;
1034
1091
1035
- let _api_response = Self :: extract_result ( "get_indexer_health" , result. result ) ?;
1092
+ let _api_response = Self :: extract_result_with_error_check (
1093
+ "get_indexer_health" ,
1094
+ result. error ,
1095
+ result. result ,
1096
+ ) ?;
1036
1097
1037
1098
Ok ( true )
1038
1099
} )
@@ -1050,7 +1111,11 @@ impl Indexer for PhotonIndexer {
1050
1111
photon_api:: apis:: default_api:: get_indexer_slot_post ( & self . configuration , request)
1051
1112
. await ?;
1052
1113
1053
- let result = Self :: extract_result ( "get_indexer_slot" , result. result ) ?;
1114
+ let result = Self :: extract_result_with_error_check (
1115
+ "get_indexer_slot" ,
1116
+ result. error ,
1117
+ result. result ,
1118
+ ) ?;
1054
1119
Ok ( result)
1055
1120
} )
1056
1121
. await
@@ -1167,8 +1232,11 @@ impl Indexer for PhotonIndexer {
1167
1232
)
1168
1233
. await ?;
1169
1234
1170
- let api_response =
1171
- Self :: extract_result ( "get_multiple_compressed_accounts" , result. result ) ?;
1235
+ let api_response = Self :: extract_result_with_error_check (
1236
+ "get_multiple_compressed_accounts" ,
1237
+ result. error ,
1238
+ result. result . map ( |r| * r) ,
1239
+ ) ?;
1172
1240
if api_response. context . slot < config. slot {
1173
1241
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
1174
1242
}
@@ -1223,14 +1291,17 @@ impl Indexer for PhotonIndexer {
1223
1291
1224
1292
let result = result?;
1225
1293
1226
- let api_response =
1227
- match Self :: extract_result ( "get_multiple_new_address_proofs" , result. result ) {
1228
- Ok ( proofs) => proofs,
1229
- Err ( e) => {
1230
- error ! ( "Failed to extract proofs: {:?}" , e) ;
1231
- return Err ( e) ;
1232
- }
1233
- } ;
1294
+ let api_response = match Self :: extract_result_with_error_check (
1295
+ "get_multiple_new_address_proofs" ,
1296
+ result. error ,
1297
+ result. result . map ( |r| * r) ,
1298
+ ) {
1299
+ Ok ( proofs) => proofs,
1300
+ Err ( e) => {
1301
+ error ! ( "Failed to extract proofs: {:?}" , e) ;
1302
+ return Err ( e) ;
1303
+ }
1304
+ } ;
1234
1305
if api_response. context . slot < config. slot {
1235
1306
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
1236
1307
}
@@ -1330,7 +1401,11 @@ impl Indexer for PhotonIndexer {
1330
1401
request,
1331
1402
)
1332
1403
. await ?;
1333
- let api_response = Self :: extract_result ( "get_validity_proof_v2" , result. result ) ?;
1404
+ let api_response = Self :: extract_result_with_error_check (
1405
+ "get_validity_proof_v2" ,
1406
+ result. error ,
1407
+ result. result . map ( |r| * r) ,
1408
+ ) ?;
1334
1409
if api_response. context . slot < config. slot {
1335
1410
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
1336
1411
}
@@ -1368,7 +1443,11 @@ impl Indexer for PhotonIndexer {
1368
1443
)
1369
1444
. await ?;
1370
1445
1371
- let api_response = Self :: extract_result ( "get_validity_proof" , result. result ) ?;
1446
+ let api_response = Self :: extract_result_with_error_check (
1447
+ "get_validity_proof" ,
1448
+ result. error ,
1449
+ result. result . map ( |r| * r) ,
1450
+ ) ?;
1372
1451
if api_response. context . slot < config. slot {
1373
1452
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
1374
1453
}
@@ -1392,41 +1471,41 @@ impl Indexer for PhotonIndexer {
1392
1471
& mut self ,
1393
1472
_merkle_tree_pubkey : & Pubkey ,
1394
1473
_zkp_batch_size : u16 ,
1474
+ _start_offset : Option < u64 > ,
1395
1475
_config : Option < IndexerRpcConfig > ,
1396
1476
) -> Result < Response < BatchAddressUpdateIndexerResponse > , IndexerError > {
1397
1477
#[ cfg( not( feature = "v2" ) ) ]
1398
1478
unimplemented ! ( "get_address_queue_with_proofs" ) ;
1399
1479
#[ cfg( feature = "v2" ) ]
1400
1480
{
1401
- println ! ( "v2 get_address_queue_with_proofs" ) ;
1402
1481
let merkle_tree_pubkey = _merkle_tree_pubkey;
1403
1482
let limit = _zkp_batch_size;
1483
+ let start_queue_index = _start_offset;
1404
1484
let config = _config. unwrap_or_default ( ) ;
1405
1485
self . retry ( config. retry_config , || async {
1406
1486
let merkle_tree = Hash :: from_bytes ( merkle_tree_pubkey. to_bytes ( ) . as_ref ( ) ) ?;
1407
1487
let request = photon_api:: models:: GetBatchAddressUpdateInfoPostRequest {
1408
1488
params : Box :: new (
1409
1489
photon_api:: models:: GetBatchAddressUpdateInfoPostRequestParams {
1410
1490
limit,
1411
- start_queue_index : None ,
1491
+ start_queue_index,
1412
1492
tree : merkle_tree. to_base58 ( ) ,
1413
1493
} ,
1414
1494
) ,
1415
1495
..Default :: default ( )
1416
1496
} ;
1417
1497
1418
- println ! ( "request: {:?}" , request) ;
1419
-
1420
1498
let result = photon_api:: apis:: default_api:: get_batch_address_update_info_post (
1421
1499
& self . configuration ,
1422
1500
request,
1423
1501
)
1424
1502
. await ?;
1425
1503
1426
- println ! ( "result: {:?}" , result) ;
1427
-
1428
- let api_response =
1429
- Self :: extract_result ( "get_batch_address_update_info" , result. result ) ?;
1504
+ let api_response = Self :: extract_result_with_error_check (
1505
+ "get_batch_address_update_info" ,
1506
+ result. error ,
1507
+ result. result . map ( |r| * r) ,
1508
+ ) ?;
1430
1509
if api_response. context . slot < config. slot {
1431
1510
return Err ( IndexerError :: IndexerNotSyncedToSlot ) ;
1432
1511
}
0 commit comments