xrpl_common_stdlib/objects/generated/
xchain_owned_create_account_claim_id.rs1const 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
19pub trait XChainOwnedCreateAccountClaimIDFields: LedgerObjectCommonFields {
22 fn account(&self) -> Result<AccountID> {
24 ledger_object::get_field(self.get_slot_num(), sfield::Account)
25 }
26
27 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 fn xchain_account_create_count(&self) -> Result<u64> {
45 ledger_object::get_field(self.get_slot_num(), sfield::XChainAccountCreateCount)
46 }
47
48 fn owner_node(&self) -> Result<u64> {
50 ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
51 }
52
53 fn previous_txn_id(&self) -> Result<Hash256> {
55 ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
56 }
57
58 fn previous_txn_lgr_seq(&self) -> Result<u32> {
60 ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
61 }
62}
63
64pub trait CurrentXChainOwnedCreateAccountClaimIDFields: CurrentLedgerObjectCommonFields {
66 fn account(&self) -> Result<AccountID> {
68 current_ledger_object::get_field(sfield::Account)
69 }
70
71 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 fn xchain_account_create_count(&self) -> Result<u64> {
88 current_ledger_object::get_field(sfield::XChainAccountCreateCount)
89 }
90
91 fn owner_node(&self) -> Result<u64> {
93 current_ledger_object::get_field(sfield::OwnerNode)
94 }
95
96 fn previous_txn_id(&self) -> Result<Hash256> {
98 current_ledger_object::get_field(sfield::PreviousTxnID)
99 }
100
101 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 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}