xrpl/models/requests/
account_objects.rs

1use alloc::borrow::Cow;
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4use strum_macros::{Display, EnumString};
5
6use crate::models::{requests::RequestMethod, Model};
7
8use super::{CommonFields, LedgerIndex, LookupByLedgerRequest, Marker, Request};
9
10/// Represents the object types that an AccountObjects
11/// Request can ask for.
12#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, Display, EnumString)]
13#[strum(serialize_all = "snake_case")]
14#[serde(rename_all = "snake_case")]
15#[serde(tag = "type")]
16pub enum AccountObjectType {
17    Check,
18    DepositPreauth,
19    Escrow,
20    Offer,
21    PaymentChannel,
22    SignerList,
23    State,
24    Ticket,
25}
26
27/// This request returns the raw ledger format for all objects
28/// owned by an account. For a higher-level view of an account's
29/// trust lines and balances, see AccountLines Request instead.
30///
31/// See Account Objects:
32/// `<https://xrpl.org/account_objects.html>`
33#[skip_serializing_none]
34#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
35pub struct AccountObjects<'a> {
36    /// The common fields shared by all requests.
37    #[serde(flatten)]
38    pub common_fields: CommonFields<'a>,
39    /// A unique identifier for the account, most commonly the
40    /// account's address.
41    pub account: Cow<'a, str>,
42    /// The unique identifier of a ledger.
43    #[serde(flatten)]
44    pub ledger_lookup: Option<LookupByLedgerRequest<'a>>,
45    /// If included, filter results to include only this type
46    /// of ledger object. The valid types are: check, deposit_preauth,
47    /// escrow, offer, payment_channel, signer_list, ticket,
48    /// and state (trust line).
49    pub r#type: Option<AccountObjectType>,
50    /// If true, the response only includes objects that would block
51    /// this account from being deleted. The default is false.
52    pub deletion_blockers_only: Option<bool>,
53    /// The maximum number of objects to include in the results.
54    /// Must be within the inclusive range 10 to 400 on non-admin
55    /// connections. The default is 200.
56    pub limit: Option<u16>,
57    /// Value from a previous paginated response. Resume retrieving
58    /// data where that response left off.
59    pub marker: Option<Marker<'a>>,
60}
61
62impl<'a> Model for AccountObjects<'a> {}
63
64impl<'a> Request<'a> for AccountObjects<'a> {
65    fn get_common_fields(&self) -> &CommonFields<'a> {
66        &self.common_fields
67    }
68
69    fn get_common_fields_mut(&mut self) -> &mut CommonFields<'a> {
70        &mut self.common_fields
71    }
72}
73
74impl<'a> AccountObjects<'a> {
75    pub fn new(
76        id: Option<Cow<'a, str>>,
77        account: Cow<'a, str>,
78        ledger_hash: Option<Cow<'a, str>>,
79        ledger_index: Option<LedgerIndex<'a>>,
80        r#type: Option<AccountObjectType>,
81        deletion_blockers_only: Option<bool>,
82        limit: Option<u16>,
83        marker: Option<Marker<'a>>,
84    ) -> Self {
85        Self {
86            common_fields: CommonFields {
87                command: RequestMethod::AccountObjects,
88                id,
89            },
90            account,
91            ledger_lookup: Some(LookupByLedgerRequest {
92                ledger_hash,
93                ledger_index,
94            }),
95            r#type,
96            deletion_blockers_only,
97            limit,
98            marker,
99        }
100    }
101}