Add (preflight) simulation to BanksClient (#22084) (#22149)

* Add more-legitimate conversion from legacy Transaction to SanitizedTransaction

* Add Banks method with preflight checks

* Expose BanksClient method with preflight checks

* Unwrap simulation err

* Add Bank simulation method that works on unfrozen Banks

* Add simpler api

* Better name: BanksTransactionResultWithSimulation

(cherry picked from commit 422a095647)

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
This commit is contained in:
mergify[bot]
2021-12-28 22:04:27 +00:00
committed by GitHub
parent 810ca36eae
commit adc584ee22
6 changed files with 165 additions and 14 deletions

View File

@@ -76,20 +76,24 @@ impl SanitizedTransaction {
})
}
/// Create a sanitized transaction from a legacy transaction. Used for tests only.
pub fn from_transaction_for_tests(tx: Transaction) -> Self {
tx.sanitize().unwrap();
pub fn try_from_legacy_transaction(tx: Transaction) -> Result<Self> {
tx.sanitize()?;
if tx.message.has_duplicates() {
Result::<Self>::Err(TransactionError::AccountLoadedTwice).unwrap();
return Err(TransactionError::AccountLoadedTwice);
}
Self {
Ok(Self {
message_hash: tx.message.hash(),
message: SanitizedMessage::Legacy(tx.message),
is_simple_vote_tx: false,
signatures: tx.signatures,
}
})
}
/// Create a sanitized transaction from a legacy transaction. Used for tests only.
pub fn from_transaction_for_tests(tx: Transaction) -> Self {
Self::try_from_legacy_transaction(tx).unwrap()
}
/// Return the first signature for this transaction.