Skip to content

Commit

Permalink
Merge pull request #47 from 0xPolygonMiden/frisitano-compiled-transac…
Browse files Browse the repository at this point in the history
…tion

Implement CompiledTransaction
  • Loading branch information
frisitano authored Mar 2, 2023
2 parents 3d84e89 + e06084e commit 8e22f43
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
3 changes: 1 addition & 2 deletions objects/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ pub mod notes;
mod errors;
pub use errors::{AccountError, AssetError, NoteError};

mod transaction;
pub use transaction::ProvenTransaction;
pub mod transaction;
57 changes: 57 additions & 0 deletions objects/src/transaction/compiled_tx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use super::{AccountId, Digest, Note, Vec};
use miden_core::Program;

/// Resultant object of compiling a set of note scripts in the context of an account.
/// The CompiledTransaction does not contain any account data, it is passed to a component
/// that will do the required data lookups before processing the transaction further.
/// Contains:
/// - account_id: the account that the transaction was executed against.
/// - consumed_notes: a list of consumed notes.
/// - tx_script_root: optional MAST root for the transaction script.
/// - tx_program: an executable program describing the transaction.
pub struct CompiledTransaction {
account_id: AccountId,
consumed_notes: Vec<Note>,
tx_script_root: Option<Digest>,
tx_program: Program,
}

impl CompiledTransaction {
/// Creates a new CompiledTransaction object.
pub fn new(
account_id: AccountId,
consumed_notes: Vec<Note>,
tx_script_root: Option<Digest>,
tx_program: Program,
) -> Self {
Self {
account_id,
consumed_notes,
tx_script_root,
tx_program,
}
}

// ACCESSORS
// --------------------------------------------------------------------------------------------

/// Returns the account id.
pub fn account_id(&self) -> AccountId {
self.account_id
}

/// Returns the consumed notes.
pub fn consumed_notes(&self) -> &[Note] {
&self.consumed_notes
}

/// Returns the transaction script root.
pub fn tx_script_root(&self) -> Option<Digest> {
self.tx_script_root
}

/// Returns the transaction program.
pub fn tx_program(&self) -> &Program {
&self.tx_program
}
}
4 changes: 3 additions & 1 deletion objects/src/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::{AccountId, Digest, Felt, Hasher, StarkField, Vec, Word};
use super::{notes::Note, AccountId, Digest, Felt, Hasher, StarkField, Vec, Word};

mod compiled_tx;
mod consumed_note;
mod created_note;
mod proven_tx;

pub use compiled_tx::CompiledTransaction;
pub use consumed_note::ConsumedNoteInfo;
pub use created_note::CreatedNoteInfo;
pub use proven_tx::ProvenTransaction;

0 comments on commit 8e22f43

Please sign in to comment.