Skip to main content

xrpl_common_stdlib/objects/generated/
xchain_owned_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::amount::Amount;
18use crate::types::uint::Hash256;
19
20/// Trait providing access to fields specific to XChainOwnedClaimID objects in any ledger.
21pub trait XChainOwnedClaimIDFields: 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    /// The unique sequence number for a cross-chain transfer.
43    fn xchain_claim_id(&self) -> Result<u64> {
44        ledger_object::get_field(self.get_slot_num(), sfield::XChainClaimID)
45    }
46
47    /// The account that must send the corresponding `XChainCommit` on the source chain. The
48    /// destination may be specified in the `XChainCommit` transaction, which means that if the
49    /// `OtherChainSource` isn't specified, another account can try to specify a different
50    /// destination and steal the funds. This also allows tracking only a single set of signatures,
51    /// since we know which account will send the `XChainCommit` transaction.
52    fn other_chain_source(&self) -> Result<AccountID> {
53        ledger_object::get_field(self.get_slot_num(), sfield::OtherChainSource)
54    }
55
56    /// The total amount to pay the witness servers for their signatures. It must be at least the
57    /// value of `SignatureReward` in the `Bridge` ledger object.
58    fn signature_reward(&self) -> Result<Amount> {
59        ledger_object::get_field(self.get_slot_num(), sfield::SignatureReward)
60    }
61
62    /// The OwnerNode field (Required).
63    fn owner_node(&self) -> Result<u64> {
64        ledger_object::get_field(self.get_slot_num(), sfield::OwnerNode)
65    }
66
67    /// The PreviousTxnID field (Required).
68    fn previous_txn_id(&self) -> Result<Hash256> {
69        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnID)
70    }
71
72    /// The PreviousTxnLgrSeq field (Required).
73    fn previous_txn_lgr_seq(&self) -> Result<u32> {
74        ledger_object::get_field(self.get_slot_num(), sfield::PreviousTxnLgrSeq)
75    }
76}
77
78/// Trait providing access to fields specific to the current XChainOwnedClaimID object.
79pub trait CurrentXChainOwnedClaimIDFields: CurrentLedgerObjectCommonFields {
80    /// The account that owns this object.
81    fn account(&self) -> Result<AccountID> {
82        current_ledger_object::get_field(sfield::Account)
83    }
84
85    /// The door accounts and assets of the bridge this object correlates to.
86    /// Raw bytes; XCHAIN_BRIDGE is not yet typed in Rust.
87    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    /// The unique sequence number for a cross-chain transfer.
100    fn xchain_claim_id(&self) -> Result<u64> {
101        current_ledger_object::get_field(sfield::XChainClaimID)
102    }
103
104    /// The account that must send the corresponding `XChainCommit` on the source chain. The
105    /// destination may be specified in the `XChainCommit` transaction, which means that if the
106    /// `OtherChainSource` isn't specified, another account can try to specify a different
107    /// destination and steal the funds. This also allows tracking only a single set of signatures,
108    /// since we know which account will send the `XChainCommit` transaction.
109    fn other_chain_source(&self) -> Result<AccountID> {
110        current_ledger_object::get_field(sfield::OtherChainSource)
111    }
112
113    /// The total amount to pay the witness servers for their signatures. It must be at least the
114    /// value of `SignatureReward` in the `Bridge` ledger object.
115    fn signature_reward(&self) -> Result<Amount> {
116        current_ledger_object::get_field(sfield::SignatureReward)
117    }
118
119    /// The OwnerNode field (Required).
120    fn owner_node(&self) -> Result<u64> {
121        current_ledger_object::get_field(sfield::OwnerNode)
122    }
123
124    /// The PreviousTxnID field (Required).
125    fn previous_txn_id(&self) -> Result<Hash256> {
126        current_ledger_object::get_field(sfield::PreviousTxnID)
127    }
128
129    /// The PreviousTxnLgrSeq field (Required).
130    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    /// Binds this handle to a host-managed slot holding a XChainOwnedClaimID ledger object.
142    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}