@@ -5,7 +5,6 @@ use anchor_lang::prelude::declare_program;
5
5
use anchor_spl:: associated_token;
6
6
use anyhow:: { anyhow, Context , Result } ;
7
7
use chrono:: Utc ;
8
- use log:: info;
9
8
use num:: BigUint ;
10
9
use solana_client:: nonblocking:: rpc_client:: RpcClient ;
11
10
use solana_client:: rpc_config:: RpcTransactionConfig ;
@@ -25,6 +24,7 @@ use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta;
25
24
use spl_associated_token_account:: get_associated_token_address_with_program_id;
26
25
use spl_associated_token_account:: instruction:: create_associated_token_account_idempotent;
27
26
use spl_token:: instruction:: transfer;
27
+ use tracing:: { info, instrument} ;
28
28
29
29
use crate :: { random_intent_id, retry} ;
30
30
@@ -54,6 +54,7 @@ impl TxInstructions {
54
54
}
55
55
}
56
56
57
+ #[ instrument( skip_all) ]
57
58
pub async fn escrow_funds (
58
59
client : & RpcClient ,
59
60
payer : Arc < Keypair > ,
@@ -76,9 +77,11 @@ pub async fn escrow_funds(
76
77
let timeout = timestamp + timeout_sec;
77
78
let intent_id = random_intent_id ( ) ;
78
79
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
+ } ;
82
85
83
86
let ( escrow_pda, _) = Pubkey :: find_program_address ( & [ ESCROW_SEED ] , & program_id) ;
84
87
let ( escrow_sol_pda, _) = Pubkey :: find_program_address ( & [ ESCROW_SEED , SOL_SEED ] , & program_id) ;
@@ -139,7 +142,11 @@ pub async fn escrow_funds(
139
142
. args ( escrow_args)
140
143
. instructions ( ) ?;
141
144
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 ?;
143
150
144
151
let escrow_transaction = Transaction :: new_signed_with_payer (
145
152
& escrow_instructions,
@@ -148,10 +155,15 @@ pub async fn escrow_funds(
148
155
recent_blockhash,
149
156
) ;
150
157
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 ?;
152
163
Ok ( signature)
153
164
}
154
165
166
+ #[ instrument( skip_all) ]
155
167
pub async fn cancel_intent (
156
168
client : & RpcClient ,
157
169
payer : Arc < Keypair > ,
@@ -202,7 +214,11 @@ pub async fn cancel_intent(
202
214
. args ( cancel_args)
203
215
. instructions ( ) ?;
204
216
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 ?;
206
222
207
223
let cancel_transaction = Transaction :: new_signed_with_payer (
208
224
& cancel_instructions,
@@ -211,10 +227,15 @@ pub async fn cancel_intent(
211
227
recent_blockhash,
212
228
) ;
213
229
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 ?;
215
235
Ok ( signature)
216
236
}
217
237
238
+ #[ instrument( skip_all) ]
218
239
pub async fn initialize ( client : & RpcClient , payer : Arc < Keypair > , program_id : Pubkey ) -> Result < Signature > {
219
240
let cluster = Cluster :: Custom ( client. url ( ) , String :: default ( ) ) ;
220
241
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
243
264
. args ( initialize_args)
244
265
. instructions ( ) ?;
245
266
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 ?;
247
272
248
273
let initialize_tx = Transaction :: new_signed_with_payer (
249
274
& initialize_ix,
@@ -252,10 +277,15 @@ pub async fn initialize(client: &RpcClient, payer: Arc<Keypair>, program_id: Pub
252
277
recent_blockhash,
253
278
) ;
254
279
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 ?;
256
285
Ok ( signature)
257
286
}
258
287
288
+ #[ instrument( skip_all) ]
259
289
pub async fn create_associated_token_account (
260
290
client : & RpcClient ,
261
291
payer : Arc < Keypair > ,
@@ -265,7 +295,11 @@ pub async fn create_associated_token_account(
265
295
let ( create_associated_account_ix, ata) =
266
296
create_associated_token_account_ix ( client, payer. clone ( ) , user, token_mint) . await ?;
267
297
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 ?;
269
303
270
304
let create_associated_account_tx = Transaction :: new_signed_with_payer (
271
305
& [ create_associated_account_ix] ,
@@ -299,6 +333,7 @@ pub async fn create_associated_token_account_ix(
299
333
Ok ( ( instructions, ata) )
300
334
}
301
335
336
+ #[ instrument( skip_all) ]
302
337
pub async fn get_transaction_info (
303
338
client : & RpcClient ,
304
339
signature : Signature ,
@@ -308,16 +343,25 @@ pub async fn get_transaction_info(
308
343
commitment : Some ( CommitmentConfig :: confirmed ( ) ) ,
309
344
max_supported_transaction_version : Some ( 0 ) ,
310
345
} ;
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 ?;
312
351
313
352
Ok ( transaction_info)
314
353
}
315
354
355
+ #[ instrument( skip_all) ]
316
356
pub async fn get_lookup_table_accounts (
317
357
client : & RpcClient ,
318
358
lookup_table_addresses : & [ Pubkey ] ,
319
359
) -> 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 ?;
321
365
322
366
lookup_table_addresses
323
367
. iter ( )
@@ -334,6 +378,7 @@ pub async fn get_lookup_table_accounts(
334
378
. collect ( )
335
379
}
336
380
381
+ #[ instrument( skip_all) ]
337
382
pub async fn transfer_spl_token (
338
383
client : & RpcClient ,
339
384
sender : Arc < Keypair > ,
@@ -344,7 +389,11 @@ pub async fn transfer_spl_token(
344
389
let transfer_spl_token_ix =
345
390
transfer_spl_token_ix ( client, sender. clone ( ) , recipient, token_mint, amount) . await ?;
346
391
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 ?;
348
397
349
398
let transfer_spl_token_tx = Transaction :: new_signed_with_payer (
350
399
& transfer_spl_token_ix,
@@ -353,7 +402,11 @@ pub async fn transfer_spl_token(
353
402
recent_blockhash,
354
403
) ;
355
404
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 ?;
357
410
Ok ( signature)
358
411
}
359
412
@@ -393,6 +446,7 @@ pub async fn transfer_spl_token_ix(
393
446
Ok ( transfer_instructions)
394
447
}
395
448
449
+ #[ instrument( skip_all) ]
396
450
pub async fn submit_through_rpc (
397
451
client : & RpcClient ,
398
452
payer : Arc < Keypair > ,
@@ -404,25 +458,40 @@ pub async fn submit_through_rpc(
404
458
& transaction. instructions ,
405
459
Some ( & payer. pubkey ( ) ) ,
406
460
& [ & * payer] ,
407
- retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?,
461
+ retry (
462
+ || client. get_latest_blockhash ( ) ,
463
+ 3 ,
464
+ )
465
+ . await ?,
408
466
) ;
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" )
412
473
} else {
413
474
let message = v0:: Message :: try_compile (
414
475
& payer. pubkey ( ) ,
415
476
& transaction. instructions ,
416
477
& transaction. address_lookup_table ,
417
- retry ( || client. get_latest_blockhash ( ) , 3 ) . await ?,
478
+ retry (
479
+ || client. get_latest_blockhash ( ) ,
480
+ 3 ,
481
+ )
482
+ . await ?,
418
483
) ?;
419
484
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" )
423
491
}
424
492
}
425
493
494
+ #[ instrument( skip_all) ]
426
495
pub async fn submit_through_rpc_multiple (
427
496
client : & RpcClient ,
428
497
payer : Arc < Keypair > ,
@@ -446,8 +515,14 @@ pub async fn submit_through_rpc_multiple(
446
515
Ok ( signatures)
447
516
}
448
517
518
+ #[ instrument( skip_all) ]
449
519
pub 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
+ {
451
526
account if account. owner == spl_token_2022:: ID => Ok ( spl_token_2022:: ID ) ,
452
527
account if account. owner == spl_token:: ID => Ok ( spl_token:: ID ) ,
453
528
_ => Err ( anyhow ! ( "Failed to get token program ID for token {}" , token_mint) ) ,
0 commit comments