Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-pease authored and LeonardTibben committed Jun 14, 2024
1 parent 97b2c08 commit 7112430
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 6 deletions.
36 changes: 36 additions & 0 deletions stellar_rust_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,42 @@ pub mod effects;
///
pub mod fee_stats;

/// Provides `Request` and `Response` structs for retrieving liquidity pools.
///
/// The `liquidity_pools` module in the Stellar Horizon SDK includes structures and methods that facilitate
/// querying liquidity pool data from the Horizon server.
///
/// # Usage
///
/// This module is used to construct requests for liquidity pool related data and to parse the responses
/// received from the Horizon server. It includes request and response structures for querying
/// liquidity pool data.
///
/// # Example
///
/// To use this module, you can create an instance of a request struct, such as `SingleLiquidityPoolRequest`,
/// and pass the request to the `HorizonClient`. The client will then execute the request and
/// return the corresponding response struct, like `LiquidityPool`.
///
/// ```rust
/// # use stellar_rs::horizon_client::HorizonClient;
/// # use stellar_rs::liquidity_pools::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 fee stats
/// let single_lp_request = SingleLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string())
/// .unwrap();
/// let lp_response = horizon_client.get_single_liquidity_pool(&single_lp_request).await?;
///
/// // Process the response...
/// # Ok(())
/// # }
/// ```
///
pub mod liquidity_pools;

/// Provides `Request` and `Response` structs for retrieving offers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Reserve {
/// to filter by when querying the Horizon server for liquidity pool records.
#[derive(PartialEq, Debug)]
pub enum ReserveType {
/// A native reserve type. It holds no Value
/// A native reserve type. It holds no value.
Native,
/// An alphanumeric 4 reserve type. It holds a Reserve struct with asset code and asset issuer.
Alphanumeric4(Reserve),
Expand Down Expand Up @@ -51,15 +51,12 @@ pub struct AllLiquidityPoolsRequest {
/// A pointer to a specific location in a collection of responses, derived from the
/// `paging_token` value of a record. Used for pagination control in the API response.
cursor: Option<u32>,

/// Specifies the maximum number of records to be returned in a single response.
/// The range for this parameter is from 1 to 200. The default value is set to 10.
limit: Option<u8>,

/// Determines the [`Order`] of the records in the response. Valid options are [`Order::Asc`] (ascending)
/// and [`Order::Desc`] (descending). If not specified, it defaults to ascending.
order: Option<Order>,

/// A list of reserves to filter by.
reserves: Option<Vec<ReserveType>>,
}
Expand Down
61 changes: 60 additions & 1 deletion stellar_rust_sdk/src/liquidity_pools/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,68 @@
/// Provides the `SingleLiquidityPoolRequest`.
///
/// This module provides the `SingleLiquidityPoolRequest` struct, specifically designed for
/// constructing requests to query information about a single liquidity pool from the Horizon
/// server. It is tailored for use with the [`HorizonClient::get_single_liquidity_pool`](crate::horizon_client::HorizonClient::get_single_liquidity_pool)
/// method.
///
pub mod single_liquidity_pool_request;

/// Provides the `AllLiquidityPoolsRequest`.
///
/// This module provides the `AllLiquidityPoolsRequest` struct, specifically designed for
/// constructing requests to query information about all liquidity pools from the Horizon
/// server. It is tailored for use with the [`HorizonClient::get_all_liquidity_pools`](crate::horizon_client::HorizonClient::get_all_liquidity_pools)
/// method.
pub mod all_liquidity_pools_request;

/// Provides the responses.
///
/// This module defines structures representing the response from the Horizon API when querying
/// for liquidity pools. The structures are designed to deserialize the JSON response into Rust
/// objects, enabling straightforward access to various details of a single Stellar account.
///
/// These structures are equipped with serialization capabilities to handle the JSON data from the
/// Horizon server and with getter methods for easy field access.
///
pub mod response;
pub mod single_liquidity_pool_request;

/// The base path for liquidity pool related endpoints in the Horizon API.
///
/// # Usage
/// This variable is intended to be used internally by the request-building logic
/// to ensure consistent and accurate path construction for liquidity pool related API calls.
///
static LIQUIDITY_POOLS_PATH: &str = "liquidity_pools";

/// The `prelude` module of the `liquidity_pools` module.
///
/// This module serves as a convenience for users of the Horizon Rust SDK, allowing for easy and
/// ergonomic import of the most commonly used items across various modules. It re-exports
/// key structs and traits from the sibling modules, simplifying access to these components
/// when using the library.
///
/// By importing the contents of `prelude`, users can conveniently access the primary
/// functionalities of the liquidity pool related modules without needing to import each item
/// individually.
///
/// # Contents
///
/// The `prelude` includes the following re-exports:
///
/// * From `single_liquidity_pool_request`: All items (e.g. `SingleLiquidityPoolRequest`).
/// * From `all_liquidity_pools_request`: All items (e.g. `AllLiquidityPoolsRequest`, `Reserve`, etc.).
/// * From `response`: All items (e.g. `AllLiquidityPoolsResponse`, `Reserve`, etc.).
///
/// # Example
/// ```
/// # use crate::stellar_rs::models::*;
/// // Import the contents of the liquidity pools prelude
/// use stellar_rs::liquidity_pools::prelude::*;
///
/// // Now you can directly use SingleLiquidityPoolRequest, LiquidityPool, etc.
/// let single_lp_request = SingleLiquidityPoolRequest::new();
/// ```
///
pub mod prelude {
pub use super::response::*;
pub use super::single_liquidity_pool_request::*;
Expand Down
1 change: 1 addition & 0 deletions stellar_rust_sdk/src/liquidity_pools/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct AllLiquidityPoolsResponse {
#[serde(rename = "_embedded")]
pub embedded: Embedded<LiquidityPool>,
}

/// Represents a single liquidity pool record in the Horizon API response.
///
/// This struct encapsulates detailed information about a single liquidity pool, including its ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::models::Request;

/// Represents the liquidity pool ID.
#[derive(Default, Clone)]
pub struct LiquidityPoolId(String);

/// Represents the absence of a liquidity pool ID.
#[derive(Default, Clone)]
pub struct NoLiquidityPoolId;

Expand All @@ -25,7 +29,7 @@ pub struct NoLiquidityPoolId;
/// # use stellar_rs::liquidity_pools::prelude::SingleLiquidityPoolRequest;
/// # use stellar_rs::models::Request;
/// let request = SingleLiquidityPoolRequest::new()
/// .set_liquidity_pool_id("1".to_string())
/// .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca".to_string())
/// .unwrap();
/// // Use with HorizonClient::get_single_liquidity_pool
/// ```
Expand Down

0 comments on commit 7112430

Please sign in to comment.