xrpl_common_stdlib/objects/generated/
xchain_owned_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::amount::Amount;
18use crate::types::uint::Hash256;
19
20pub trait XChainOwnedClaimIDFields: 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_claim_id(&self) -> Result<u64> {
44 ledger_object::get_field(self.get_slot_num(), sfield::XChainClaimID)
45 }
46
47 fn other_chain_source(&self) -> Result<AccountID> {
53 ledger_object::get_field(self.get_slot_num(), sfield::OtherChainSource)
54 }
55
56 fn signature_reward(&self) -> Result<Amount> {
59 ledger_object::get_field(self.get_slot_num(), sfield::SignatureReward)
60 }
61
62 fn owner_node(&self) -> Result<u64> {
64 ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
65 }
66
67 fn previous_txn_id(&self) -> Result<Hash256> {
69 ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
70 }
71
72 fn previous_txn_lgr_seq(&self) -> Result<u32> {
74 ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
75 }
76}
77
78pub trait CurrentXChainOwnedClaimIDFields: CurrentLedgerObjectCommonFields {
80 fn account(&self) -> Result<AccountID> {
82 current_ledger_object::get_field(sfield::Account)
83 }
84
85 fn xchain_bridge(&self) -> Result<[u8; RAW_UNMAPPED_FIELD_SIZE]> {
88 let mut buffer = [0u8; RAW_UNMAPPED_FIELD_SIZE];
89 let result_code = unsafe {
90 home_le_field(
91 sfield::XChainBridge.into(),
92 buffer.as_mut_ptr(),
93 buffer.len(),
94 )
95 };
96 match_result_code(result_code, || buffer)
97 }
98
99 fn xchain_claim_id(&self) -> Result<u64> {
101 current_ledger_object::get_field(sfield::XChainClaimID)
102 }
103
104 fn other_chain_source(&self) -> Result<AccountID> {
110 current_ledger_object::get_field(sfield::OtherChainSource)
111 }
112
113 fn signature_reward(&self) -> Result<Amount> {
116 current_ledger_object::get_field(sfield::SignatureReward)
117 }
118
119 fn owner_node(&self) -> Result<u64> {
121 current_ledger_object::get_field(sfield::OwnerNode)
122 }
123
124 fn previous_txn_id(&self) -> Result<Hash256> {
126 current_ledger_object::get_field(sfield::PreviousTxnID)
127 }
128
129 fn previous_txn_lgr_seq(&self) -> Result<u32> {
131 current_ledger_object::get_field(sfield::PreviousTxnLgrSeq)
132 }
133}
134
135#[derive(Debug, Clone, Copy, Eq, PartialEq)]
136pub struct XChainOwnedClaimID {
137 pub(crate) slot_num: i32,
138}
139
140impl XChainOwnedClaimID {
141 pub fn new(slot_num: i32) -> Self {
143 Self { slot_num }
144 }
145}
146
147impl LedgerObjectCommonFields for XChainOwnedClaimID {
148 fn get_slot_num(&self) -> i32 {
149 self.slot_num
150 }
151}
152
153impl XChainOwnedClaimIDFields for XChainOwnedClaimID {}
154
155#[cfg(test)]
156mod tests {
157 use super::*;
158 use crate::host::host_bindings_trait::MockHostBindings;
159 use crate::host::setup_mock;
160 use crate::objects::test_utils::*;
161
162 #[test]
163 fn read_all_fields() {
164 let mut mock = MockHostBindings::new();
165 mock_all_fields_present(&mut mock);
166 let _guard = setup_mock(mock);
167
168 let obj = XChainOwnedClaimID::new(0);
169
170 assert!(obj.account().is_ok());
171 assert!(obj.xchain_bridge().is_ok());
172 assert!(obj.xchain_claim_id().is_ok());
173 assert!(obj.other_chain_source().is_ok());
174 assert!(obj.signature_reward().is_ok());
175 assert!(obj.owner_node().is_ok());
176 assert!(obj.previous_txn_id().is_ok());
177 assert!(obj.previous_txn_lgr_seq().is_ok());
178 }
179}