From c3f26e88a8116224dfdb7b3f784c2fd6e067a989 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Thu, 7 Nov 2024 14:19:50 -0600 Subject: [PATCH] RuntimeTransaction --- .../runtime_transaction/transaction_view.rs | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/runtime-transaction/src/runtime_transaction/transaction_view.rs b/runtime-transaction/src/runtime_transaction/transaction_view.rs index 2931d638295c3f..8c4ae4a781ba29 100644 --- a/runtime-transaction/src/runtime_transaction/transaction_view.rs +++ b/runtime-transaction/src/runtime_transaction/transaction_view.rs @@ -4,14 +4,16 @@ use { signature_details::get_precompile_signature_details, transaction_meta::TransactionMeta, }, agave_transaction_view::{ - transaction_data::TransactionData, transaction_version::TransactionVersion, - transaction_view::SanitizedTransactionView, + resolved_transaction_view::ResolvedTransactionView, transaction_data::TransactionData, + transaction_version::TransactionVersion, transaction_view::SanitizedTransactionView, }, + solana_pubkey::Pubkey, solana_sdk::{ - message::{TransactionSignatureDetails, VersionedMessage}, + message::{v0::LoadedAddresses, TransactionSignatureDetails, VersionedMessage}, simple_vote_transaction_checker::is_simple_vote_transaction_impl, - transaction::{MessageHash, Result}, + transaction::{MessageHash, Result, TransactionError}, }, + std::collections::HashSet, }; fn is_simple_vote_transaction( @@ -60,3 +62,31 @@ impl RuntimeTransaction> { }) } } + +impl RuntimeTransaction> { + /// Create a new `RuntimeTransaction` from a + /// `RuntimeTransaction` that already has + /// static metadata loaded. + pub fn try_from( + statically_loaded_runtime_tx: RuntimeTransaction>, + loaded_addresses: Option, + reserved_account_keys: &HashSet, + ) -> Result { + let RuntimeTransaction { transaction, meta } = statically_loaded_runtime_tx; + // transaction-view does not distinguish between different types of errors here. + // return generic sanitize failure error here. + // these transactions should be immediately dropped, and we generally + // will not care about the specific error at this point. + let transaction = + ResolvedTransactionView::try_new(transaction, loaded_addresses, reserved_account_keys) + .map_err(|_| TransactionError::SanitizeFailure)?; + let mut tx = Self { transaction, meta }; + tx.load_dynamic_metadata()?; + + Ok(tx) + } + + fn load_dynamic_metadata(&mut self) -> Result<()> { + Ok(()) + } +}