Skip to main content

xrpl_common_stdlib/objects/generated/
signer_list.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 SignerList objects in any ledger.
12pub trait SignerListFields: LedgerObjectCommonFields {
13    /// The Owner field (Optional).
14    fn owner(&self) -> Result<Option<AccountID>> {
15        ledger_object::get_field_optional(self.get_slot_num(), sfield::Owner)
16    }
17
18    /// A hint indicating which page of the owner directory links to this object, 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    /// A target number for signer weights. To produce a valid signature for the owner of this
25    /// SignerList, the signers must provide valid signatures whose weights sum to this value or
26    /// more.
27    fn signer_quorum(&self) -> Result<u32> {
28        ledger_object::get_field(self.get_slot_num(), sfield::SignerQuorum)
29    }
30
31    /// An ID for this signer list. Currently always set to `0`. If a future amendment allows
32    /// multiple signer lists for an account, this may change.
33    fn signer_list_id(&self) -> Result<u32> {
34        ledger_object::get_field(self.get_slot_num(), sfield::SignerListID)
35    }
36
37    /// The identifying hash of the transaction that most recently modified this object.
38    fn previous_txn_id(&self) -> Result<Hash256> {
39        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
40    }
41
42    /// The index of the ledger that contains the transaction that most recently modified this
43    /// object.
44    fn previous_txn_lgr_seq(&self) -> Result<u32> {
45        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
46    }
47}
48
49/// Trait providing access to fields specific to the current SignerList object.
50pub trait CurrentSignerListFields: CurrentLedgerObjectCommonFields {
51    /// The Owner field (Optional).
52    fn owner(&self) -> Result<Option<AccountID>> {
53        current_ledger_object::get_field_optional(sfield::Owner)
54    }
55
56    /// A hint indicating which page of the owner directory links to this object, in case the
57    /// directory consists of multiple pages.
58    fn owner_node(&self) -> Result<u64> {
59        current_ledger_object::get_field(sfield::OwnerNode)
60    }
61
62    /// A target number for signer weights. To produce a valid signature for the owner of this
63    /// SignerList, the signers must provide valid signatures whose weights sum to this value or
64    /// more.
65    fn signer_quorum(&self) -> Result<u32> {
66        current_ledger_object::get_field(sfield::SignerQuorum)
67    }
68
69    /// An ID for this signer list. Currently always set to `0`. If a future amendment allows
70    /// multiple signer lists for an account, this may change.
71    fn signer_list_id(&self) -> Result<u32> {
72        current_ledger_object::get_field(sfield::SignerListID)
73    }
74
75    /// The identifying hash of the transaction that most recently modified this object.
76    fn previous_txn_id(&self) -> Result<Hash256> {
77        current_ledger_object::get_field(sfield::PreviousTxnID)
78    }
79
80    /// The index of the ledger that contains the transaction that most recently modified this
81    /// object.
82    fn previous_txn_lgr_seq(&self) -> Result<u32> {
83        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
84    }
85}
86
87#[derive(Debug, Clone, Copy, Eq, PartialEq)]
88pub struct SignerList {
89    pub(crate) slot_num: i32,
90}
91
92impl SignerList {
93    /// Binds this handle to a host-managed slot holding a SignerList ledger object.
94    pub fn new(slot_num: i32) -> Self {
95        Self { slot_num }
96    }
97}
98
99impl LedgerObjectCommonFields for SignerList {
100    fn get_slot_num(&self) -> i32 {
101        self.slot_num
102    }
103}
104
105impl SignerListFields for SignerList {}
106
107#[cfg(test)]
108mod tests {
109    use super::*;
110    use crate::host::host_bindings_trait::MockHostBindings;
111    use crate::host::setup_mock;
112    use crate::objects::test_utils::*;
113
114    #[test]
115    fn read_all_fields() {
116        let mut mock = MockHostBindings::new();
117        mock_all_fields_present(&mut mock);
118        let _guard = setup_mock(mock);
119
120        let obj = SignerList::new(0);
121
122        assert!(obj.owner_node().is_ok());
123        assert!(obj.signer_quorum().is_ok());
124        assert!(obj.signer_list_id().is_ok());
125        assert!(obj.previous_txn_id().is_ok());
126        assert!(obj.previous_txn_lgr_seq().is_ok());
127        assert!(obj.owner().is_ok());
128    }
129
130    #[test]
131    fn optional_fields_none() {
132        let mut mock = MockHostBindings::new();
133        mock_all_fields_not_found(&mut mock);
134        let _guard = setup_mock(mock);
135
136        let obj = SignerList::new(0);
137
138        assert!(obj.owner().unwrap().is_none());
139    }
140}