Skip to main content

xrpl_common_stdlib/objects/generated/
escrow.rs

1// GENERATED -- do not hand-edit. Run scripts/generate-ledger-objects.sh to regenerate.
2
3use crate::host::Result;
4use crate::objects::ledger_object;
5use crate::objects::traits::LedgerObjectCommonFields;
6use crate::sfield;
7use crate::types::account_id::AccountID;
8use crate::types::amount::Amount;
9use crate::types::blob::{ConditionBlob, WasmBlob};
10use crate::types::contract_data::ContractData;
11use crate::types::uint::Hash256;
12
13/// Trait providing access to fields specific to Escrow objects in any ledger.
14pub trait EscrowFields: LedgerObjectCommonFields {
15    /// The address of the owner (sender) of this escrow. This is the account that provided the
16    /// funds, and gets it back if the escrow is canceled.
17    fn account(&self) -> Result<AccountID> {
18        ledger_object::get_field(self.get_slot_num(), sfield::Account)
19    }
20
21    /// The Sequence field (Optional).
22    fn sequence(&self) -> Result<Option<u32>> {
23        ledger_object::get_field_optional(self.get_slot_num(), sfield::Sequence)
24    }
25
26    /// The destination address where the XRP is paid if the escrow is successful.
27    fn destination(&self) -> Result<AccountID> {
28        ledger_object::get_field(self.get_slot_num(), sfield::Destination)
29    }
30
31    /// The amount to be delivered by the payment in escrow. The amount can be XRP, or with the
32    /// TokenEscrow amendment, a fungible token.
33    fn amount(&self) -> Result<Amount> {
34        ledger_object::get_field(self.get_slot_num(), sfield::Amount)
35    }
36
37    /// A PREIMAGE-SHA-256 crypto-condition, as hexadecimal. If present, the EscrowFinish
38    /// transaction must contain a fulfillment that satisfies this condition.
39    fn condition(&self) -> Result<Option<ConditionBlob>> {
40        ledger_object::get_field_optional(self.get_slot_num(), sfield::Condition)
41    }
42
43    /// The escrow can be canceled if and only if this field is present _and_ the time it specifies
44    /// has passed. Specifically, this is specified as seconds since the Ripple Epoch and it "has
45    /// passed" if it's earlier than the close time of the previous validated ledger.
46    fn cancel_after(&self) -> Result<Option<u32>> {
47        ledger_object::get_field_optional(self.get_slot_num(), sfield::CancelAfter)
48    }
49
50    /// The time, in seconds since the Ripple Epoch, after which this escrow can be finished. Any
51    /// EscrowFinish transaction before this time fails. (Specifically, this is compared with the
52    /// close time of the previous validated ledger.)
53    fn finish_after(&self) -> Result<Option<u32>> {
54        ledger_object::get_field_optional(self.get_slot_num(), sfield::FinishAfter)
55    }
56
57    /// The Bytecode field (Optional).
58    fn bytecode(&self) -> Result<Option<WasmBlob>> {
59        ledger_object::get_field_optional(self.get_slot_num(), sfield::Bytecode)
60    }
61
62    /// The Data field (Optional).
63    fn data(&self) -> Result<Option<ContractData>> {
64        ledger_object::get_field_optional(self.get_slot_num(), sfield::Data)
65    }
66
67    /// An arbitrary tag to further specify the source for this escrow, such as a hosted recipient
68    /// at the owner's address.
69    fn source_tag(&self) -> Result<Option<u32>> {
70        ledger_object::get_field_optional(self.get_slot_num(), sfield::SourceTag)
71    }
72
73    /// An arbitrary tag to further specify the destination for this escrow, such as a hosted
74    /// recipient at the destination address.
75    fn destination_tag(&self) -> Result<Option<u32>> {
76        ledger_object::get_field_optional(self.get_slot_num(), sfield::DestinationTag)
77    }
78
79    /// A hint indicating which page of the sender's owner directory links to this entry, in case
80    /// the directory consists of multiple pages.
81    fn owner_node(&self) -> Result<u64> {
82        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
83    }
84
85    /// The identifying hash of the transaction that most recently modified this entry.
86    fn previous_txn_id(&self) -> Result<Hash256> {
87        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
88    }
89
90    /// The index of the ledger that contains the transaction that most recently modified this
91    /// entry.
92    fn previous_txn_lgr_seq(&self) -> Result<u32> {
93        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
94    }
95
96    /// A hint indicating which page of the destination's owner directory links to this object, in
97    /// case the directory consists of multiple pages. Omitted on escrows created before enabling
98    /// the fix1523 amendment.
99    fn destination_node(&self) -> Result<Option<u64>> {
100        ledger_object::get_field_optional(self.get_slot_num(), sfield::DestinationNode)
101    }
102
103    /// The transfer rate or fee to charge when users finish an escrow, locked at the creation of an
104    /// escrow contract and used during settlement. Applicable to Trust Line Tokens and MPTs only.
105    fn transfer_rate(&self) -> Result<Option<u32>> {
106        ledger_object::get_field_optional(self.get_slot_num(), sfield::TransferRate)
107    }
108
109    /// The ledger index of the issuer's directory node associated with the `Escrow`. Used when the
110    /// issuer is neither the source nor destination account.
111    fn issuer_node(&self) -> Result<Option<u64>> {
112        ledger_object::get_field_optional(self.get_slot_num(), sfield::IssuerNode)
113    }
114}
115
116#[derive(Debug, Clone, Copy, Eq, PartialEq)]
117pub struct Escrow {
118    pub(crate) slot_num: i32,
119}
120
121impl Escrow {
122    /// Binds this handle to a host-managed slot holding an Escrow ledger object.
123    pub fn new(slot_num: i32) -> Self {
124        Self { slot_num }
125    }
126}
127
128impl LedgerObjectCommonFields for Escrow {
129    fn get_slot_num(&self) -> i32 {
130        self.slot_num
131    }
132}
133
134impl EscrowFields for Escrow {}
135
136#[cfg(test)]
137mod tests {
138    use super::*;
139    use crate::host::host_bindings_trait::MockHostBindings;
140    use crate::host::setup_mock;
141    use crate::objects::test_utils::*;
142
143    #[test]
144    fn read_all_fields() {
145        let mut mock = MockHostBindings::new();
146        mock_all_fields_present(&mut mock);
147        let _guard = setup_mock(mock);
148
149        let obj = Escrow::new(0);
150
151        assert!(obj.account().is_ok());
152        assert!(obj.destination().is_ok());
153        assert!(obj.amount().is_ok());
154        assert!(obj.owner_node().is_ok());
155        assert!(obj.previous_txn_id().is_ok());
156        assert!(obj.previous_txn_lgr_seq().is_ok());
157        assert!(obj.sequence().is_ok());
158        assert!(obj.condition().is_ok());
159        assert!(obj.cancel_after().is_ok());
160        assert!(obj.finish_after().is_ok());
161        assert!(obj.bytecode().is_ok());
162        assert!(obj.data().is_ok());
163        assert!(obj.source_tag().is_ok());
164        assert!(obj.destination_tag().is_ok());
165        assert!(obj.destination_node().is_ok());
166        assert!(obj.transfer_rate().is_ok());
167        assert!(obj.issuer_node().is_ok());
168    }
169
170    #[test]
171    fn optional_fields_none() {
172        let mut mock = MockHostBindings::new();
173        mock_all_fields_not_found(&mut mock);
174        let _guard = setup_mock(mock);
175
176        let obj = Escrow::new(0);
177
178        assert!(obj.sequence().unwrap().is_none());
179        assert!(obj.cancel_after().unwrap().is_none());
180        assert!(obj.finish_after().unwrap().is_none());
181        assert!(obj.source_tag().unwrap().is_none());
182        assert!(obj.destination_tag().unwrap().is_none());
183        assert!(obj.destination_node().unwrap().is_none());
184        assert!(obj.transfer_rate().unwrap().is_none());
185        assert!(obj.issuer_node().unwrap().is_none());
186    }
187}