xrpl/models/requests/submit.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 submit method applies a transaction and sends it to
10/// the network to be confirmed and included in future ledgers.
11///
12/// This command has two modes:
13/// * Submit-only mode takes a signed, serialized transaction
14/// as a binary blob, and submits it to the network as-is.
15/// Since signed transaction objects are immutable, no part
16/// of the transaction can be modified or automatically
17/// filled in after submission.
18/// * Sign-and-submit mode takes a JSON-formatted Transaction
19/// object, completes and signs the transaction in the same
20/// manner as the sign method, and then submits the signed
21/// transaction. We recommend only using this mode for
22/// testing and development.
23///
24/// To send a transaction as robustly as possible, you should
25/// construct and sign it in advance, persist it somewhere that
26/// you can access even after a power outage, then submit it as
27/// a tx_blob. After submission, monitor the network with the
28/// tx method command to see if the transaction was successfully
29/// applied; if a restart or other problem occurs, you can
30/// safely re-submit the tx_blob transaction: it won't be
31/// applied twice since it has the same sequence number as the
32/// old transaction.
33///
34/// See Submit:
35/// `<https://xrpl.org/submit.html>`
36#[skip_serializing_none]
37#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
38pub struct Submit<'a> {
39 /// The common fields shared by all requests.
40 #[serde(flatten)]
41 pub common_fields: CommonFields<'a>,
42 /// Hex representation of the signed transaction to submit.
43 /// This can also be a multi-signed transaction.
44 pub tx_blob: Cow<'a, str>,
45 /// If true, and the transaction fails locally, do not retry
46 /// or relay the transaction to other servers
47 pub fail_hard: Option<bool>,
48}
49
50impl<'a> Model for Submit<'a> {}
51
52impl<'a> Request<'a> for Submit<'a> {
53 fn get_common_fields(&self) -> &CommonFields<'a> {
54 &self.common_fields
55 }
56
57 fn get_common_fields_mut(&mut self) -> &mut CommonFields<'a> {
58 &mut self.common_fields
59 }
60}
61
62impl<'a> Submit<'a> {
63 pub fn new(id: Option<Cow<'a, str>>, tx_blob: Cow<'a, str>, fail_hard: Option<bool>) -> Self {
64 Self {
65 common_fields: CommonFields {
66 command: RequestMethod::Submit,
67 id,
68 },
69 tx_blob,
70 fail_hard,
71 }
72 }
73}