Skip to main content

xrpl_common_stdlib/objects/generated/
ripple_state.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::amount::Amount;
10use crate::types::uint::Hash256;
11
12/// Trait providing access to fields specific to RippleState objects in any ledger.
13pub trait RippleStateFields: LedgerObjectCommonFields {
14    /// The balance of the trust line, from the perspective of the low account. A negative balance
15    /// indicates that the high account holds tokens issued by the low account. The issuer in this
16    /// is always set to the neutral value ACCOUNT_ONE.
17    fn balance(&self) -> Result<Amount> {
18        ledger_object::get_field(self.get_slot_num(), sfield::Balance)
19    }
20
21    /// The limit that the low account has set on the trust line. The `issuer` is the address of the
22    /// low account that set this limit.
23    fn low_limit(&self) -> Result<Amount> {
24        ledger_object::get_field(self.get_slot_num(), sfield::LowLimit)
25    }
26
27    /// The limit that the high account has set on the trust line. The `issuer` is the address of
28    /// the high account that set this limit.
29    fn high_limit(&self) -> Result<Amount> {
30        ledger_object::get_field(self.get_slot_num(), sfield::HighLimit)
31    }
32
33    /// The identifying hash of the transaction that most recently modified this entry.
34    fn previous_txn_id(&self) -> Result<Hash256> {
35        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
36    }
37
38    /// The index of the ledger that contains the transaction that most recently modified this
39    /// entry.
40    fn previous_txn_lgr_seq(&self) -> Result<u32> {
41        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
42    }
43
44    /// (Omitted in some historical ledgers) A hint indicating which page of the low account's owner
45    /// directory links to this entry, in case the directory consists of multiple pages.
46    fn low_node(&self) -> Result<Option<u64>> {
47        ledger_object::get_field_optional(self.get_slot_num(), sfield::LowNode)
48    }
49
50    /// The inbound quality set by the low account, as an integer in the implied ratio
51    /// `LowQualityIn`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion, or
52    /// face value.
53    fn low_quality_in(&self) -> Result<Option<u32>> {
54        ledger_object::get_field_optional(self.get_slot_num(), sfield::LowQualityIn)
55    }
56
57    /// The outbound quality set by the low account, as an integer in the implied ratio
58    /// `LowQualityOut`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion, or
59    /// face value.
60    fn low_quality_out(&self) -> Result<Option<u32>> {
61        ledger_object::get_field_optional(self.get_slot_num(), sfield::LowQualityOut)
62    }
63
64    /// (Omitted in some historical ledgers) A hint indicating which page of the high account's
65    /// owner directory links to this entry, in case the directory consists of multiple pages.
66    fn high_node(&self) -> Result<Option<u64>> {
67        ledger_object::get_field_optional(self.get_slot_num(), sfield::HighNode)
68    }
69
70    /// The inbound quality set by the high account, as an integer in the implied ratio
71    /// `HighQualityIn`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion, or
72    /// face value.
73    fn high_quality_in(&self) -> Result<Option<u32>> {
74        ledger_object::get_field_optional(self.get_slot_num(), sfield::HighQualityIn)
75    }
76
77    /// The outbound quality set by the high account, as an integer in the implied ratio
78    /// `HighQualityOut`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion,
79    /// or face value.
80    fn high_quality_out(&self) -> Result<Option<u32>> {
81        ledger_object::get_field_optional(self.get_slot_num(), sfield::HighQualityOut)
82    }
83
84    /// The sponsor paying the reserve on behalf of the _high account_ on the trust line. This is
85    /// separate from `LowSponsor` because bidirectional trust lines may have the reserve held by
86    /// two accounts.
87    fn high_sponsor(&self) -> Result<Option<AccountID>> {
88        ledger_object::get_field_optional(self.get_slot_num(), sfield::HighSponsor)
89    }
90
91    /// The sponsor paying the reserve on behalf of the _low account_ on the trust line. This is
92    /// separate from `HighSponsor` because bidirectional trust lines may have the reserve held by
93    /// two accounts.
94    fn low_sponsor(&self) -> Result<Option<AccountID>> {
95        ledger_object::get_field_optional(self.get_slot_num(), sfield::LowSponsor)
96    }
97}
98
99/// Trait providing access to fields specific to the current RippleState object.
100pub trait CurrentRippleStateFields: CurrentLedgerObjectCommonFields {
101    /// The balance of the trust line, from the perspective of the low account. A negative balance
102    /// indicates that the high account holds tokens issued by the low account. The issuer in this
103    /// is always set to the neutral value ACCOUNT_ONE.
104    fn balance(&self) -> Result<Amount> {
105        current_ledger_object::get_field(sfield::Balance)
106    }
107
108    /// The limit that the low account has set on the trust line. The `issuer` is the address of the
109    /// low account that set this limit.
110    fn low_limit(&self) -> Result<Amount> {
111        current_ledger_object::get_field(sfield::LowLimit)
112    }
113
114    /// The limit that the high account has set on the trust line. The `issuer` is the address of
115    /// the high account that set this limit.
116    fn high_limit(&self) -> Result<Amount> {
117        current_ledger_object::get_field(sfield::HighLimit)
118    }
119
120    /// The identifying hash of the transaction that most recently modified this entry.
121    fn previous_txn_id(&self) -> Result<Hash256> {
122        current_ledger_object::get_field(sfield::PreviousTxnID)
123    }
124
125    /// The index of the ledger that contains the transaction that most recently modified this
126    /// entry.
127    fn previous_txn_lgr_seq(&self) -> Result<u32> {
128        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
129    }
130
131    /// (Omitted in some historical ledgers) A hint indicating which page of the low account's owner
132    /// directory links to this entry, in case the directory consists of multiple pages.
133    fn low_node(&self) -> Result<Option<u64>> {
134        current_ledger_object::get_field_optional(sfield::LowNode)
135    }
136
137    /// The inbound quality set by the low account, as an integer in the implied ratio
138    /// `LowQualityIn`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion, or
139    /// face value.
140    fn low_quality_in(&self) -> Result<Option<u32>> {
141        current_ledger_object::get_field_optional(sfield::LowQualityIn)
142    }
143
144    /// The outbound quality set by the low account, as an integer in the implied ratio
145    /// `LowQualityOut`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion, or
146    /// face value.
147    fn low_quality_out(&self) -> Result<Option<u32>> {
148        current_ledger_object::get_field_optional(sfield::LowQualityOut)
149    }
150
151    /// (Omitted in some historical ledgers) A hint indicating which page of the high account's
152    /// owner directory links to this entry, in case the directory consists of multiple pages.
153    fn high_node(&self) -> Result<Option<u64>> {
154        current_ledger_object::get_field_optional(sfield::HighNode)
155    }
156
157    /// The inbound quality set by the high account, as an integer in the implied ratio
158    /// `HighQualityIn`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion, or
159    /// face value.
160    fn high_quality_in(&self) -> Result<Option<u32>> {
161        current_ledger_object::get_field_optional(sfield::HighQualityIn)
162    }
163
164    /// The outbound quality set by the high account, as an integer in the implied ratio
165    /// `HighQualityOut`:1,000,000,000. As a special case, the value 0 is equivalent to 1 billion,
166    /// or face value.
167    fn high_quality_out(&self) -> Result<Option<u32>> {
168        current_ledger_object::get_field_optional(sfield::HighQualityOut)
169    }
170
171    /// The sponsor paying the reserve on behalf of the _high account_ on the trust line. This is
172    /// separate from `LowSponsor` because bidirectional trust lines may have the reserve held by
173    /// two accounts.
174    fn high_sponsor(&self) -> Result<Option<AccountID>> {
175        current_ledger_object::get_field_optional(sfield::HighSponsor)
176    }
177
178    /// The sponsor paying the reserve on behalf of the _low account_ on the trust line. This is
179    /// separate from `HighSponsor` because bidirectional trust lines may have the reserve held by
180    /// two accounts.
181    fn low_sponsor(&self) -> Result<Option<AccountID>> {
182        current_ledger_object::get_field_optional(sfield::LowSponsor)
183    }
184}
185
186#[derive(Debug, Clone, Copy, Eq, PartialEq)]
187pub struct RippleState {
188    pub(crate) slot_num: i32,
189}
190
191impl RippleState {
192    /// Binds this handle to a host-managed slot holding a RippleState ledger object.
193    pub fn new(slot_num: i32) -> Self {
194        Self { slot_num }
195    }
196}
197
198impl LedgerObjectCommonFields for RippleState {
199    fn get_slot_num(&self) -> i32 {
200        self.slot_num
201    }
202}
203
204impl RippleStateFields for RippleState {}
205
206#[cfg(test)]
207mod tests {
208    use super::*;
209    use crate::host::host_bindings_trait::MockHostBindings;
210    use crate::host::setup_mock;
211    use crate::objects::test_utils::*;
212
213    #[test]
214    fn read_all_fields() {
215        let mut mock = MockHostBindings::new();
216        mock_all_fields_present(&mut mock);
217        let _guard = setup_mock(mock);
218
219        let obj = RippleState::new(0);
220
221        assert!(obj.balance().is_ok());
222        assert!(obj.low_limit().is_ok());
223        assert!(obj.high_limit().is_ok());
224        assert!(obj.previous_txn_id().is_ok());
225        assert!(obj.previous_txn_lgr_seq().is_ok());
226        assert!(obj.low_node().is_ok());
227        assert!(obj.low_quality_in().is_ok());
228        assert!(obj.low_quality_out().is_ok());
229        assert!(obj.high_node().is_ok());
230        assert!(obj.high_quality_in().is_ok());
231        assert!(obj.high_quality_out().is_ok());
232        assert!(obj.high_sponsor().is_ok());
233        assert!(obj.low_sponsor().is_ok());
234    }
235
236    #[test]
237    fn optional_fields_none() {
238        let mut mock = MockHostBindings::new();
239        mock_all_fields_not_found(&mut mock);
240        let _guard = setup_mock(mock);
241
242        let obj = RippleState::new(0);
243
244        assert!(obj.low_node().unwrap().is_none());
245        assert!(obj.low_quality_in().unwrap().is_none());
246        assert!(obj.low_quality_out().unwrap().is_none());
247        assert!(obj.high_node().unwrap().is_none());
248        assert!(obj.high_quality_in().unwrap().is_none());
249        assert!(obj.high_quality_out().unwrap().is_none());
250        assert!(obj.high_sponsor().unwrap().is_none());
251        assert!(obj.low_sponsor().unwrap().is_none());
252    }
253}