Skip to main content

xrpl_common_stdlib/objects/generated/
permissioned_domain.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 PermissionedDomain objects in any ledger.
12pub trait PermissionedDomainFields: LedgerObjectCommonFields {
13    /// The address of the account that owns this domain.
14    fn owner(&self) -> Result<AccountID> {
15        ledger_object::get_field(self.get_slot_num(), sfield::Owner)
16    }
17
18    /// The `Sequence` value of the transaction that created this entry.
19    fn sequence(&self) -> Result<u32> {
20        ledger_object::get_field(self.get_slot_num(), sfield::Sequence)
21    }
22
23    /// A hint indicating which page of the owner directory links to this entry, in case the
24    /// directory consists of multiple pages.
25    fn owner_node(&self) -> Result<u64> {
26        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
27    }
28
29    /// The identifying hash of the transaction that most recently modified this entry.
30    fn previous_txn_id(&self) -> Result<Hash256> {
31        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
32    }
33
34    /// The index of the ledger that contains the transaction that most recently modified this
35    /// object.
36    fn previous_txn_lgr_seq(&self) -> Result<u32> {
37        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
38    }
39}
40
41/// Trait providing access to fields specific to the current PermissionedDomain object.
42pub trait CurrentPermissionedDomainFields: CurrentLedgerObjectCommonFields {
43    /// The address of the account that owns this domain.
44    fn owner(&self) -> Result<AccountID> {
45        current_ledger_object::get_field(sfield::Owner)
46    }
47
48    /// The `Sequence` value of the transaction that created this entry.
49    fn sequence(&self) -> Result<u32> {
50        current_ledger_object::get_field(sfield::Sequence)
51    }
52
53    /// A hint indicating which page of the owner directory links to this entry, in case the
54    /// directory consists of multiple pages.
55    fn owner_node(&self) -> Result<u64> {
56        current_ledger_object::get_field(sfield::OwnerNode)
57    }
58
59    /// The identifying hash of the transaction that most recently modified this entry.
60    fn previous_txn_id(&self) -> Result<Hash256> {
61        current_ledger_object::get_field(sfield::PreviousTxnID)
62    }
63
64    /// The index of the ledger that contains the transaction that most recently modified this
65    /// object.
66    fn previous_txn_lgr_seq(&self) -> Result<u32> {
67        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
68    }
69}
70
71#[derive(Debug, Clone, Copy, Eq, PartialEq)]
72pub struct PermissionedDomain {
73    pub(crate) slot_num: i32,
74}
75
76impl PermissionedDomain {
77    /// Binds this handle to a host-managed slot holding a PermissionedDomain ledger object.
78    pub fn new(slot_num: i32) -> Self {
79        Self { slot_num }
80    }
81}
82
83impl LedgerObjectCommonFields for PermissionedDomain {
84    fn get_slot_num(&self) -> i32 {
85        self.slot_num
86    }
87}
88
89impl PermissionedDomainFields for PermissionedDomain {}
90
91#[cfg(test)]
92mod tests {
93    use super::*;
94    use crate::host::host_bindings_trait::MockHostBindings;
95    use crate::host::setup_mock;
96    use crate::objects::test_utils::*;
97
98    #[test]
99    fn read_all_fields() {
100        let mut mock = MockHostBindings::new();
101        mock_all_fields_present(&mut mock);
102        let _guard = setup_mock(mock);
103
104        let obj = PermissionedDomain::new(0);
105
106        assert!(obj.owner().is_ok());
107        assert!(obj.sequence().is_ok());
108        assert!(obj.owner_node().is_ok());
109        assert!(obj.previous_txn_id().is_ok());
110        assert!(obj.previous_txn_lgr_seq().is_ok());
111    }
112}