diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index e73e9d2b18..7efe81caca 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -3520,6 +3520,7 @@ pub mod rpc_full { if config.sig_verify { verify_transaction(&transaction, &bank.feature_set)?; } + let number_of_accounts = transaction.message().account_keys_len(); let TransactionSimulationResult { result, @@ -3539,28 +3540,36 @@ pub mod rpc_full { return Err(Error::invalid_params("base58 encoding not supported")); } - if config_accounts.addresses.len() > post_simulation_accounts.len() { + if config_accounts.addresses.len() > number_of_accounts { return Err(Error::invalid_params(format!( "Too many accounts provided; max {}", - post_simulation_accounts.len() + number_of_accounts ))); } - let mut accounts = vec![]; - for address_str in config_accounts.addresses { - let address = verify_pubkey(&address_str)?; - accounts.push(if result.is_err() { - None - } else { - post_simulation_accounts - .iter() - .find(|(key, _account)| key == &address) - .map(|(pubkey, account)| { - UiAccount::encode(pubkey, account, accounts_encoding, None, None) - }) - }); + if result.is_err() { + Some(vec![None; config_accounts.addresses.len()]) + } else { + let mut accounts = vec![]; + for address_str in config_accounts.addresses { + let address = verify_pubkey(&address_str)?; + accounts.push( + post_simulation_accounts + .iter() + .find(|(key, _account)| key == &address) + .map(|(pubkey, account)| { + UiAccount::encode( + pubkey, + account, + accounts_encoding, + None, + None, + ) + }), + ); + } + Some(accounts) } - Some(accounts) } else { None };