@@ -5,7 +5,6 @@ use anchor_lang::prelude::declare_program;
55use anchor_spl:: associated_token;
66use anyhow:: { anyhow, Context , Result } ;
77use chrono:: Utc ;
8- use log:: info;
98use num:: BigUint ;
109use solana_client:: nonblocking:: rpc_client:: RpcClient ;
1110use solana_client:: rpc_config:: RpcTransactionConfig ;
@@ -25,6 +24,7 @@ use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta;
2524use spl_associated_token_account:: get_associated_token_address_with_program_id;
2625use spl_associated_token_account:: instruction:: create_associated_token_account_idempotent;
2726use spl_token:: instruction:: transfer;
27+ use tracing:: { info, instrument} ;
2828
2929use crate :: { random_intent_id, retry} ;
3030
@@ -54,6 +54,7 @@ impl TxInstructions {
5454 }
5555}
5656
57+ #[ instrument( skip_all) ]
5758pub async fn escrow_funds (
5859 client : & RpcClient ,
5960 payer : Arc < Keypair > ,
@@ -76,9 +77,11 @@ pub async fn escrow_funds(
7677 let timeout = timestamp + timeout_sec;
7778 let intent_id = random_intent_id ( ) ;
7879
79- let token_in_mint = ( token_in == Pubkey :: default ( ) )
80- . then_some ( spl_token:: native_mint:: ID )
81- . unwrap_or ( token_in) ;
80+ let token_in_mint = if token_in == Pubkey :: default ( ) {
81+ spl_token:: native_mint:: ID
82+ } else {
83+ token_in
84+ } ;
8285
8386 let ( escrow_pda, _) = Pubkey :: find_program_address ( & [ ESCROW_SEED ] , & program_id) ;
8487 let ( escrow_sol_pda, _) = Pubkey :: find_program_address ( & [ ESCROW_SEED , SOL_SEED ] , & program_id) ;
@@ -139,7 +142,11 @@ pub async fn escrow_funds(
139142 . args ( escrow_args)
140143 . instructions ( ) ?;
141144
142- let recent_blockhash = retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?;
145+ let recent_blockhash = retry (
146+ || client. get_latest_blockhash ( ) ,
147+ 3 ,
148+ )
149+ . await ?;
143150
144151 let escrow_transaction = Transaction :: new_signed_with_payer (
145152 & escrow_instructions,
@@ -148,10 +155,15 @@ pub async fn escrow_funds(
148155 recent_blockhash,
149156 ) ;
150157
151- let signature = retry ( || client. send_and_confirm_transaction ( & escrow_transaction) , 3 ) . await ?;
158+ let signature = retry (
159+ || client. send_and_confirm_transaction ( & escrow_transaction) ,
160+ 3 ,
161+ )
162+ . await ?;
152163 Ok ( signature)
153164}
154165
166+ #[ instrument( skip_all) ]
155167pub async fn cancel_intent (
156168 client : & RpcClient ,
157169 payer : Arc < Keypair > ,
@@ -202,7 +214,11 @@ pub async fn cancel_intent(
202214 . args ( cancel_args)
203215 . instructions ( ) ?;
204216
205- let recent_blockhash = retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?;
217+ let recent_blockhash = retry (
218+ || client. get_latest_blockhash ( ) ,
219+ 3 ,
220+ )
221+ . await ?;
206222
207223 let cancel_transaction = Transaction :: new_signed_with_payer (
208224 & cancel_instructions,
@@ -211,10 +227,15 @@ pub async fn cancel_intent(
211227 recent_blockhash,
212228 ) ;
213229
214- let signature = retry ( || client. send_and_confirm_transaction ( & cancel_transaction) , 3 ) . await ?;
230+ let signature = retry (
231+ || client. send_and_confirm_transaction ( & cancel_transaction) ,
232+ 3 ,
233+ )
234+ . await ?;
215235 Ok ( signature)
216236}
217237
238+ #[ instrument( skip_all) ]
218239pub async fn initialize ( client : & RpcClient , payer : Arc < Keypair > , program_id : Pubkey ) -> Result < Signature > {
219240 let cluster = Cluster :: Custom ( client. url ( ) , String :: default ( ) ) ;
220241 let client_anchor = Client :: new_with_options ( cluster, payer. clone ( ) , CommitmentConfig :: processed ( ) ) ;
@@ -243,7 +264,11 @@ pub async fn initialize(client: &RpcClient, payer: Arc<Keypair>, program_id: Pub
243264 . args ( initialize_args)
244265 . instructions ( ) ?;
245266
246- let recent_blockhash = retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?;
267+ let recent_blockhash = retry (
268+ || client. get_latest_blockhash ( ) ,
269+ 3 ,
270+ )
271+ . await ?;
247272
248273 let initialize_tx = Transaction :: new_signed_with_payer (
249274 & initialize_ix,
@@ -252,10 +277,15 @@ pub async fn initialize(client: &RpcClient, payer: Arc<Keypair>, program_id: Pub
252277 recent_blockhash,
253278 ) ;
254279
255- let signature = retry ( || client. send_and_confirm_transaction ( & initialize_tx) , 3 ) . await ?;
280+ let signature = retry (
281+ || client. send_and_confirm_transaction ( & initialize_tx) ,
282+ 3 ,
283+ )
284+ . await ?;
256285 Ok ( signature)
257286}
258287
288+ #[ instrument( skip_all) ]
259289pub async fn create_associated_token_account (
260290 client : & RpcClient ,
261291 payer : Arc < Keypair > ,
@@ -265,7 +295,11 @@ pub async fn create_associated_token_account(
265295 let ( create_associated_account_ix, ata) =
266296 create_associated_token_account_ix ( client, payer. clone ( ) , user, token_mint) . await ?;
267297
268- let recent_blockhash = retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?;
298+ let recent_blockhash = retry (
299+ || client. get_latest_blockhash ( ) ,
300+ 3 ,
301+ )
302+ . await ?;
269303
270304 let create_associated_account_tx = Transaction :: new_signed_with_payer (
271305 & [ create_associated_account_ix] ,
@@ -299,6 +333,7 @@ pub async fn create_associated_token_account_ix(
299333 Ok ( ( instructions, ata) )
300334}
301335
336+ #[ instrument( skip_all) ]
302337pub async fn get_transaction_info (
303338 client : & RpcClient ,
304339 signature : Signature ,
@@ -308,16 +343,25 @@ pub async fn get_transaction_info(
308343 commitment : Some ( CommitmentConfig :: confirmed ( ) ) ,
309344 max_supported_transaction_version : Some ( 0 ) ,
310345 } ;
311- let transaction_info = retry ( || client. get_transaction_with_config ( & signature, config) , 3 ) . await ?;
346+ let transaction_info = retry (
347+ || client. get_transaction_with_config ( & signature, config) ,
348+ 3 ,
349+ )
350+ . await ?;
312351
313352 Ok ( transaction_info)
314353}
315354
355+ #[ instrument( skip_all) ]
316356pub async fn get_lookup_table_accounts (
317357 client : & RpcClient ,
318358 lookup_table_addresses : & [ Pubkey ] ,
319359) -> Result < Vec < AddressLookupTableAccount > > {
320- let lookup_table_accounts = retry ( || client. get_multiple_accounts ( lookup_table_addresses) , 3 ) . await ?;
360+ let lookup_table_accounts = retry (
361+ || client. get_multiple_accounts ( lookup_table_addresses) ,
362+ 3 ,
363+ )
364+ . await ?;
321365
322366 lookup_table_addresses
323367 . iter ( )
@@ -334,6 +378,7 @@ pub async fn get_lookup_table_accounts(
334378 . collect ( )
335379}
336380
381+ #[ instrument( skip_all) ]
337382pub async fn transfer_spl_token (
338383 client : & RpcClient ,
339384 sender : Arc < Keypair > ,
@@ -344,7 +389,11 @@ pub async fn transfer_spl_token(
344389 let transfer_spl_token_ix =
345390 transfer_spl_token_ix ( client, sender. clone ( ) , recipient, token_mint, amount) . await ?;
346391
347- let recent_blockhash = retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?;
392+ let recent_blockhash = retry (
393+ || client. get_latest_blockhash ( ) ,
394+ 3 ,
395+ )
396+ . await ?;
348397
349398 let transfer_spl_token_tx = Transaction :: new_signed_with_payer (
350399 & transfer_spl_token_ix,
@@ -353,7 +402,11 @@ pub async fn transfer_spl_token(
353402 recent_blockhash,
354403 ) ;
355404
356- let signature = retry ( || client. send_and_confirm_transaction ( & transfer_spl_token_tx) , 3 ) . await ?;
405+ let signature = retry (
406+ || client. send_and_confirm_transaction ( & transfer_spl_token_tx) ,
407+ 3 ,
408+ )
409+ . await ?;
357410 Ok ( signature)
358411}
359412
@@ -393,6 +446,7 @@ pub async fn transfer_spl_token_ix(
393446 Ok ( transfer_instructions)
394447}
395448
449+ #[ instrument( skip_all) ]
396450pub async fn submit_through_rpc (
397451 client : & RpcClient ,
398452 payer : Arc < Keypair > ,
@@ -404,25 +458,40 @@ pub async fn submit_through_rpc(
404458 & transaction. instructions ,
405459 Some ( & payer. pubkey ( ) ) ,
406460 & [ & * payer] ,
407- retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?,
461+ retry (
462+ || client. get_latest_blockhash ( ) ,
463+ 3 ,
464+ )
465+ . await ?,
408466 ) ;
409- retry ( || client. send_and_confirm_transaction ( & transaction) , 3 )
410- . await
411- . context ( "Failed to send legacy transaction" )
467+ retry (
468+ || client. send_and_confirm_transaction ( & transaction) ,
469+ 3 ,
470+ )
471+ . await
472+ . context ( "Failed to send legacy transaction" )
412473 } else {
413474 let message = v0:: Message :: try_compile (
414475 & payer. pubkey ( ) ,
415476 & transaction. instructions ,
416477 & transaction. address_lookup_table ,
417- retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?,
478+ retry (
479+ || client. get_latest_blockhash ( ) ,
480+ 3 ,
481+ )
482+ . await ?,
418483 ) ?;
419484 let transaction = VersionedTransaction :: try_new ( VersionedMessage :: V0 ( message) , & [ & payer] ) ?;
420- retry ( || client. send_and_confirm_transaction ( & transaction) , 3 )
421- . await
422- . context ( "Failed to send versioned transaction" )
485+ retry (
486+ || client. send_and_confirm_transaction ( & transaction) ,
487+ 3 ,
488+ )
489+ . await
490+ . context ( "Failed to send versioned transaction" )
423491 }
424492}
425493
494+ #[ instrument( skip_all) ]
426495pub async fn submit_through_rpc_multiple (
427496 client : & RpcClient ,
428497 payer : Arc < Keypair > ,
@@ -446,8 +515,14 @@ pub async fn submit_through_rpc_multiple(
446515 Ok ( signatures)
447516}
448517
518+ #[ instrument( skip_all) ]
449519pub async fn get_token_program_id ( client : & RpcClient , token_mint : & Pubkey ) -> Result < Pubkey > {
450- match retry ( || client. get_account ( token_mint) , 3 ) . await ? {
520+ match retry (
521+ || client. get_account ( token_mint) ,
522+ 3 ,
523+ )
524+ . await ?
525+ {
451526 account if account. owner == spl_token_2022:: ID => Ok ( spl_token_2022:: ID ) ,
452527 account if account. owner == spl_token:: ID => Ok ( spl_token:: ID ) ,
453528 _ => Err ( anyhow ! ( "Failed to get token program ID for token {}" , token_mint) ) ,
0 commit comments