Revert "Revert "simulateTransaction now returns the correct error code if accounts are provided as input (#21715)""

This reverts commit 6deb0a9f5d.
This commit is contained in:
Tyera Eulberg
2021-12-16 14:27:42 -07:00
committed by Tyera Eulberg
parent 93a8fd6a2b
commit df40ede6ea

View File

@ -3223,38 +3223,37 @@ pub mod rpc_full {
return Err(Error::invalid_params("base58 encoding not supported")); return Err(Error::invalid_params("base58 encoding not supported"));
} }
if config_accounts.addresses.len() > post_simulation_accounts.len() { let number_of_accounts = transaction.message.account_keys.len();
if config_accounts.addresses.len() > number_of_accounts {
return Err(Error::invalid_params(format!( return Err(Error::invalid_params(format!(
"Too many accounts provided; max {}", "Too many accounts provided; max {}",
post_simulation_accounts.len() number_of_accounts
))); )));
} }
if result.is_err() {
Some(vec![None; config_accounts.addresses.len()])
} else {
let mut accounts = vec![]; let mut accounts = vec![];
for address_str in config_accounts.addresses { for address_str in config_accounts.addresses {
let address = verify_pubkey(&address_str)?; let address = verify_pubkey(&address_str)?;
accounts.push(if result.is_err() { accounts.push(
None
} else {
(0..transaction.message.account_keys.len())
.position(|i| {
post_simulation_accounts post_simulation_accounts
.get(i) .iter()
.map(|(key, _account)| *key == address) .find(|(key, _account)| key == &address)
.unwrap_or(false) .map(|(pubkey, account)| {
})
.map(|i| {
UiAccount::encode( UiAccount::encode(
&address, pubkey,
&post_simulation_accounts[i].1, account,
accounts_encoding, accounts_encoding,
None, None,
None, None,
) )
}) }),
}); );
} }
Some(accounts) Some(accounts)
}
} else { } else {
None None
}; };