Skip to main content

xrpl/models/requests/
submit_multisigned.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 Submit Multisigned:
19/// `<https://xrpl.org/submit_multisigned.html>`
20#[skip_serializing_none]
21#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
22pub struct SubmitMultisigned<'a> {
23    /// The common fields shared by all requests.
24    #[serde(flatten)]
25    pub common_fields: CommonFields<'a>,
26    pub tx_json: serde_json::Value,
27    /// If true, and the transaction fails locally, do not
28    /// retry or relay the transaction to other servers.
29    pub fail_hard: Option<bool>,
30}
31
32impl<'a> Model for SubmitMultisigned<'a> {}
33
34impl<'a> Request<'a> for SubmitMultisigned<'a> {
35    fn get_common_fields(&self) -> &CommonFields<'a> {
36        &self.common_fields
37    }
38
39    fn get_common_fields_mut(&mut self) -> &mut CommonFields<'a> {
40        &mut self.common_fields
41    }
42}
43
44impl<'a> SubmitMultisigned<'a> {
45    pub fn new(
46        id: Option<Cow<'a, str>>,
47        tx_json: serde_json::Value,
48        fail_hard: Option<bool>,
49    ) -> Self {
50        Self {
51            common_fields: CommonFields {
52                command: RequestMethod::SubmitMultisigned,
53                id,
54            },
55            fail_hard,
56            tx_json,
57        }
58    }
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_serde_round_trip() {
67        let tx_json = serde_json::json!({
68            "TransactionType": "Payment",
69            "Account": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
70        });
71        let req = SubmitMultisigned::new(Some("sm-1".into()), tx_json, Some(false));
72        let serialized = serde_json::to_string(&req).unwrap();
73        let deserialized: SubmitMultisigned = serde_json::from_str(&serialized).unwrap();
74        assert_eq!(req, deserialized);
75        assert!(serialized.contains("\"command\":\"submit_multisigned\""));
76        assert!(serialized.contains("\"fail_hard\":false"));
77    }
78}