Skip to content

Commit

Permalink
simulateTransaction now returns the correct error code if accounts ar…
Browse files Browse the repository at this point in the history
…e provided as input
  • Loading branch information
mvines committed Dec 8, 2021
1 parent 8d1e5ac commit 824994d
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
};
Expand Down

0 comments on commit 824994d

Please sign in to comment.