Skip to main content

xrpl_common_stdlib/objects/generated/
fee_settings.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::amount::Amount;
9use crate::types::uint::Hash256;
10
11/// Trait providing access to fields specific to FeeSettings objects in any ledger.
12pub trait FeeSettingsFields: LedgerObjectCommonFields {
13    /// The transaction cost of the "reference transaction" in drops of XRP as hexadecimal.
14    fn base_fee(&self) -> Result<Option<u64>> {
15        ledger_object::get_field_optional(self.get_slot_num(), sfield::BaseFee)
16    }
17
18    /// The `BaseFee` translated into "fee units".
19    fn reference_fee_units(&self) -> Result<Option<u32>> {
20        ledger_object::get_field_optional(self.get_slot_num(), sfield::ReferenceFeeUnits)
21    }
22
23    /// The base reserve for an account in the XRP Ledger, as drops of XRP.
24    fn reserve_base(&self) -> Result<Option<u32>> {
25        ledger_object::get_field_optional(self.get_slot_num(), sfield::ReserveBase)
26    }
27
28    /// The incremental owner reserve for owning objects, as drops of XRP.
29    fn reserve_increment(&self) -> Result<Option<u32>> {
30        ledger_object::get_field_optional(self.get_slot_num(), sfield::ReserveIncrement)
31    }
32
33    /// The transaction cost of the "reference transaction" in drops of XRP.
34    fn base_fee_drops(&self) -> Result<Option<Amount>> {
35        ledger_object::get_field_optional(self.get_slot_num(), sfield::BaseFeeDrops)
36    }
37
38    /// The base reserve for an account in the XRP Ledger, as drops of XRP.
39    fn reserve_base_drops(&self) -> Result<Option<Amount>> {
40        ledger_object::get_field_optional(self.get_slot_num(), sfield::ReserveBaseDrops)
41    }
42
43    /// The incremental owner reserve for owning objects, as drops of XRP.
44    fn reserve_increment_drops(&self) -> Result<Option<Amount>> {
45        ledger_object::get_field_optional(self.get_slot_num(), sfield::ReserveIncrementDrops)
46    }
47
48    /// The GasLimit field (Optional).
49    fn gas_limit(&self) -> Result<Option<u32>> {
50        ledger_object::get_field_optional(self.get_slot_num(), sfield::GasLimit)
51    }
52
53    /// The BytecodeSizeLimit field (Optional).
54    fn bytecode_size_limit(&self) -> Result<Option<u32>> {
55        ledger_object::get_field_optional(self.get_slot_num(), sfield::BytecodeSizeLimit)
56    }
57
58    /// The GasPrice field (Optional).
59    fn gas_price(&self) -> Result<Option<u32>> {
60        ledger_object::get_field_optional(self.get_slot_num(), sfield::GasPrice)
61    }
62
63    /// The identifying hash of the transaction that most recently modified this entry.
64    fn previous_txn_id(&self) -> Result<Option<Hash256>> {
65        ledger_object::get_field_optional(self.get_slot_num(), sfield::PreviousTxnID)
66    }
67
68    /// The index of the ledger that contains the transaction that most recently modified this
69    /// entry.
70    fn previous_txn_lgr_seq(&self) -> Result<Option<u32>> {
71        ledger_object::get_field_optional(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
72    }
73}
74
75/// Trait providing access to fields specific to the current FeeSettings object.
76pub trait CurrentFeeSettingsFields: CurrentLedgerObjectCommonFields {
77    /// The transaction cost of the "reference transaction" in drops of XRP as hexadecimal.
78    fn base_fee(&self) -> Result<Option<u64>> {
79        current_ledger_object::get_field_optional(sfield::BaseFee)
80    }
81
82    /// The `BaseFee` translated into "fee units".
83    fn reference_fee_units(&self) -> Result<Option<u32>> {
84        current_ledger_object::get_field_optional(sfield::ReferenceFeeUnits)
85    }
86
87    /// The base reserve for an account in the XRP Ledger, as drops of XRP.
88    fn reserve_base(&self) -> Result<Option<u32>> {
89        current_ledger_object::get_field_optional(sfield::ReserveBase)
90    }
91
92    /// The incremental owner reserve for owning objects, as drops of XRP.
93    fn reserve_increment(&self) -> Result<Option<u32>> {
94        current_ledger_object::get_field_optional(sfield::ReserveIncrement)
95    }
96
97    /// The transaction cost of the "reference transaction" in drops of XRP.
98    fn base_fee_drops(&self) -> Result<Option<Amount>> {
99        current_ledger_object::get_field_optional(sfield::BaseFeeDrops)
100    }
101
102    /// The base reserve for an account in the XRP Ledger, as drops of XRP.
103    fn reserve_base_drops(&self) -> Result<Option<Amount>> {
104        current_ledger_object::get_field_optional(sfield::ReserveBaseDrops)
105    }
106
107    /// The incremental owner reserve for owning objects, as drops of XRP.
108    fn reserve_increment_drops(&self) -> Result<Option<Amount>> {
109        current_ledger_object::get_field_optional(sfield::ReserveIncrementDrops)
110    }
111
112    /// The GasLimit field (Optional).
113    fn gas_limit(&self) -> Result<Option<u32>> {
114        current_ledger_object::get_field_optional(sfield::GasLimit)
115    }
116
117    /// The BytecodeSizeLimit field (Optional).
118    fn bytecode_size_limit(&self) -> Result<Option<u32>> {
119        current_ledger_object::get_field_optional(sfield::BytecodeSizeLimit)
120    }
121
122    /// The GasPrice field (Optional).
123    fn gas_price(&self) -> Result<Option<u32>> {
124        current_ledger_object::get_field_optional(sfield::GasPrice)
125    }
126
127    /// The identifying hash of the transaction that most recently modified this entry.
128    fn previous_txn_id(&self) -> Result<Option<Hash256>> {
129        current_ledger_object::get_field_optional(sfield::PreviousTxnID)
130    }
131
132    /// The index of the ledger that contains the transaction that most recently modified this
133    /// entry.
134    fn previous_txn_lgr_seq(&self) -> Result<Option<u32>> {
135        current_ledger_object::get_field_optional(sfield::PreviousTxnLgrSeq)
136    }
137}
138
139#[derive(Debug, Clone, Copy, Eq, PartialEq)]
140pub struct FeeSettings {
141    pub(crate) slot_num: i32,
142}
143
144impl FeeSettings {
145    /// Binds this handle to a host-managed slot holding a FeeSettings ledger object.
146    pub fn new(slot_num: i32) -> Self {
147        Self { slot_num }
148    }
149}
150
151impl LedgerObjectCommonFields for FeeSettings {
152    fn get_slot_num(&self) -> i32 {
153        self.slot_num
154    }
155}
156
157impl FeeSettingsFields for FeeSettings {}
158
159#[cfg(test)]
160mod tests {
161    use super::*;
162    use crate::host::host_bindings_trait::MockHostBindings;
163    use crate::host::setup_mock;
164    use crate::objects::test_utils::*;
165
166    #[test]
167    fn read_all_fields() {
168        let mut mock = MockHostBindings::new();
169        mock_all_fields_present(&mut mock);
170        let _guard = setup_mock(mock);
171
172        let obj = FeeSettings::new(0);
173
174        assert!(obj.base_fee().is_ok());
175        assert!(obj.reference_fee_units().is_ok());
176        assert!(obj.reserve_base().is_ok());
177        assert!(obj.reserve_increment().is_ok());
178        assert!(obj.base_fee_drops().is_ok());
179        assert!(obj.reserve_base_drops().is_ok());
180        assert!(obj.reserve_increment_drops().is_ok());
181        assert!(obj.gas_limit().is_ok());
182        assert!(obj.bytecode_size_limit().is_ok());
183        assert!(obj.gas_price().is_ok());
184        assert!(obj.previous_txn_id().is_ok());
185        assert!(obj.previous_txn_lgr_seq().is_ok());
186    }
187
188    #[test]
189    fn optional_fields_none() {
190        let mut mock = MockHostBindings::new();
191        mock_all_fields_not_found(&mut mock);
192        let _guard = setup_mock(mock);
193
194        let obj = FeeSettings::new(0);
195
196        assert!(obj.base_fee().unwrap().is_none());
197        assert!(obj.reference_fee_units().unwrap().is_none());
198        assert!(obj.reserve_base().unwrap().is_none());
199        assert!(obj.reserve_increment().unwrap().is_none());
200        assert!(obj.gas_limit().unwrap().is_none());
201        assert!(obj.bytecode_size_limit().unwrap().is_none());
202        assert!(obj.gas_price().unwrap().is_none());
203        assert!(obj.previous_txn_id().unwrap().is_none());
204        assert!(obj.previous_txn_lgr_seq().unwrap().is_none());
205    }
206}