xrpl_api/api/
ripple_path_find.rs

1//! The ripple_path_find method is a simplified version of the path_find method
2//! that provides a single response with a payment path you can use right away.
3//! It is available in both the WebSocket and JSON-RPC APIs. However, the
4//! results tend to become outdated as time passes. Instead of making multiple
5//! calls to stay updated, you should instead use the path_find method to
6//! subscribe to continued updates where possible.
7//!
8//! Although the rippled server tries to find the cheapest path or combination
9//! of paths for making a payment, it is not guaranteed that the paths
10//! returned by this method are, in fact, the best paths.
11//!
12//! <https://xrpl.org/ripple_path_find.html>
13//!
14//! <https://xrpl.org/paths.html>
15
16use serde::{Deserialize, Serialize};
17use serde_json::Value;
18
19use crate::{Amount, Request};
20
21// #TODO is Clone really needed?
22#[derive(Default, Debug, Clone, Serialize)]
23pub struct RipplePathFindRequest {
24    /// Unique address of the account that would send funds in a transaction.
25    source_account: String,
26    /// Unique address of the account that would receive funds in a transaction.
27    destination_account: String,
28    /// Currency Amount that the destination account would receive in a
29    /// transaction. Special case: New in: rippled 0.30.0  You can specify "-1"
30    /// (for XRP) or provide -1 as the contents of the value field
31    /// (for non-XRP currencies). This requests a path to deliver as much as
32    /// possible, while spending no more than the amount specified in
33    /// send_max (if provided).
34    destination_amount: Amount,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    send_max: Option<Amount>,
37    /// A 20-byte hex string for the ledger version to use.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub ledger_hash: Option<String>,
40    /// The ledger index of the ledger to use, or a shortcut string to choose a
41    /// ledger automatically.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub ledger_index: Option<String>,
44}
45
46impl Request for RipplePathFindRequest {
47    type Response = RipplePathFindResponse;
48
49    fn method(&self) -> String {
50        "ripple_path_find".to_owned()
51    }
52}
53
54impl RipplePathFindRequest {
55    pub fn new(
56        source_account: &str,
57        destination_account: &str,
58        destination_amount: Amount,
59    ) -> Self {
60        Self {
61            source_account: source_account.to_owned(),
62            destination_account: destination_account.to_owned(),
63            destination_amount,
64            ..Default::default()
65        }
66    }
67}
68
69#[derive(Debug, Deserialize)]
70pub struct Path {
71    // #TODO full types missing
72    /// Array of arrays of objects defining payment paths.
73    pub paths_computed: Vec<Vec<Value>>,
74    /// Currency Amount that the source would have to send along this path for
75    /// the destination to receive the desired amount.
76    pub source_amount: Amount,
77}
78
79#[derive(Debug, Deserialize)]
80pub struct RipplePathFindResponse {
81    pub alternatives: Vec<Path>,
82    pub destination_account: String,
83    pub destination_currencies: Vec<String>,
84}