diff --git a/stellar_rust_sdk/src/horizon_client.rs b/stellar_rust_sdk/src/horizon_client.rs index 9db249e..e07ac2b 100644 --- a/stellar_rust_sdk/src/horizon_client.rs +++ b/stellar_rust_sdk/src/horizon_client.rs @@ -1986,7 +1986,7 @@ impl HorizonClient { /// # let horizon_client = HorizonClient::new(base_url) /// # .expect("Failed to create Horizon Client"); /// let request = PaymentsForLedgerRequest::new() - /// .set_ledger_sequence(12345678); + /// .set_ledger_sequence("48483".to_string()); /// /// let response = horizon_client.get_payments_for_ledger(&request).await; /// diff --git a/stellar_rust_sdk/src/lib.rs b/stellar_rust_sdk/src/lib.rs index a13497a..c001b09 100644 --- a/stellar_rust_sdk/src/lib.rs +++ b/stellar_rust_sdk/src/lib.rs @@ -15,7 +15,7 @@ //! stabilization. //! //! #### Supported endpoints: -//! ![80%](https://progress-bar.dev/80/?width=200) +//! ![86%](https://progress-bar.dev/67/?width=200) //! * Accounts //! * Assets //! * Claimable balance @@ -26,12 +26,12 @@ //! * Operations //! * Offers //! * Orderbook +//! * Payments //! * Trades //! * Trade aggregations //! //! #### Endpoints on the roadmap: //! * Paths -//! * Payments //! * Transactions //! @@ -509,30 +509,30 @@ pub mod operations; pub mod order_book; /// Provides `Request` and `Response` structs for retrieving trade aggregation details. -/// +/// /// The `trade_aggregations` module in the Stellar Horizon SDK includes structures and methods that facilitate /// querying trade aggregations data from the Horizon server. -/// +/// /// # Usage -/// +/// /// This module is used to construct requests for trade aggregations related data and to parse the responses /// received from the Horizon server. It includes request and response structures for querying /// trade aggregations. -/// +/// /// # Example -/// +/// /// To use this module, you can create an instance of a request struct, such as `TradeAggregationsRequest`, /// set any desired query parameters, and pass the request to the `HorizonClient`. The client will /// then execute the request and return the corresponding response struct, like `AllTradeAggregationsResponse`. -/// +/// /// ```rust /// use stellar_rs::horizon_client::HorizonClient; /// use stellar_rs::trade_aggregations::prelude::*; /// use stellar_rs::models::Request; -/// +/// /// # async fn example() -> Result<(), Box> { /// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?; -/// +/// /// // Example: Fetching trade aggregations /// let request = TradeAggregationsRequest::new() /// .set_base_asset(AssetType::Native).unwrap() @@ -542,7 +542,7 @@ pub mod order_book; /// })).unwrap() /// .set_resolution(Resolution(ResolutionData::Duration604800000)).unwrap(); /// let response = horizon_client.get_trade_aggregations(&request).await?; -/// +/// /// // Process the response... /// # Ok(()) /// # } @@ -632,6 +632,47 @@ pub mod transactions; /// pub mod trades; +/// Provides `Request` and `Response` structs for retrieving payments. +/// +/// This module provides a set of specialized request and response structures designed for +/// interacting with the payment-related endpoints of the Horizon server. These structures +/// facilitate the construction of requests to query trade data and the interpretation of +/// the corresponding responses. +/// +/// # Usage +/// +/// This module is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient) +/// for making specific payment-related API calls to the Horizon server. The request +/// structures are designed to be passed to the client's methods, which handle the +/// communication with the server and return the corresponding response structures. +/// +/// /// # Example +/// +/// To use this module, you can create an instance of a request struct, such as +/// `AllPaymentsRequest`, set any desired query parameters, and pass the request to the +/// `HorizonClient`. The client will then execute the request and return the corresponding +/// response struct, like `AllPaymentsResponse`. +/// +/// ```rust +/// use stellar_rs::horizon_client::HorizonClient; +/// use stellar_rs::payments::prelude::*; +/// use stellar_rs::models::Request; +/// +/// # async fn example() -> Result<(), Box> { +/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?; +/// +/// // Example: Fetching all payments +/// let all_payments_request = AllPaymentsRequest::new(); +/// +/// let all_payments_response = horizon_client.get_all_payments(&all_payments_request).await?; +/// +/// // Process the responses... +/// # Ok(()) +/// # } +/// ``` +/// +pub mod payments; + /// Contains core data structures and traits. /// /// This module is used by the Stellar Rust SDK to interact with the Horizon API. @@ -643,7 +684,6 @@ pub mod trades; /// of the Horizon API, allowing developers to work with high-level Rust constructs /// instead of raw HTTP requests and JSON responses. pub mod models; -mod payments; /// Extension trait for building query parameter strings from a vector of optional values. /// diff --git a/stellar_rust_sdk/src/payments/mod.rs b/stellar_rust_sdk/src/payments/mod.rs index bd8c58a..b7c360c 100644 --- a/stellar_rust_sdk/src/payments/mod.rs +++ b/stellar_rust_sdk/src/payments/mod.rs @@ -1,8 +1,49 @@ -mod all_payments_request; -mod payments_for_account_request; -mod payments_for_ledger_request; -mod payments_for_transaction_request; -mod response; +/// Provides the `AllPaymentsRequest` struct to build the request for the `/payments` endpoint +/// +/// # Usage +/// This module provides the `AllPaymentsRequest` struct, specifically for constructing requests to query information +/// about all payments made on the Stellar network. It is tailored for use in the `HorizonClient::get_all_payments` function. +pub mod all_payments_request; + +/// Provides the `PaymentsForAccountRequest` struct to build the request for the `/accounts/{account_id}/payments` endpoint +/// +/// # Usage +/// This module provides the `PaymentsForAccountRequest` struct, specifically for constructing requests to query information +/// about payments made to a specific account on the Stellar network. It is tailored for use in the `HorizonClient::get_payments_for_account` function. +/// +pub mod payments_for_account_request; + +/// Provides the `PaymentsForLedgerRequest` struct to build the request for the `/ledgers/{ledger_sequence}/payments` endpoint +/// +/// # Usage +/// This module provides the `PaymentsForLedgerRequest` struct, specifically for constructing requests to query information +/// about payments made in a specific ledger on the Stellar network. It is tailored for use in the `HorizonClient::get_payments_for_ledger` function. +/// +pub mod payments_for_ledger_request; + +/// Provides the `PaymentsForTransactionRequest` struct to build the request for the `/transactions/{transaction_hash}/payments` endpoint +/// +/// # Usage +/// This module provides the `PaymentsForTransactionRequest` struct, specifically for constructing requests to query information +/// about payments made in a specific transaction on the Stellar network. It is tailored for use in the `HorizonClient::get_payments_for_transaction` function. +/// +pub mod payments_for_transaction_request; + +/// Provides the `PaymentsResponse` struct to parse the response from the Horizon server when querying for payments +/// +/// This module defines structures representing the response from the Horizon API when querying +/// for payments. The structures are designed to deserialize the JSON response into Rust +/// objects, enabling straightforward access to various details of a single transaction. +/// Some fields are optional because not every payment response is exactly alike, but not different enough to warrent +/// different response structs for each type of payment. +/// +/// # Usage +/// This module provides the `PaymentsResponse` struct, which represents the response from the Horizon server when querying for payments. +/// It includes the links to the current, next, and previous pages of the response, as well as the embedded records of payments. +/// +pub mod response; + +static PAYMENTS_PATH: &str = "payments"; pub mod prelude { pub use super::all_payments_request::*; diff --git a/stellar_rust_sdk/src/payments/payments_for_account_request.rs b/stellar_rust_sdk/src/payments/payments_for_account_request.rs index dc7233c..5fb0ec4 100644 --- a/stellar_rust_sdk/src/payments/payments_for_account_request.rs +++ b/stellar_rust_sdk/src/payments/payments_for_account_request.rs @@ -1,4 +1,5 @@ use crate::models::{IncludeFailed, Order, Request}; +use crate::payments::PAYMENTS_PATH; use crate::Paginatable; use stellar_rust_sdk_derive::Pagination; @@ -75,9 +76,10 @@ impl Request for PaymentsForAccountRequest { let binding = "".to_string(); let account_id = self.account_id.as_ref().unwrap_or(&binding); format!( - "{}/accounts/{}/payments?{}", + "{}/accounts/{}/{}?{}", base_url, account_id, + PAYMENTS_PATH, self.get_query_parameters() ) } diff --git a/stellar_rust_sdk/src/payments/payments_for_ledger_request.rs b/stellar_rust_sdk/src/payments/payments_for_ledger_request.rs index bd1658b..ffe00f1 100644 --- a/stellar_rust_sdk/src/payments/payments_for_ledger_request.rs +++ b/stellar_rust_sdk/src/payments/payments_for_ledger_request.rs @@ -1,4 +1,5 @@ use crate::models::{IncludeFailed, Order, Request}; +use crate::payments::PAYMENTS_PATH; use crate::Paginatable; use stellar_rust_sdk_derive::Pagination; @@ -71,9 +72,10 @@ impl Request for PaymentsForLedgerRequest { let binding = "".to_string(); let ledger_sequence = self.ledger_sequence.as_ref().unwrap_or(&binding); format!( - "{}/ledgers/{}/payments?{}", + "{}/ledgers/{}/{}?{}", base_url, ledger_sequence, + PAYMENTS_PATH, self.get_query_parameters() ) } diff --git a/stellar_rust_sdk/src/payments/payments_for_transaction_request.rs b/stellar_rust_sdk/src/payments/payments_for_transaction_request.rs index 6a193d2..3ef849e 100644 --- a/stellar_rust_sdk/src/payments/payments_for_transaction_request.rs +++ b/stellar_rust_sdk/src/payments/payments_for_transaction_request.rs @@ -1,4 +1,5 @@ use crate::models::{Order, Request}; +use crate::payments::PAYMENTS_PATH; use crate::Paginatable; use stellar_rust_sdk_derive::Pagination; @@ -61,9 +62,10 @@ impl Request for PaymentsForTransactionRequest { let binding = "".to_string(); let transaction_hash = self.transaction_hash.as_ref().unwrap_or(&binding); format!( - "{}/transactions/{}/payments?{}", + "{}/transactions/{}/{}?{}", base_url, transaction_hash, + PAYMENTS_PATH, self.get_query_parameters() ) }