xrpl_common_stdlib/objects/generated/
signer_list.rs1use 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
11pub trait SignerListFields: LedgerObjectCommonFields {
13 fn owner(&self) -> Result<Option<AccountID>> {
15 ledger_object::get_field_optional(self.get_slot_num(), sfield::Owner)
16 }
17
18 fn owner_node(&self) -> Result<u64> {
21 ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
22 }
23
24 fn signer_quorum(&self) -> Result<u32> {
28 ledger_object::get_field(self.get_slot_num(), sfield::SignerQuorum)
29 }
30
31 fn signer_list_id(&self) -> Result<u32> {
34 ledger_object::get_field(self.get_slot_num(), sfield::SignerListID)
35 }
36
37 fn previous_txn_id(&self) -> Result<Hash256> {
39 ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
40 }
41
42 fn previous_txn_lgr_seq(&self) -> Result<u32> {
45 ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
46 }
47}
48
49pub trait CurrentSignerListFields: CurrentLedgerObjectCommonFields {
51 fn owner(&self) -> Result<Option<AccountID>> {
53 current_ledger_object::get_field_optional(sfield::Owner)
54 }
55
56 fn owner_node(&self) -> Result<u64> {
59 current_ledger_object::get_field(sfield::OwnerNode)
60 }
61
62 fn signer_quorum(&self) -> Result<u32> {
66 current_ledger_object::get_field(sfield::SignerQuorum)
67 }
68
69 fn signer_list_id(&self) -> Result<u32> {
72 current_ledger_object::get_field(sfield::SignerListID)
73 }
74
75 fn previous_txn_id(&self) -> Result<Hash256> {
77 current_ledger_object::get_field(sfield::PreviousTxnID)
78 }
79
80 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 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}