@@ -6,10 +6,7 @@ use crate::{
66} ;
77use borsh:: { BorshDeserialize , BorshSerialize } ;
88use solana_program:: {
9- account_info:: { next_account_info, AccountInfo } ,
10- entrypoint:: ProgramResult ,
11- msg,
12- program_error:: ProgramError ,
9+ account_info:: AccountInfo , entrypoint:: ProgramResult , msg, program_error:: ProgramError ,
1310 pubkey:: Pubkey ,
1411} ;
1512use std:: { collections:: HashSet , net:: Ipv4Addr } ;
@@ -82,11 +79,17 @@ pub fn process_set_result_destination(
8279 accounts : & [ AccountInfo ] ,
8380 args : & SetResultDestinationArgs ,
8481) -> ProgramResult {
85- let accounts_iter = & mut accounts. iter ( ) ;
86-
87- let user_account = next_account_info ( accounts_iter) ?;
88- let payer_account = next_account_info ( accounts_iter) ?;
89- let _system_program = next_account_info ( accounts_iter) ?;
82+ if accounts. len ( ) < 3 {
83+ msg ! ( "Not enough accounts" ) ;
84+ return Err ( ProgramError :: NotEnoughAccountKeys ) ;
85+ }
86+ // Account layout: [user, probe_0..probe_N, payer, system_program]
87+ // Payer and system_program are always the last two accounts (appended by
88+ // execute_transaction in the SDK), with variable-length probe accounts
89+ // between the user and the payer.
90+ let user_account = & accounts[ 0 ] ;
91+ let payer_account = & accounts[ accounts. len ( ) - 2 ] ;
92+ let probe_accounts = & accounts[ 1 ..accounts. len ( ) - 2 ] ;
9093
9194 if !payer_account. is_signer {
9295 msg ! ( "Payer must be a signer" ) ;
@@ -124,18 +127,16 @@ pub fn process_set_result_destination(
124127 }
125128 }
126129
127- // Remaining accounts are the probe accounts to bump target_update_count on.
128- let remaining: Vec < & AccountInfo > = accounts_iter. collect ( ) ;
129- if remaining. len ( ) != unique_probes. len ( ) {
130+ if probe_accounts. len ( ) != unique_probes. len ( ) {
130131 msg ! (
131132 "Expected {} probe accounts, got {}" ,
132133 unique_probes. len( ) ,
133- remaining . len( )
134+ probe_accounts . len( )
134135 ) ;
135136 return Err ( GeolocationError :: TooManyReferencedProbes . into ( ) ) ;
136137 }
137138
138- for probe_account in & remaining {
139+ for probe_account in probe_accounts {
139140 if probe_account. owner != program_id {
140141 msg ! ( "Invalid GeoProbe account owner" ) ;
141142 return Err ( ProgramError :: IllegalOwner ) ;
@@ -155,8 +156,8 @@ pub fn process_set_result_destination(
155156
156157 try_acc_write ( & user, user_account, payer_account, accounts) ?;
157158
158- for probe_account in & remaining {
159- let mut probe = GeoProbe :: try_from ( * probe_account) ?;
159+ for probe_account in probe_accounts {
160+ let mut probe = GeoProbe :: try_from ( probe_account) ?;
160161 probe. target_update_count = probe. target_update_count . wrapping_add ( 1 ) ; // Probe uses change in this value to check for updates.
161162 try_acc_write ( & probe, probe_account, payer_account, accounts) ?;
162163 }
0 commit comments