Skip to main content

xrpl_common_stdlib/objects/generated/
negative_unl.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::blob::StandardBlob;
9use crate::types::uint::Hash256;
10
11/// Trait providing access to fields specific to NegativeUNL objects in any ledger.
12pub trait NegativeUNLFields: LedgerObjectCommonFields {
13    /// The public key of a trusted validator that is scheduled to be disabled in the next flag
14    /// ledger.
15    fn validator_to_disable(&self) -> Result<Option<StandardBlob>> {
16        ledger_object::get_field_optional(self.get_slot_num(), sfield::ValidatorToDisable)
17    }
18
19    /// The public key of a trusted validator in the Negative UNL that is scheduled to be re-enabled
20    /// in the next flag ledger.
21    fn validator_to_re_enable(&self) -> Result<Option<StandardBlob>> {
22        ledger_object::get_field_optional(self.get_slot_num(), sfield::ValidatorToReEnable)
23    }
24
25    /// The identifying hash of the transaction that most recently modified this entry.
26    fn previous_txn_id(&self) -> Result<Option<Hash256>> {
27        ledger_object::get_field_optional(self.get_slot_num(), sfield::PreviousTxnID)
28    }
29
30    /// The index of the ledger that contains the transaction that most recently modified this
31    /// entry.
32    fn previous_txn_lgr_seq(&self) -> Result<Option<u32>> {
33        ledger_object::get_field_optional(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
34    }
35}
36
37/// Trait providing access to fields specific to the current NegativeUNL object.
38pub trait CurrentNegativeUNLFields: CurrentLedgerObjectCommonFields {
39    /// The public key of a trusted validator that is scheduled to be disabled in the next flag
40    /// ledger.
41    fn validator_to_disable(&self) -> Result<Option<StandardBlob>> {
42        current_ledger_object::get_field_optional(sfield::ValidatorToDisable)
43    }
44
45    /// The public key of a trusted validator in the Negative UNL that is scheduled to be re-enabled
46    /// in the next flag ledger.
47    fn validator_to_re_enable(&self) -> Result<Option<StandardBlob>> {
48        current_ledger_object::get_field_optional(sfield::ValidatorToReEnable)
49    }
50
51    /// The identifying hash of the transaction that most recently modified this entry.
52    fn previous_txn_id(&self) -> Result<Option<Hash256>> {
53        current_ledger_object::get_field_optional(sfield::PreviousTxnID)
54    }
55
56    /// The index of the ledger that contains the transaction that most recently modified this
57    /// entry.
58    fn previous_txn_lgr_seq(&self) -> Result<Option<u32>> {
59        current_ledger_object::get_field_optional(sfield::PreviousTxnLgrSeq)
60    }
61}
62
63#[derive(Debug, Clone, Copy, Eq, PartialEq)]
64pub struct NegativeUNL {
65    pub(crate) slot_num: i32,
66}
67
68impl NegativeUNL {
69    /// Binds this handle to a host-managed slot holding a NegativeUNL ledger object.
70    pub fn new(slot_num: i32) -> Self {
71        Self { slot_num }
72    }
73}
74
75impl LedgerObjectCommonFields for NegativeUNL {
76    fn get_slot_num(&self) -> i32 {
77        self.slot_num
78    }
79}
80
81impl NegativeUNLFields for NegativeUNL {}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86    use crate::host::host_bindings_trait::MockHostBindings;
87    use crate::host::setup_mock;
88    use crate::objects::test_utils::*;
89
90    #[test]
91    fn read_all_fields() {
92        let mut mock = MockHostBindings::new();
93        mock_all_fields_present(&mut mock);
94        let _guard = setup_mock(mock);
95
96        let obj = NegativeUNL::new(0);
97
98        assert!(obj.validator_to_disable().is_ok());
99        assert!(obj.validator_to_re_enable().is_ok());
100        assert!(obj.previous_txn_id().is_ok());
101        assert!(obj.previous_txn_lgr_seq().is_ok());
102    }
103
104    #[test]
105    fn optional_fields_none() {
106        let mut mock = MockHostBindings::new();
107        mock_all_fields_not_found(&mut mock);
108        let _guard = setup_mock(mock);
109
110        let obj = NegativeUNL::new(0);
111
112        assert!(obj.previous_txn_id().unwrap().is_none());
113        assert!(obj.previous_txn_lgr_seq().unwrap().is_none());
114    }
115}