Skip to content

Commit

Permalink
RuntimeTransactions: implement SVM traits (anza-xyz#2987)
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge authored and ray-kast committed Nov 27, 2024
1 parent fd4cc30 commit 381fb85
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions runtime-transaction/src/runtime_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ use {
solana_sdk::{
feature_set::FeatureSet,
hash::Hash,
message::{AddressLoader, TransactionSignatureDetails},
message::{AccountKeys, AddressLoader, TransactionSignatureDetails},
pubkey::Pubkey,
signature::Signature,
simple_vote_transaction_checker::is_simple_vote_transaction,
transaction::{Result, SanitizedTransaction, SanitizedVersionedTransaction},
},
solana_svm_transaction::instruction::SVMInstruction,
solana_svm_transaction::{
instruction::SVMInstruction, message_address_table_lookup::SVMMessageAddressTableLookup,
svm_message::SVMMessage, svm_transaction::SVMTransaction,
},
std::collections::HashSet,
};

Expand Down Expand Up @@ -153,6 +157,71 @@ impl RuntimeTransaction<SanitizedTransaction> {
}
}

impl<T: SVMMessage> SVMMessage for RuntimeTransaction<T> {
// override to access from the cached meta instead of re-calculating
fn num_total_signatures(&self) -> u64 {
self.meta.signature_details.total_signatures()
}

fn num_write_locks(&self) -> u64 {
self.transaction.num_write_locks()
}

fn recent_blockhash(&self) -> &Hash {
self.transaction.recent_blockhash()
}

fn num_instructions(&self) -> usize {
self.transaction.num_instructions()
}

fn instructions_iter(&self) -> impl Iterator<Item = SVMInstruction> {
self.transaction.instructions_iter()
}

fn program_instructions_iter(&self) -> impl Iterator<Item = (&Pubkey, SVMInstruction)> {
self.transaction.program_instructions_iter()
}

fn account_keys(&self) -> AccountKeys {
self.transaction.account_keys()
}

fn fee_payer(&self) -> &Pubkey {
self.transaction.fee_payer()
}

fn is_writable(&self, index: usize) -> bool {
self.transaction.is_writable(index)
}

fn is_signer(&self, index: usize) -> bool {
self.transaction.is_signer(index)
}

fn is_invoked(&self, key_index: usize) -> bool {
self.transaction.is_invoked(key_index)
}

fn num_lookup_tables(&self) -> usize {
self.transaction.num_lookup_tables()
}

fn message_address_table_lookups(&self) -> impl Iterator<Item = SVMMessageAddressTableLookup> {
self.transaction.message_address_table_lookups()
}
}

impl<T: SVMTransaction> SVMTransaction for RuntimeTransaction<T> {
fn signature(&self) -> &Signature {
self.transaction.signature()
}

fn signatures(&self) -> &[Signature] {
self.transaction.signatures()
}
}

#[cfg(test)]
mod tests {
use {
Expand Down

0 comments on commit 381fb85

Please sign in to comment.