xrpl_api/api/
ledger_entry.rs

1//! <https://xrpl.org/ledger_entry.html>
2//!
3//! TIP: Better use the more specialized methods, like `get_offer_object`.
4
5use crate::{LedgerObject, Request, RetrieveLedgerSpec, ReturnLedgerSpec, WithLedgerSpec};
6use serde::{Deserialize, Serialize};
7
8#[derive(Default, Debug, Clone, Serialize)]
9pub struct LedgerEntryRequest {
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub binary: Option<bool>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub offer: Option<OfferParams>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub account_root: Option<String>,
16    #[serde(flatten)]
17    pub ledger_spec: RetrieveLedgerSpec,
18}
19
20#[derive(Default, Debug, Clone, Serialize)]
21pub struct OfferParams {
22    pub account: String,
23    pub seq: u32,
24}
25
26impl Request for LedgerEntryRequest {
27    type Response = LedgerEntryResponse;
28
29    fn method(&self) -> String {
30        "ledger_entry".to_owned()
31    }
32}
33
34impl WithLedgerSpec for LedgerEntryRequest {
35    fn as_ledger_spec(&self) -> &crate::RetrieveLedgerSpec {
36        &self.ledger_spec
37    }
38
39    fn as_ledger_spec_mut(&mut self) -> &mut crate::RetrieveLedgerSpec {
40        &mut self.ledger_spec
41    }
42}
43
44impl LedgerEntryRequest {
45    pub fn offer(account: impl Into<String>, sequence: u32) -> Self {
46        Self {
47            offer: Some(OfferParams {
48                account: account.into(),
49                seq: sequence,
50            }),
51            ..Default::default()
52        }
53    }
54
55    pub fn account(account: impl Into<String>) -> Self {
56        Self {
57            account_root: Some(account.into()),
58            ..Default::default()
59        }
60    }
61}
62
63#[derive(Debug, Deserialize)]
64pub struct LedgerEntryResponse {
65    /// The unique ID of this ledger object.
66    pub index: String,
67    /// (Omitted if "binary": true specified.) Object containing the data of this ledger object, according to the ledger format.
68    pub node: Option<LedgerObject>,
69    /// (Omitted unless "binary":true specified) The binary representation of the ledger object, as hexadecimal.
70    pub node_binary: Option<String>,
71    #[serde(flatten)]
72    pub ledger_spec: ReturnLedgerSpec,
73}