1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
use super::{
Account, BlockHeader, InputNote, InputNotes, Program, TransactionArgs, TransactionInputs,
};
// PREPARED TRANSACTION
// ================================================================================================
/// A struct that contains all of the data required to execute a transaction.
///
/// This includes:
/// - A an executable program which defines the transaction.
/// - An optional transaction script.
/// - A set of inputs against which the transaction program should be executed.
#[derive(Debug)]
pub struct PreparedTransaction {
program: Program,
tx_inputs: TransactionInputs,
tx_args: TransactionArgs,
}
impl PreparedTransaction {
// CONSTRUCTOR
// --------------------------------------------------------------------------------------------
/// Returns a new [PreparedTransaction] instantiated from the provided executable transaction
/// program and inputs required to execute this program.
pub fn new(program: Program, tx_inputs: TransactionInputs, tx_args: TransactionArgs) -> Self {
Self { program, tx_inputs, tx_args }
}
// ACCESSORS
// --------------------------------------------------------------------------------------------
/// Returns the transaction program.
pub fn program(&self) -> &Program {
&self.program
}
/// Returns the account for this transaction.
pub fn account(&self) -> &Account {
self.tx_inputs.account()
}
/// Returns the block header for this transaction.
pub fn block_header(&self) -> &BlockHeader {
self.tx_inputs.block_header()
}
/// Returns the notes to be consumed in this transaction.
pub fn input_notes(&self) -> &InputNotes<InputNote> {
self.tx_inputs.input_notes()
}
/// Returns a reference to the transaction args.
pub fn tx_args(&self) -> &TransactionArgs {
&self.tx_args
}
/// Returns a reference to the inputs for this transaction.
pub fn tx_inputs(&self) -> &TransactionInputs {
&self.tx_inputs
}
// CONVERSIONS
// --------------------------------------------------------------------------------------------
/// Consumes the prepared transaction and returns its parts.
pub fn into_parts(self) -> (Program, TransactionInputs, TransactionArgs) {
(self.program, self.tx_inputs, self.tx_args)
}
}