Skip to main content

xrpl_common_stdlib/objects/generated/
ticket.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 Ticket objects in any ledger.
12pub trait TicketFields: LedgerObjectCommonFields {
13    /// The account that owns this Ticket.
14    fn account(&self) -> Result<AccountID> {
15        ledger_object::get_field(self.get_slot_num(), sfield::Account)
16    }
17
18    /// A hint indicating which page of the owner directory links to this entry, in case the
19    /// directory consists of multiple pages.
20    fn owner_node(&self) -> Result<u64> {
21        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
22    }
23
24    /// The Sequence Number this Ticket sets aside.
25    fn ticket_sequence(&self) -> Result<u32> {
26        ledger_object::get_field(self.get_slot_num(), sfield::TicketSequence)
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    /// entry.
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 Ticket object.
42pub trait CurrentTicketFields: CurrentLedgerObjectCommonFields {
43    /// The account that owns this Ticket.
44    fn account(&self) -> Result<AccountID> {
45        current_ledger_object::get_field(sfield::Account)
46    }
47
48    /// A hint indicating which page of the owner directory links to this entry, in case the
49    /// directory consists of multiple pages.
50    fn owner_node(&self) -> Result<u64> {
51        current_ledger_object::get_field(sfield::OwnerNode)
52    }
53
54    /// The Sequence Number this Ticket sets aside.
55    fn ticket_sequence(&self) -> Result<u32> {
56        current_ledger_object::get_field(sfield::TicketSequence)
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    /// entry.
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 Ticket {
73    pub(crate) slot_num: i32,
74}
75
76impl Ticket {
77    /// Binds this handle to a host-managed slot holding a Ticket ledger object.
78    pub fn new(slot_num: i32) -> Self {
79        Self { slot_num }
80    }
81}
82
83impl LedgerObjectCommonFields for Ticket {
84    fn get_slot_num(&self) -> i32 {
85        self.slot_num
86    }
87}
88
89impl TicketFields for Ticket {}
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 = Ticket::new(0);
105
106        assert!(obj.account().is_ok());
107        assert!(obj.owner_node().is_ok());
108        assert!(obj.ticket_sequence().is_ok());
109        assert!(obj.previous_txn_id().is_ok());
110        assert!(obj.previous_txn_lgr_seq().is_ok());
111    }
112}