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