Clean up sanitized tx creation for tests (#21006)
This commit is contained in:
@ -14,7 +14,6 @@ use {
|
||||
transaction::{Result, Transaction, TransactionError, VersionedTransaction},
|
||||
},
|
||||
solana_program::{system_instruction::SystemInstruction, system_program},
|
||||
std::convert::TryFrom,
|
||||
std::sync::Arc,
|
||||
};
|
||||
|
||||
@ -35,23 +34,6 @@ pub struct TransactionAccountLocks<'a> {
|
||||
pub writable: Vec<&'a Pubkey>,
|
||||
}
|
||||
|
||||
impl TryFrom<Transaction> for SanitizedTransaction {
|
||||
type Error = TransactionError;
|
||||
fn try_from(tx: Transaction) -> Result<Self> {
|
||||
tx.sanitize()?;
|
||||
|
||||
if tx.message.has_duplicates() {
|
||||
return Err(TransactionError::AccountLoadedTwice);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
message_hash: tx.message.hash(),
|
||||
message: SanitizedMessage::Legacy(tx.message),
|
||||
signatures: tx.signatures,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl SanitizedTransaction {
|
||||
/// Create a sanitized transaction from an unsanitized transaction.
|
||||
/// If the input transaction uses address maps, attempt to map the
|
||||
@ -83,6 +65,21 @@ 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();
|
||||
|
||||
if tx.message.has_duplicates() {
|
||||
Result::<Self>::Err(TransactionError::AccountLoadedTwice).unwrap();
|
||||
}
|
||||
|
||||
Self {
|
||||
message_hash: tx.message.hash(),
|
||||
message: SanitizedMessage::Legacy(tx.message),
|
||||
signatures: tx.signatures,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the first signature for this transaction.
|
||||
///
|
||||
/// Notes:
|
||||
|
Reference in New Issue
Block a user