1
- use std:: { fmt:: Debug , str :: FromStr , time:: Duration } ;
1
+ use std:: { fmt:: Debug , time:: Duration } ;
2
2
3
3
use async_trait:: async_trait;
4
4
use bs58;
5
5
use light_compressed_account:: compressed_account:: {
6
6
CompressedAccount , CompressedAccountData , CompressedAccountWithMerkleContext , MerkleContext ,
7
7
} ;
8
8
use light_merkle_tree_metadata:: QueueType ;
9
- use light_sdk:: token:: { AccountState , TokenData , TokenDataWithMerkleContext } ;
9
+ use light_sdk:: token:: TokenDataWithMerkleContext ;
10
10
use photon_api:: {
11
11
apis:: configuration:: { ApiKey , Configuration } ,
12
- models:: {
13
- Account , GetCompressedAccountsByOwnerPostRequestParams ,
14
- GetCompressedTokenAccountsByOwnerPostRequestParams ,
15
- GetCompressedTokenAccountsByOwnerV2PostRequest , TokenBalanceList ,
16
- } ,
12
+ models:: { GetCompressedAccountsByOwnerPostRequestParams , TokenBalanceList } ,
17
13
} ;
18
14
use solana_pubkey:: Pubkey ;
19
15
use tracing:: { debug, error, warn} ;
20
16
21
17
use super :: {
22
- AddressQueueIndex , BatchAddressUpdateIndexerResponse , MerkleProofWithContext , ProofRpcResult ,
18
+ types :: Account , BatchAddressUpdateIndexerResponse , MerkleProofWithContext , ProofRpcResult ,
23
19
} ;
24
20
use crate :: indexer:: {
25
- Address , AddressWithTree , Base58Conversions , FromPhotonTokenAccountList , Hash , Indexer ,
26
- IndexerError , MerkleProof , NewAddressProofWithContext ,
21
+ tree_info:: QUEUE_TREE_MAPPING , Address , AddressWithTree , Base58Conversions ,
22
+ FromPhotonTokenAccountList , Hash , Indexer , IndexerError , MerkleProof ,
23
+ NewAddressProofWithContext ,
27
24
} ;
28
25
29
26
pub struct PhotonIndexer {
@@ -239,6 +236,65 @@ impl Indexer for PhotonIndexer {
239
236
. await
240
237
}
241
238
239
+ async fn get_compressed_accounts_by_owner (
240
+ & self ,
241
+ owner : & Pubkey ,
242
+ ) -> Result < Vec < CompressedAccountWithMerkleContext > , IndexerError > {
243
+ self . retry ( || async {
244
+ let request = photon_api:: models:: GetCompressedAccountsByOwnerPostRequest {
245
+ params : Box :: from ( GetCompressedAccountsByOwnerPostRequestParams {
246
+ cursor : None ,
247
+ data_slice : None ,
248
+ filters : None ,
249
+ limit : None ,
250
+ owner : owner. to_string ( ) ,
251
+ } ) ,
252
+ ..Default :: default ( )
253
+ } ;
254
+ let result = photon_api:: apis:: default_api:: get_compressed_accounts_by_owner_post (
255
+ & self . configuration ,
256
+ request,
257
+ )
258
+ . await ?;
259
+ let accs = result. result . ok_or ( IndexerError :: AccountNotFound ) ?. value ;
260
+ let mut accounts: Vec < CompressedAccountWithMerkleContext > = Vec :: new ( ) ;
261
+
262
+ for acc in accs. items {
263
+ let compressed_account = CompressedAccount {
264
+ owner : Pubkey :: from ( Hash :: from_base58 ( & acc. owner ) ?) ,
265
+ lamports : acc. lamports ,
266
+ address : acc
267
+ . address
268
+ . map ( |address| Hash :: from_base58 ( & address) . unwrap ( ) ) ,
269
+ data : acc. data . map ( |data| CompressedAccountData {
270
+ discriminator : data. discriminator . to_le_bytes ( ) ,
271
+ data : base64:: decode ( data. data ) . unwrap ( ) ,
272
+ data_hash : Hash :: from_base58 ( & data. data_hash ) . unwrap ( ) ,
273
+ } ) ,
274
+ } ;
275
+ let tree_info = QUEUE_TREE_MAPPING
276
+ . get ( & acc. tree )
277
+ . ok_or ( IndexerError :: InvalidResponseData ) ?;
278
+ let merkle_context = MerkleContext {
279
+ merkle_tree_pubkey : tree_info. tree ,
280
+ queue_pubkey : tree_info. queue ,
281
+ leaf_index : acc. leaf_index ,
282
+ tree_type : tree_info. tree_type ,
283
+ prove_by_index : false ,
284
+ } ;
285
+
286
+ let account = CompressedAccountWithMerkleContext {
287
+ compressed_account,
288
+ merkle_context,
289
+ } ;
290
+ accounts. push ( account) ;
291
+ }
292
+
293
+ Ok ( accounts)
294
+ } )
295
+ . await
296
+ }
297
+
242
298
async fn get_compressed_accounts_by_owner_v2 (
243
299
& self ,
244
300
_owner : & Pubkey ,
@@ -265,8 +321,7 @@ impl Indexer for PhotonIndexer {
265
321
request,
266
322
)
267
323
. await ?;
268
-
269
- let accs = result. result . unwrap ( ) . value ;
324
+ let accs = result. result . ok_or ( IndexerError :: AccountNotFound ) ?. value ;
270
325
let mut accounts: Vec < CompressedAccountWithMerkleContext > = Vec :: new ( ) ;
271
326
272
327
for acc in accs. items {
@@ -277,8 +332,8 @@ impl Indexer for PhotonIndexer {
277
332
. address
278
333
. map ( |address| Hash :: from_base58 ( & address) . unwrap ( ) ) ,
279
334
data : acc. data . map ( |data| CompressedAccountData {
280
- discriminator : data. discriminator . to_be_bytes ( ) ,
281
- data : data. data . as_bytes ( ) . to_vec ( ) ,
335
+ discriminator : data. discriminator . to_le_bytes ( ) ,
336
+ data : base64 :: decode ( data. data ) . unwrap ( ) ,
282
337
data_hash : Hash :: from_base58 ( & data. data_hash ) . unwrap ( ) ,
283
338
} ) ,
284
339
} ;
@@ -320,16 +375,19 @@ impl Indexer for PhotonIndexer {
320
375
unimplemented ! ( "get_compressed_token_accounts_by_owner_v2" ) ;
321
376
#[ cfg( feature = "v2" ) ]
322
377
{
378
+ use std:: str:: FromStr ;
323
379
let owner = _owner;
324
380
let mint = _mint;
325
381
self . retry ( || async {
326
- let request = GetCompressedTokenAccountsByOwnerV2PostRequest {
327
- params : Box :: from ( GetCompressedTokenAccountsByOwnerPostRequestParams {
328
- cursor : None ,
329
- limit : None ,
330
- mint : mint. map ( |x| x. to_string ( ) ) ,
331
- owner : owner. to_string ( ) ,
332
- } ) ,
382
+ let request = photon_api:: models:: GetCompressedTokenAccountsByOwnerV2PostRequest {
383
+ params : Box :: from (
384
+ photon_api:: models:: GetCompressedTokenAccountsByOwnerPostRequestParams {
385
+ cursor : None ,
386
+ limit : None ,
387
+ mint : mint. map ( |x| x. to_string ( ) ) ,
388
+ owner : owner. to_string ( ) ,
389
+ } ,
390
+ ) ,
333
391
..Default :: default ( )
334
392
} ;
335
393
let result =
@@ -344,7 +402,7 @@ impl Indexer for PhotonIndexer {
344
402
let mut token_data: Vec < TokenDataWithMerkleContext > = Vec :: new ( ) ;
345
403
for account in accounts. items . iter ( ) {
346
404
let token_data_with_merkle_context = TokenDataWithMerkleContext {
347
- token_data : TokenData {
405
+ token_data : light_sdk :: token :: TokenData {
348
406
mint : Pubkey :: from_str ( & account. token_data . mint ) . unwrap ( ) ,
349
407
owner : Pubkey :: from_str ( & account. token_data . owner ) . unwrap ( ) ,
350
408
amount : account. token_data . amount ,
@@ -356,9 +414,9 @@ impl Indexer for PhotonIndexer {
356
414
state : if account. token_data . state
357
415
== photon_api:: models:: account_state:: AccountState :: Initialized
358
416
{
359
- AccountState :: Initialized
417
+ light_sdk :: token :: AccountState :: Initialized
360
418
} else {
361
- AccountState :: Frozen
419
+ light_sdk :: token :: AccountState :: Frozen
362
420
} ,
363
421
tlv : None ,
364
422
} ,
@@ -423,10 +481,11 @@ impl Indexer for PhotonIndexer {
423
481
)
424
482
. await ?;
425
483
let response = Self :: extract_result ( "get_compressed_account" , result. result ) ?;
426
- response
484
+ let response = response
427
485
. value
428
486
. ok_or ( IndexerError :: AccountNotFound )
429
- . map ( |boxed| * boxed)
487
+ . map ( |boxed| * boxed) ?;
488
+ Account :: try_from ( & response)
430
489
} )
431
490
. await
432
491
}
@@ -539,7 +598,12 @@ impl Indexer for PhotonIndexer {
539
598
. await ?;
540
599
541
600
let response = Self :: extract_result ( "get_multiple_compressed_accounts" , result. result ) ?;
542
- Ok ( response. value . items )
601
+ response
602
+ . value
603
+ . items
604
+ . iter ( )
605
+ . map ( Account :: try_from)
606
+ . collect :: < Result < Vec < Account > , IndexerError > > ( )
543
607
} )
544
608
. await
545
609
}
@@ -753,13 +817,15 @@ impl Indexer for PhotonIndexer {
753
817
754
818
async fn get_validity_proof_v2 (
755
819
& self ,
756
- hashes : Vec < Hash > ,
757
- new_addresses_with_trees : Vec < AddressWithTree > ,
820
+ _hashes : Vec < Hash > ,
821
+ _new_addresses_with_trees : Vec < AddressWithTree > ,
758
822
) -> Result < super :: types:: ProofRpcResultV2 , IndexerError > {
759
823
#[ cfg( not( feature = "v2" ) ) ]
760
824
unimplemented ! ( "get_validity_proof_v2" ) ;
761
825
#[ cfg( feature = "v2" ) ]
762
826
{
827
+ let hashes = _hashes;
828
+ let new_addresses_with_trees = _new_addresses_with_trees;
763
829
self . retry ( || async {
764
830
let request = photon_api:: models:: GetValidityProofV2PostRequest {
765
831
params : Box :: new ( photon_api:: models:: GetValidityProofPostRequestParams {
@@ -823,7 +889,7 @@ impl Indexer for PhotonIndexer {
823
889
let addresses = response
824
890
. addresses
825
891
. iter ( )
826
- . map ( |x| AddressQueueIndex {
892
+ . map ( |x| crate :: indexer :: AddressQueueIndex {
827
893
address : Hash :: from_base58 ( x. address . clone ( ) . as_ref ( ) ) . unwrap ( ) ,
828
894
queue_index : x. queue_index ,
829
895
} )
@@ -884,15 +950,19 @@ impl Indexer for PhotonIndexer {
884
950
885
951
async fn get_queue_elements (
886
952
& mut self ,
887
- pubkey : [ u8 ; 32 ] ,
888
- queue_type : QueueType ,
889
- num_elements : u16 ,
890
- start_offset : Option < u64 > ,
953
+ _pubkey : [ u8 ; 32 ] ,
954
+ _queue_type : QueueType ,
955
+ _num_elements : u16 ,
956
+ _start_offset : Option < u64 > ,
891
957
) -> Result < Vec < MerkleProofWithContext > , IndexerError > {
892
958
#[ cfg( not( feature = "v2" ) ) ]
893
959
unimplemented ! ( "get_queue_elements" ) ;
894
960
#[ cfg( feature = "v2" ) ]
895
961
{
962
+ let pubkey = _pubkey;
963
+ let queue_type = _queue_type;
964
+ let num_elements = _num_elements;
965
+ let start_offset = _start_offset;
896
966
self . retry ( || async {
897
967
let request: photon_api:: models:: GetQueueElementsPostRequest =
898
968
photon_api:: models:: GetQueueElementsPostRequest {
0 commit comments