xrpl/models/requests/
server_state.rs

1use alloc::borrow::Cow;
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5use crate::models::{requests::RequestMethod, Model};
6
7use super::{CommonFields, Request};
8
9/// The server_state command asks the server for various
10/// machine-readable information about the rippled server's
11/// current state. The response is almost the same as the
12/// server_info method, but uses units that are easier to
13/// process instead of easier to read. (For example, XRP
14/// values are given in integer drops instead of scientific
15/// notation or decimal values, and time is given in
16/// milliseconds instead of seconds.)
17///
18/// See Server State:
19/// `<https://xrpl.org/server_state.html#server_state>`
20#[skip_serializing_none]
21#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
22pub struct ServerState<'a> {
23    /// The common fields shared by all requests.
24    #[serde(flatten)]
25    pub common_fields: CommonFields<'a>,
26    pub ledger_index: Option<Cow<'a, str>>,
27}
28
29impl<'a> Model for ServerState<'a> {}
30
31impl<'a> Request<'a> for ServerState<'a> {
32    fn get_common_fields(&self) -> &CommonFields<'a> {
33        &self.common_fields
34    }
35
36    fn get_common_fields_mut(&mut self) -> &mut CommonFields<'a> {
37        &mut self.common_fields
38    }
39}
40
41impl<'a> ServerState<'a> {
42    pub fn new(id: Option<Cow<'a, str>>) -> Self {
43        Self {
44            ledger_index: Some("current".into()),
45            common_fields: CommonFields {
46                command: RequestMethod::ServerState,
47                id,
48            },
49        }
50    }
51}