Skip to main content

xrpl_escrow_stdlib/current_tx/
escrow_finish.rs

1//! # EscrowFinish
2//!
3//! This module provides functionality for handling EscrowFinish transactions within the
4//! XRPL Programmability environment.
5
6use xrpl_common_stdlib::core::current_tx::traits::TransactionCommonFields;
7
8use crate::current_tx::traits::EscrowFinishFields;
9
10/// Represents an EscrowFinish transaction in the XRPL Programmability environment.
11///
12/// This zero-sized type serves as a marker for EscrowFinish transactions and provides
13/// access to transaction-specific fields through trait implementations. The structure
14/// implements both common transaction fields (available to all transaction types) and
15/// escrow-finish-specific fields.
16///
17/// # Field Access
18///
19/// Through the implemented traits, this structure provides access to:
20///
21/// ## Common Transaction Fields (via `TransactionCommonFields`)
22/// - Account (transaction sender)
23/// - Fee (transaction cost in drops)
24/// - Sequence (account sequence number)
25/// - LastLedgerSequence (transaction expiration)
26/// - And other standard XRPL transaction fields
27///
28/// ## EscrowFinish-Specific Fields (via `EscrowFinishFields`)
29/// - Owner (account that created the escrow)
30/// - OfferSequence (sequence number of the EscrowCreate transaction)
31/// - Condition (cryptographic condition, if present)
32/// - Fulfillment (cryptographic fulfillment, if present)
33///
34/// # Zero-Cost Abstraction
35///
36/// This structure has no runtime overhead as it contains no data fields. All field
37/// access is performed through the trait methods, which directly call the underlying
38/// host functions to retrieve data from the current transaction context.
39#[derive(Debug, Clone, Copy, Eq, PartialEq)]
40pub struct EscrowFinish;
41
42/// Implementation of common transaction fields for EscrowFinish transactions.
43///
44/// This implementation provides access to standard XRPL transaction fields that are
45/// present in all transaction types, such as Account, Fee, Sequence, and others.
46/// The methods are provided by the `TransactionCommonFields` trait.
47impl TransactionCommonFields for EscrowFinish {}
48
49/// Implementation of EscrowFinish-specific transaction fields.
50///
51/// This implementation provides access to fields that are specific to EscrowFinish
52/// transactions, such as Owner, OfferSequence, Condition, and Fulfillment.
53/// The methods are provided by the `EscrowFinishFields` trait.
54impl EscrowFinishFields for EscrowFinish {}
55
56/// Creates a new EscrowFinish transaction handler for the current transaction context.
57///
58/// This function returns an `EscrowFinish` instance that can be used to access fields
59/// from the current XRPL transaction. The function assumes that the current transaction
60/// is indeed an EscrowFinish transaction - using this with other transaction types
61/// may result in unexpected behavior or errors when accessing type-specific fields.
62///
63/// # Returns
64///
65/// Returns an `EscrowFinish` struct that provides access to both common transaction
66/// fields and EscrowFinish-specific fields through its trait implementations.
67///
68/// # Safety
69///
70/// This function is safe to call, but the returned object should only be used when
71/// the current transaction context is guaranteed to be an EscrowFinish transaction.
72/// The XRPL Programmability environment ensures this context is correct when the
73/// smart contract is invoked in response to an EscrowFinish transaction.
74///
75/// # Performance
76///
77/// This function has zero runtime cost as it simply returns a zero-sized type.
78/// All actual field access happens lazily when trait methods are called.
79///
80/// # Example
81///
82/// ```no_run
83/// use xrpl_escrow_stdlib::current_tx::escrow_finish::EscrowFinish;
84/// use xrpl_escrow_stdlib::current_tx::traits::EscrowFinishFields;
85/// use xrpl_common_stdlib::core::current_tx::traits::TransactionCommonFields;
86/// let tx = EscrowFinish;
87/// let owner = tx.get_owner().unwrap_or_panic();
88/// let offer_seq = tx.get_offer_sequence().unwrap_or_panic();
89/// let condition = tx.get_condition().unwrap_or_panic(); // Option<_>
90/// ```
91#[inline]
92pub fn get_current_escrow_finish() -> EscrowFinish {
93    EscrowFinish
94}