@@ -249,54 +249,50 @@ impl Service {
249
249
}
250
250
}
251
251
252
- fn validate_swap_transaction_instructions (
252
+ async fn validate_swap_transaction_instructions (
253
253
& self ,
254
254
tx : & VersionedTransaction ,
255
255
user_wallet : & Pubkey ,
256
256
) -> Result < ( ) , RestError > {
257
- let accounts = tx. message . static_account_keys ( ) ;
258
- tx. message
259
- . instructions ( )
260
- . iter ( )
261
- . enumerate ( )
262
- . try_for_each ( |( index, ix) | {
263
- self . validate_swap_transaction_instruction (
264
- ix. program_id ( tx. message . static_account_keys ( ) ) ,
265
- ix,
266
- user_wallet,
267
- accounts,
268
- )
269
- . map_err ( |e| RestError :: InvalidInstruction ( Some ( index) , e) )
270
- } ) ?;
271
-
257
+ for ( index, ix) in tx. message . instructions ( ) . iter ( ) . enumerate ( ) {
258
+ self . validate_swap_transaction_instruction (
259
+ ix. program_id ( tx. message . static_account_keys ( ) ) ,
260
+ ix,
261
+ tx,
262
+ user_wallet,
263
+ index,
264
+ )
265
+ . await ?;
266
+ }
272
267
Ok ( ( ) )
273
268
}
274
269
275
270
/// Checks if the instruction provided meets the criteria for validity.
276
271
/// Instruction must either be an approved program instruction or not contain the user wallet in its accounts.
277
- fn validate_swap_transaction_instruction (
272
+ async fn validate_swap_transaction_instruction (
278
273
& self ,
279
274
program_id : & Pubkey ,
280
275
ix : & CompiledInstruction ,
276
+ tx : & VersionedTransaction ,
281
277
user_wallet : & Pubkey ,
282
- accounts : & [ Pubkey ] ,
283
- ) -> Result < ( ) , InstructionError > {
278
+ ix_index : usize ,
279
+ ) -> Result < ( ) , RestError > {
284
280
if self
285
281
. check_approved_program_instruction ( program_id, ix)
286
282
. is_ok ( )
287
283
{
288
284
Ok ( ( ) )
289
285
} else {
290
- ix. accounts . iter ( ) . try_for_each ( |i| {
291
- if accounts
292
- . get ( * i as usize )
293
- . expect ( "account index out of bounds" )
294
- == user_wallet
295
- {
296
- return Err ( InstructionError :: UnsupportedInvocationOfUserWallet ) ;
286
+ // TODO: this loop will be slow and invoke many rpc calls if there are many lookup accounts. either parallelize this extraction or limit number of lookup accounts
287
+ for i in 0 ..ix. accounts . len ( ) {
288
+ let account_key = self . extract_account ( tx, ix, i) . await ?;
289
+ if account_key == * user_wallet {
290
+ return Err ( RestError :: InvalidInstruction (
291
+ Some ( ix_index) ,
292
+ InstructionError :: UnsupportedInvocationOfUserWallet ,
293
+ ) ) ;
297
294
}
298
- Ok ( ( ) )
299
- } ) ?;
295
+ }
300
296
301
297
Ok ( ( ) )
302
298
}
@@ -1097,7 +1093,8 @@ impl Service {
1097
1093
self . validate_swap_transaction_instructions (
1098
1094
bid_chain_data_create_svm. get_transaction ( ) ,
1099
1095
& user_wallet,
1100
- ) ?;
1096
+ )
1097
+ . await ?;
1101
1098
let quote_tokens = get_swap_quote_tokens ( & opp) ;
1102
1099
let opportunity_swap_data = get_opportunity_swap_data ( & opp) ;
1103
1100
self . check_svm_swap_bid_fields ( bid_data, opportunity_swap_data, & quote_tokens)
0 commit comments