xrpl_api/api/
transaction_entry.rs

1//! The transaction_entry method retrieves information on a single transaction
2//! from a specific ledger version. (The tx method, by contrast, searches all
3//! ledgers for the specified transaction. We recommend using that method
4//! instead.)
5//!
6//! <https://xrpl.org/transaction_entry.html>
7
8use crate::{types::Meta, types::Transaction, LedgerIndex, Request};
9use serde::{Deserialize, Serialize};
10
11#[derive(Default, Debug, Clone, Serialize)]
12pub struct TransactionEntryRequest {
13    #[serde(skip_serializing_if = "Option::is_none")]
14    ledger_hash: Option<String>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    ledger_index: Option<LedgerIndex>,
17    /// Unique hash of the transaction you are looking up.
18    tx_hash: String,
19}
20
21impl Request for TransactionEntryRequest {
22    type Response = TransactionEntryResponse;
23
24    fn method(&self) -> String {
25        "transaction_entry".to_owned()
26    }
27}
28
29impl TransactionEntryRequest {
30    pub fn new(tx_hash: impl Into<String>) -> Self {
31        Self {
32            tx_hash: tx_hash.into(),
33            ..Default::default()
34        }
35    }
36
37    pub fn ledger_index(self, ledger_index: LedgerIndex) -> Self {
38        Self {
39            ledger_index: Some(ledger_index),
40            ..self
41        }
42    }
43}
44
45#[derive(Debug, Deserialize)]
46pub struct TransactionEntryResponse {
47    /// The ledger index of the ledger version the transaction was found in; this is the same as the one from the request.
48    pub ledger_index: u32,
49    /// The identifying hash of the ledger version the transaction was found in; this is the same as the one from the request.
50    pub ledger_hash: Option<String>,
51    pub metadata: Meta,
52    pub tx_json: Transaction,
53}