simulateTransaction now returns the correct error code if accounts are provided as input

This commit is contained in:
Michael Vines 2021-12-08 10:42:13 -08:00
parent 8d1e5ac294
commit 824994db69
1 changed files with 25 additions and 16 deletions

View File

@ -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
};