Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Aug 9, 2024
1 parent 6ee6d40 commit b94019a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 6 additions & 3 deletions svm/examples/paytube/src/settler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use {
pubkey::Pubkey, signature::Keypair, signer::Signer, system_instruction,
transaction::Transaction as SolanaTransaction,
},
solana_svm::transaction_processor::LoadAndExecuteSanitizedTransactionsOutput,
solana_svm::{
transaction_processing_result::TransactionProcessingResultExtensions,
transaction_processor::LoadAndExecuteSanitizedTransactionsOutput,
},
spl_associated_token_account::get_associated_token_address,
std::collections::HashMap,
};
Expand Down Expand Up @@ -61,11 +64,11 @@ impl Ledger {
let mut ledger: HashMap<LedgerKey, i128> = HashMap::new();
paytube_transactions
.iter()
.zip(svm_output.execution_results)
.zip(svm_output.processing_results)
.for_each(|(transaction, result)| {
// Only append to the ledger if the PayTube transaction was
// successful.
if result.was_executed_successfully() {
if result.was_processed_with_successful_result() {
let mint = transaction.mint;
let mut keys = [transaction.from, transaction.to];
keys.sort();
Expand Down
8 changes: 8 additions & 0 deletions svm/src/transaction_processing_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub type ProcessedTransaction = ExecutedTransaction;

pub trait TransactionProcessingResultExtensions {
fn was_processed(&self) -> bool;
fn was_processed_with_successful_result(&self) -> bool;
fn processed_transaction(&self) -> Option<&ProcessedTransaction>;
fn processed_transaction_mut(&mut self) -> Option<&mut ProcessedTransaction>;
fn flattened_result(&self) -> TransactionResult<()>;
Expand All @@ -18,6 +19,13 @@ impl TransactionProcessingResultExtensions for TransactionProcessingResult {
self.is_ok()
}

fn was_processed_with_successful_result(&self) -> bool {
match self {
Ok(processed_tx) => processed_tx.was_successful(),
Err(_) => false,
}
}

fn processed_transaction(&self) -> Option<&ProcessedTransaction> {
match self {
Ok(processed_tx) => Some(processed_tx),
Expand Down
5 changes: 3 additions & 2 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ pub struct LoadAndExecuteSanitizedTransactionsOutput {
pub error_metrics: TransactionErrorMetrics,
/// Timings for transaction batch execution.
pub execute_timings: ExecuteTimings,
// Vector of results indicating whether a transaction was executed or could not
// be executed. Note executed transactions can still have failed!
/// Vector of results indicating whether a transaction was processed or
/// could not be processed. Note processed transactions can still have a
/// failure result meaning that the transaction will be rolled back.
pub processing_results: Vec<TransactionProcessingResult>,
}

Expand Down

0 comments on commit b94019a

Please sign in to comment.