Skip to main content

miden_protocol/transaction/outputs/
mod.rs

1use core::fmt::Debug;
2
3use crate::Word;
4use crate::account::AccountHeader;
5use crate::asset::FungibleAsset;
6use crate::block::BlockNumber;
7use crate::utils::serde::{
8    ByteReader,
9    ByteWriter,
10    Deserializable,
11    DeserializationError,
12    Serializable,
13};
14
15mod notes;
16pub use notes::{
17    OutputNote,
18    OutputNoteCollection,
19    OutputNotes,
20    PrivateNoteHeader,
21    PublicOutputNote,
22    RawOutputNote,
23    RawOutputNotes,
24};
25
26#[cfg(test)]
27mod tests;
28
29// TRANSACTION OUTPUTS
30// ================================================================================================
31
32/// Describes the result of executing a transaction.
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct TransactionOutputs {
35    /// Information related to the account's final state.
36    pub account: AccountHeader,
37    /// The commitment to the delta computed by the transaction kernel.
38    pub account_delta_commitment: Word,
39    /// Set of output notes created by the transaction.
40    pub output_notes: RawOutputNotes,
41    /// The fee of the transaction.
42    pub fee: FungibleAsset,
43    /// Defines up to which block the transaction is considered valid.
44    pub expiration_block_num: BlockNumber,
45}
46
47impl TransactionOutputs {
48    // CONSTANTS
49    // --------------------------------------------------------------------------------------------
50
51    /// The element index starting from which the output notes commitment is stored on the output
52    /// stack.
53    pub const OUTPUT_NOTES_COMMITMENT_WORD_IDX: usize = 0;
54
55    /// The element index starting from which the account update commitment word is stored on the
56    /// output stack.
57    pub const ACCOUNT_UPDATE_COMMITMENT_WORD_IDX: usize = 4;
58
59    /// The index of the element at which the ID suffix of the faucet that issues the native asset
60    /// is stored on the output stack.
61    pub const NATIVE_ASSET_ID_SUFFIX_ELEMENT_IDX: usize = 8;
62
63    /// The index of the element at which the ID prefix of the faucet that issues the native asset
64    /// is stored on the output stack.
65    pub const NATIVE_ASSET_ID_PREFIX_ELEMENT_IDX: usize = 9;
66
67    /// The index of the element at which the fee amount is stored on the output stack.
68    pub const FEE_AMOUNT_ELEMENT_IDX: usize = 10;
69
70    /// The index of the item at which the expiration block height is stored on the output stack.
71    pub const EXPIRATION_BLOCK_ELEMENT_IDX: usize = 11;
72}
73
74impl Serializable for TransactionOutputs {
75    fn write_into<W: ByteWriter>(&self, target: &mut W) {
76        self.account.write_into(target);
77        self.account_delta_commitment.write_into(target);
78        self.output_notes.write_into(target);
79        self.fee.write_into(target);
80        self.expiration_block_num.write_into(target);
81    }
82}
83
84impl Deserializable for TransactionOutputs {
85    fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
86        let account = AccountHeader::read_from(source)?;
87        let account_delta_commitment = Word::read_from(source)?;
88        let output_notes = RawOutputNotes::read_from(source)?;
89        let fee = FungibleAsset::read_from(source)?;
90        let expiration_block_num = BlockNumber::read_from(source)?;
91
92        Ok(Self {
93            account,
94            account_delta_commitment,
95            output_notes,
96            fee,
97            expiration_block_num,
98        })
99    }
100}