Skip to main content

xrpl_common_stdlib/objects/generated/
deposit_preauth.rs

1// GENERATED -- do not hand-edit. Run scripts/generate-ledger-objects.sh to regenerate.
2
3use crate::host::Result;
4use crate::objects::traits::CurrentLedgerObjectCommonFields;
5use crate::objects::traits::LedgerObjectCommonFields;
6use crate::objects::{current_ledger_object, ledger_object};
7use crate::sfield;
8use crate::types::account_id::AccountID;
9use crate::types::uint::Hash256;
10
11/// Trait providing access to fields specific to DepositPreauth objects in any ledger.
12pub trait DepositPreauthFields: LedgerObjectCommonFields {
13    /// The account that granted the preauthorization. (The destination of the preauthorized
14    /// payments.)
15    fn account(&self) -> Result<AccountID> {
16        ledger_object::get_field(self.get_slot_num(), sfield::Account)
17    }
18
19    /// The account that received the preauthorization. (The sender of the preauthorized payments.)
20    fn authorize(&self) -> Result<Option<AccountID>> {
21        ledger_object::get_field_optional(self.get_slot_num(), sfield::Authorize)
22    }
23
24    /// A hint indicating which page of the sender's owner directory links to this object, in case
25    /// the directory consists of multiple pages. Note: The object does not contain a direct link to
26    /// the owner directory containing it, since that value can be derived from the `Account`.
27    fn owner_node(&self) -> Result<u64> {
28        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
29    }
30
31    /// The identifying hash of the transaction that most recently modified this object.
32    fn previous_txn_id(&self) -> Result<Hash256> {
33        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
34    }
35
36    /// The index of the ledger that contains the transaction that most recently modified this
37    /// object.
38    fn previous_txn_lgr_seq(&self) -> Result<u32> {
39        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
40    }
41}
42
43/// Trait providing access to fields specific to the current DepositPreauth object.
44pub trait CurrentDepositPreauthFields: CurrentLedgerObjectCommonFields {
45    /// The account that granted the preauthorization. (The destination of the preauthorized
46    /// payments.)
47    fn account(&self) -> Result<AccountID> {
48        current_ledger_object::get_field(sfield::Account)
49    }
50
51    /// The account that received the preauthorization. (The sender of the preauthorized payments.)
52    fn authorize(&self) -> Result<Option<AccountID>> {
53        current_ledger_object::get_field_optional(sfield::Authorize)
54    }
55
56    /// A hint indicating which page of the sender's owner directory links to this object, in case
57    /// the directory consists of multiple pages. Note: The object does not contain a direct link to
58    /// the owner directory containing it, since that value can be derived from the `Account`.
59    fn owner_node(&self) -> Result<u64> {
60        current_ledger_object::get_field(sfield::OwnerNode)
61    }
62
63    /// The identifying hash of the transaction that most recently modified this object.
64    fn previous_txn_id(&self) -> Result<Hash256> {
65        current_ledger_object::get_field(sfield::PreviousTxnID)
66    }
67
68    /// The index of the ledger that contains the transaction that most recently modified this
69    /// object.
70    fn previous_txn_lgr_seq(&self) -> Result<u32> {
71        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
72    }
73}
74
75#[derive(Debug, Clone, Copy, Eq, PartialEq)]
76pub struct DepositPreauth {
77    pub(crate) slot_num: i32,
78}
79
80impl DepositPreauth {
81    /// Binds this handle to a host-managed slot holding a DepositPreauth ledger object.
82    pub fn new(slot_num: i32) -> Self {
83        Self { slot_num }
84    }
85}
86
87impl LedgerObjectCommonFields for DepositPreauth {
88    fn get_slot_num(&self) -> i32 {
89        self.slot_num
90    }
91}
92
93impl DepositPreauthFields for DepositPreauth {}
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98    use crate::host::host_bindings_trait::MockHostBindings;
99    use crate::host::setup_mock;
100    use crate::objects::test_utils::*;
101
102    #[test]
103    fn read_all_fields() {
104        let mut mock = MockHostBindings::new();
105        mock_all_fields_present(&mut mock);
106        let _guard = setup_mock(mock);
107
108        let obj = DepositPreauth::new(0);
109
110        assert!(obj.account().is_ok());
111        assert!(obj.owner_node().is_ok());
112        assert!(obj.previous_txn_id().is_ok());
113        assert!(obj.previous_txn_lgr_seq().is_ok());
114        assert!(obj.authorize().is_ok());
115    }
116
117    #[test]
118    fn optional_fields_none() {
119        let mut mock = MockHostBindings::new();
120        mock_all_fields_not_found(&mut mock);
121        let _guard = setup_mock(mock);
122
123        let obj = DepositPreauth::new(0);
124
125        assert!(obj.authorize().unwrap().is_none());
126    }
127}