Skip to content

Commit

Permalink
cleanup and lib documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardTibben committed Jul 26, 2024
1 parent a6b8ac4 commit eb590ec
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 21 deletions.
2 changes: 1 addition & 1 deletion stellar_rust_sdk/src/horizon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
///
Expand Down
64 changes: 52 additions & 12 deletions stellar_rust_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,12 +26,12 @@
//! * Operations
//! * Offers
//! * Orderbook
//! * Payments
//! * Trades
//! * Trade aggregations
//!
//! #### Endpoints on the roadmap:
//! * Paths
//! * Payments
//! * Transactions
//!
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
/// 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()
Expand All @@ -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(())
/// # }
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
/// 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.
Expand All @@ -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.
///
Expand Down
51 changes: 46 additions & 5 deletions stellar_rust_sdk/src/payments/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::models::{IncludeFailed, Order, Request};
use crate::payments::PAYMENTS_PATH;
use crate::Paginatable;
use stellar_rust_sdk_derive::Pagination;

Expand Down Expand Up @@ -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()
)
}
Expand Down
4 changes: 3 additions & 1 deletion stellar_rust_sdk/src/payments/payments_for_ledger_request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::models::{IncludeFailed, Order, Request};
use crate::payments::PAYMENTS_PATH;
use crate::Paginatable;
use stellar_rust_sdk_derive::Pagination;

Expand Down Expand Up @@ -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()
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::models::{Order, Request};
use crate::payments::PAYMENTS_PATH;
use crate::Paginatable;
use stellar_rust_sdk_derive::Pagination;

Expand Down Expand Up @@ -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()
)
}
Expand Down

0 comments on commit eb590ec

Please sign in to comment.