Skip to main content

xrpl_common_stdlib/objects/generated/
xchain_owned_create_account_claim_id.rs

1// GENERATED -- do not hand-edit. Run scripts/generate-ledger-objects.sh to regenerate.
2
3/// Placeholder buffer size for fields whose XRPL wire type has no genuine Rust
4/// mapping yet (VECTOR256, XCHAIN_BRIDGE, PATHSET, ...). Such getters return
5/// raw, unparsed bytes; see the summary at the top of `generated/mod.rs`.
6const RAW_UNMAPPED_FIELD_SIZE: usize = 512;
7
8use crate::host::Result;
9use crate::host::error_codes::match_result_code;
10use crate::host::home_le_field;
11use crate::host::le_field;
12use crate::objects::traits::CurrentLedgerObjectCommonFields;
13use crate::objects::traits::LedgerObjectCommonFields;
14use crate::objects::{current_ledger_object, ledger_object};
15use crate::sfield;
16use crate::types::account_id::AccountID;
17use crate::types::uint::Hash256;
18
19/// Trait providing access to fields specific to XChainOwnedCreateAccountClaimID objects in any
20/// ledger.
21pub trait XChainOwnedCreateAccountClaimIDFields: LedgerObjectCommonFields {
22    /// The account that owns this object.
23    fn account(&self) -> Result<AccountID> {
24        ledger_object::get_field(self.get_slot_num(), sfield::Account)
25    }
26
27    /// The door accounts and assets of the bridge this object correlates to.
28    /// Raw bytes; XCHAIN_BRIDGE is not yet typed in Rust.
29    fn xchain_bridge(&self) -> Result<[u8; RAW_UNMAPPED_FIELD_SIZE]> {
30        let mut buffer = [0u8; RAW_UNMAPPED_FIELD_SIZE];
31        let result_code = unsafe {
32            le_field(
33                self.get_slot_num(),
34                sfield::XChainBridge.into(),
35                buffer.as_mut_ptr(),
36                buffer.len(),
37            )
38        };
39        match_result_code(result_code, || buffer)
40    }
41
42    /// An integer that determines the order that accounts created through cross-chain transfers
43    /// must be performed. Smaller numbers must execute before larger numbers.
44    fn xchain_account_create_count(&self) -> Result<u64> {
45        ledger_object::get_field(self.get_slot_num(), sfield::XChainAccountCreateCount)
46    }
47
48    /// The OwnerNode field (Required).
49    fn owner_node(&self) -> Result<u64> {
50        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
51    }
52
53    /// The PreviousTxnID field (Required).
54    fn previous_txn_id(&self) -> Result<Hash256> {
55        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
56    }
57
58    /// The PreviousTxnLgrSeq field (Required).
59    fn previous_txn_lgr_seq(&self) -> Result<u32> {
60        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
61    }
62}
63
64/// Trait providing access to fields specific to the current XChainOwnedCreateAccountClaimID object.
65pub trait CurrentXChainOwnedCreateAccountClaimIDFields: CurrentLedgerObjectCommonFields {
66    /// The account that owns this object.
67    fn account(&self) -> Result<AccountID> {
68        current_ledger_object::get_field(sfield::Account)
69    }
70
71    /// The door accounts and assets of the bridge this object correlates to.
72    /// Raw bytes; XCHAIN_BRIDGE is not yet typed in Rust.
73    fn xchain_bridge(&self) -> Result<[u8; RAW_UNMAPPED_FIELD_SIZE]> {
74        let mut buffer = [0u8; RAW_UNMAPPED_FIELD_SIZE];
75        let result_code = unsafe {
76            home_le_field(
77                sfield::XChainBridge.into(),
78                buffer.as_mut_ptr(),
79                buffer.len(),
80            )
81        };
82        match_result_code(result_code, || buffer)
83    }
84
85    /// An integer that determines the order that accounts created through cross-chain transfers
86    /// must be performed. Smaller numbers must execute before larger numbers.
87    fn xchain_account_create_count(&self) -> Result<u64> {
88        current_ledger_object::get_field(sfield::XChainAccountCreateCount)
89    }
90
91    /// The OwnerNode field (Required).
92    fn owner_node(&self) -> Result<u64> {
93        current_ledger_object::get_field(sfield::OwnerNode)
94    }
95
96    /// The PreviousTxnID field (Required).
97    fn previous_txn_id(&self) -> Result<Hash256> {
98        current_ledger_object::get_field(sfield::PreviousTxnID)
99    }
100
101    /// The PreviousTxnLgrSeq field (Required).
102    fn previous_txn_lgr_seq(&self) -> Result<u32> {
103        current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
104    }
105}
106
107#[derive(Debug, Clone, Copy, Eq, PartialEq)]
108pub struct XChainOwnedCreateAccountClaimID {
109    pub(crate) slot_num: i32,
110}
111
112impl XChainOwnedCreateAccountClaimID {
113    /// Binds this handle to a host-managed slot holding a XChainOwnedCreateAccountClaimID ledger
114    /// object.
115    pub fn new(slot_num: i32) -> Self {
116        Self { slot_num }
117    }
118}
119
120impl LedgerObjectCommonFields for XChainOwnedCreateAccountClaimID {
121    fn get_slot_num(&self) -> i32 {
122        self.slot_num
123    }
124}
125
126impl XChainOwnedCreateAccountClaimIDFields for XChainOwnedCreateAccountClaimID {}
127
128#[cfg(test)]
129mod tests {
130    use super::*;
131    use crate::host::host_bindings_trait::MockHostBindings;
132    use crate::host::setup_mock;
133    use crate::objects::test_utils::*;
134
135    #[test]
136    fn read_all_fields() {
137        let mut mock = MockHostBindings::new();
138        mock_all_fields_present(&mut mock);
139        let _guard = setup_mock(mock);
140
141        let obj = XChainOwnedCreateAccountClaimID::new(0);
142
143        assert!(obj.account().is_ok());
144        assert!(obj.xchain_bridge().is_ok());
145        assert!(obj.xchain_account_create_count().is_ok());
146        assert!(obj.owner_node().is_ok());
147        assert!(obj.previous_txn_id().is_ok());
148        assert!(obj.previous_txn_lgr_seq().is_ok());
149    }
150}