stellar_rs/
lib.rs

1//! Stellar Horizon SDK for Rust
2//!
3//! This Rust library provides a user-friendly interface to the Stellar Horizon API,
4//! allowing developers to easily query and transact on the Stellar network. Centered
5//! around the `HorizonClient`, the SDK abstracts the underlying HTTP request and response
6//! mechanisms into a set of simple, high-level methods.
7//!
8//! The SDK is designed with a focus on developer experience, providing clear abstractions,
9//! sensible defaults, and streamlined error handling.
10//!
11//! ## Status
12//!
13//! The SDK is under active development. It is functional but should be considered a
14//! work-in-progress. Features may be added or changed, and the SDK may evolve before
15//! stabilization.
16//!
17//! #### Supported endpoints:
18//! ![100%](https://progress-bar.dev/100/?width=200)
19//! * Accounts
20//! * Assets
21//! * Claimable balance
22//! * Effects
23//! * Fee stats
24//! * Ledgers
25//! * Liquidity pools
26//! * Operations
27//! * Offers
28//! * Orderbook
29//! * Paths
30//! * Payments
31//! * Trades
32//! * Trade aggregations
33//! * Transactions
34
35//!
36//! ## Example Usage
37//!
38//! The following example demonstrates how to use the `HorizonClient` to retrieve a list
39//! of accounts with a specific signer:
40//!
41//! ```rust
42//! use stellar_rs::horizon_client::HorizonClient;
43//! use stellar_rs::accounts::prelude::{AccountsRequest, AccountsResponse};
44//! use stellar_rs::models::{Request, Response};
45//!
46//! #[tokio::main]
47//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
48//!     // Initialize the Horizon client with the testnet server
49//!     let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
50//!
51//!     // Create a request to fetch accounts with a specific signer
52//!     let accounts_request = AccountsRequest::new()
53//!         .set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")?
54//!         .set_limit(10)?;
55//!
56//!     // Perform the request using the Horizon client
57//!     let accounts_response =
58//!         horizon_client.get_account_list(&accounts_request)
59//!         .await;
60//!
61//!     // Check for success and handle the response or error
62//!     match accounts_response {
63//!         Ok(response) => {
64//!             // Process the response
65//!         },
66//!         Err(e) => {
67//!             // Handle the error
68//!         }
69//!     }
70//!
71//!     Ok(())
72//! }
73//! ```
74//!
75//! This example initializes a `HorizonClient`, constructs an `AccountsRequest` to filter
76//! accounts by signer, and calls `get_account_list` to retrieve the relevant data.
77//! The result is then handled in a match expression, demonstrating the SDK's straightforward
78//! error handling.
79//!
80//! Visit the documentation for `HorizonClient` and endpoint-specific request and response
81//! types for more examples and detailed usage instructions.
82
83use derive_getters::Getters;
84/// Provides `Request` and `Response` structs for retrieving accounts.
85///
86/// This module provides a set of specialized request and response structures designed for
87/// interacting with the accounts-related endpoints of the Horizon server. These structures
88/// facilitate the construction of requests to query account data and the interpretation of
89/// the corresponding responses.
90///
91/// # Usage
92///
93/// This module is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
94/// for making specific account-related API calls to the Horizon server. The request
95/// structures are designed to be passed to the client's methods, which handle the
96/// communication with the server and return the corresponding response structures.
97///
98/// # Example
99/// An example of retrieving a list of accounts, filtering by signer:
100/// ```rust
101/// # use stellar_rs::accounts::prelude::{AccountsRequest, AccountsResponse};
102/// # use stellar_rs::models::Request;
103/// # use stellar_rs::horizon_client::HorizonClient;
104/// #
105/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
106/// # let base_url = "https://horizon-testnet.stellar.org";
107/// # let horizon_client = HorizonClient::new(base_url)
108/// #    .expect("Failed to create Horizon Client");
109/// let request = AccountsRequest::new()
110///     .set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap()
111///     .set_limit(10).unwrap();
112///
113/// let response = horizon_client
114///     .get_account_list(&request)
115///     .await?;
116/// # Ok({})
117/// # }
118///
119pub mod accounts;
120
121/// Provides `Request` and `Response` structs for retrieving assets.
122///
123/// This module provides the structures and functionalities necessary to interact with asset-related
124/// endpoints of the Stellar Horizon API. It defines the request and response handlers for querying
125/// information about assets on the Stellar network as described in the Stellar Horizon API documentation
126/// on [Assets](https://developers.stellar.org/api/horizon/resources/assets). It is intended to be used in
127/// conjunction with the is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
128/// struct.
129///
130/// # Example
131///
132/// The `assets` module simplifies the process of constructing queries about assets and interpreting the results. For example:
133///
134/// ```rust
135/// # use stellar_rs::assets::prelude::*;
136/// # use stellar_rs::models::Request;
137/// # use stellar_rs::horizon_client::HorizonClient;
138/// #
139/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
140/// # let base_url = "https://horizon-testnet.stellar.org";
141/// # let horizon_client = HorizonClient::new(base_url)
142/// #    .expect("Failed to create Horizon Client");
143/// let request = AllAssetsRequest::new()
144///     .set_asset_code("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap();
145///
146/// let response = horizon_client
147///     .get_all_assets(&request)
148///     .await?;
149/// # Ok({})
150/// # }
151/// ```
152///
153pub mod assets;
154
155/// Provides `Request` and `Response` structs for retrieving claimable balances.
156///
157/// This module provides structures and functionalities related to claimable balances within the Stellar network.
158/// Claimable balances are a feature of the Stellar network that allows for the creation of balances that are
159/// claimable by a designated party. They are used to facilitate payments to accounts that may not yet exist
160/// or to provide an assurance that funds can be claimed by the rightful recipient.
161///
162/// The module comprises request and response structs for both single and batched operations involving
163/// claimable balances. These are designed to interface with the Horizon API's endpoints for creating,
164/// retrieving, and claiming such balances.
165///
166/// # Usage
167///
168/// To utilize the functionalities for claimable balances, import the necessary structs from this module
169/// and use them to interact with the Horizon API. The `HorizonClient` methods, such as `get_claimable_balances`
170/// and `get_claimable_balance`, will typically return the response structs provided here.
171///
172/// # Example
173/// ```rust
174/// # use stellar_rs::claimable_balances::prelude::*;
175/// # use stellar_rs::models::Request;
176/// # use stellar_rs::horizon_client::HorizonClient;
177/// #
178/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
179/// # let base_url = "https://horizon-testnet.stellar.org";
180/// # let horizon_client = HorizonClient::new(base_url)
181/// #    .expect("Failed to create Horizon Client");
182/// let request = AllClaimableBalancesRequest::new();
183///
184/// let response = horizon_client
185///     .get_all_claimable_balances(&request)
186///     .await?;
187///
188/// // Process the response
189/// # Ok({})
190/// # }
191/// ```
192///
193pub mod claimable_balances;
194
195/// Client for calling the Stellar Horizon API
196///
197/// # Constructing a `HorizonClient`
198/// A string containing the base URL for the Horizon API is required to contruct a client.
199/// For example, to construct a client for the Horizon API testnet:
200/// ```rust
201/// use stellar_rs::horizon_client::HorizonClient;
202///
203/// let base_url = "https://horizon-testnet.stellar.org";
204/// let horizon_client = HorizonClient::new(base_url)
205///     .expect("Failed to create Horizon Client");
206/// ```
207///
208/// # Using the `HorizonClient`
209/// The HorizonClient has a function that can be called for each endpoind provided
210/// by the Horizon API. For example, it has a [`HorizonClient::get_account_list`](crate::horizon_client::HorizonClient::get_account_list)
211/// function, which returns an async future that contains a result, as illustrated below:
212/// ```rust
213/// # use stellar_rs::assets::prelude::{AllAssetsRequest, AllAssetsResponse};
214/// # use stellar_rs::models::Request;
215/// # use stellar_rs::horizon_client::HorizonClient;
216/// #
217/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
218/// # let base_url = "https://horizon-testnet.stellar.org";
219/// # let horizon_client = HorizonClient::new(base_url)
220/// #    .expect("Failed to create Horizon Client");
221/// let all_assets_request = AllAssetsRequest::new();
222/// let accounts_response = horizon_client
223///     .get_all_assets(&all_assets_request)
224///     .await?;
225/// # Ok({})
226/// # }
227/// ```
228pub mod horizon_client;
229
230/// Provides `Request` and `Response` structs for retrieving ledgers.
231///
232/// The `ledgers` module in the Stellar Horizon SDK includes structures and methods that facilitate
233/// querying ledger data from the Horizon server.
234///
235/// # Usage
236///
237/// This module is used to construct requests for ledger-related data and to parse the responses
238/// received from the Horizon server. It includes request and response structures for both
239/// individual ledger queries and queries for a collection of ledgers.
240///
241/// # Example
242///
243/// To use this module, you can create an instance of a request struct, such as `SingleLedgerRequest`
244/// or `AllLedgersRequest`, set any desired query parameters, and pass the request to the
245/// `HorizonClient`. The client will then execute the request and return the corresponding
246/// response struct, like `SingleLedgerResponse` or `AllLedgersResponse`.
247///
248/// ```rust
249/// # use stellar_rs::horizon_client::HorizonClient;
250/// # use stellar_rs::ledgers::prelude::*;
251/// # use stellar_rs::models::Request;
252///
253/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
254/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
255///
256/// // Example: Fetching a single ledger by sequence number
257/// let single_ledger_request = SingleLedgerRequest::new().set_sequence(123456)?;
258/// let ledger_response = horizon_client.get_single_ledger(&single_ledger_request).await?;
259///
260/// // Example: Fetching all ledgers
261/// let all_ledgers_request = LedgersRequest::new().set_limit(10)?;
262/// let ledgers_response = horizon_client.get_all_ledgers(&all_ledgers_request).await?;
263///
264/// // Process the responses...
265/// # Ok(())
266/// # }
267/// ```
268///
269pub mod ledgers;
270
271/// Provides `Request` and `Response` structs for retrieving effects.
272///
273/// The `effects` module in the Stellar Horizon SDK includes structures and methods that facilitate
274/// querying effect data from the Horizon server.
275///
276/// # Usage
277///
278/// This module is used to construct requests for effect-related data and to parse the responses
279/// received from the Horizon server. It includes request and response structures for both
280/// individual effect queries and queries for a collection of effects.
281///
282/// # Example
283///
284/// To use this module, you can create an instance of a request struct, such as `SingleEffectRequest`
285/// or `AllEffectsRequest`, set any desired query parameters, and pass the request to the
286/// `HorizonClient`. The client will then execute the request and return the corresponding
287/// response struct, like `SingleEffectResponse` or `AllEffectsResponse`.
288///
289/// ```rust
290/// # use stellar_rs::horizon_client::HorizonClient;
291/// # use stellar_rs::effects::prelude::*;
292/// # use stellar_rs::models::Request;
293///
294/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
295/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
296///
297/// // Example: Fetching all effects
298/// let all_effects_request = AllEffectsRequest::new().set_limit(10)?;
299/// let effects_response = horizon_client.get_all_effects(&all_effects_request).await?;
300///
301/// // Process the responses...
302/// # Ok(())
303/// # }
304/// ```
305///
306pub mod effects;
307
308/// Provides `Request` and `Response` structs for retrieving fee stats.
309///
310/// The `fee_stats` module in the Stellar Horizon SDK includes structures and methods that facilitate
311/// querying fee stats data from the Horizon server.
312///
313/// # Usage
314///
315/// This module is used to construct requests for fee stats-related data and to parse the responses
316/// received from the Horizon server. It includes request and response structures for querying
317/// fee stats data.
318///
319/// # Example
320///
321/// To use this module, you can create an instance of a request struct, such as `FeeStatsRequest`,
322/// and pass the request to the `HorizonClient`. The client will then execute the request and
323/// return the corresponding response struct, like `FeeStatsResponse`.
324///
325/// ```rust
326/// use stellar_rs::horizon_client::HorizonClient;
327/// use stellar_rs::fee_stats::prelude::*;
328/// use stellar_rs::models::Request;
329///
330/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
331/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
332///
333/// // Example: Fetching fee stats
334/// let fee_stats_request = FeeStatsRequest::new();
335/// let fee_stats_response = horizon_client.get_fee_stats(&fee_stats_request).await?;
336///
337/// // Process the response...
338/// # Ok(())
339/// # }
340/// ```
341///
342pub mod fee_stats;
343
344/// Provides `Request` and `Response` structs for retrieving liquidity pools.
345///
346/// The `liquidity_pools` module in the Stellar Horizon SDK includes structures and methods that facilitate
347/// querying liquidity pool data from the Horizon server.
348///
349/// # Usage
350///
351/// This module is used to construct requests for liquidity pool related data and to parse the responses
352/// received from the Horizon server. It includes request and response structures for querying
353/// liquidity pool data.
354///
355/// # Example
356///
357/// To use this module, you can create an instance of a request struct, such as `SingleLiquidityPoolRequest`,
358/// and pass the request to the `HorizonClient`. The client will then execute the request and
359/// return the corresponding response struct, like `LiquidityPool`.
360///
361/// ```rust
362/// # use stellar_rs::horizon_client::HorizonClient;
363/// # use stellar_rs::liquidity_pools::prelude::*;
364/// # use stellar_rs::models::Request;
365///
366/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
367/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
368///
369/// // Example: Fetching fee stats
370/// let single_lp_request = SingleLiquidityPoolRequest::new()
371///     .set_liquidity_pool_id("000000006520216af66d20d63a58534d6cbdf28ba9f2a9c1e03f8d9a756bb7d988b29bca")
372///     .unwrap();
373/// let lp_response = horizon_client.get_single_liquidity_pool(&single_lp_request).await?;
374///
375/// // Process the response...
376/// # Ok(())
377/// # }
378/// ```
379///
380pub mod liquidity_pools;
381
382/// Provides `Request` and `Response` structs for retrieving offers.
383///
384/// This module provides a set of specialized request and response structures designed for
385/// interacting with the offer-related endpoints of the Horizon server. These structures
386/// facilitate the construction of requests to query offer data and the interpretation of
387/// the corresponding responses.
388///
389/// # Usage
390///
391/// This module is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
392/// for making specific offer-related API calls to the Horizon server. The request
393/// structures are designed to be passed to the client's methods, which handle the
394/// communication with the server and return the corresponding response structures.
395///
396/// # Example
397///
398/// /// To use this module, you can create an instance of a request struct, such as
399/// `SingleOfferRequest`, set any desired query parameters, and pass the request to the
400/// `HorizonClient`. The client will then execute the request and return the corresponding
401/// response struct, like `SingleOfferResponse`.
402///
403/// ```rust
404/// use stellar_rs::horizon_client::HorizonClient;
405/// use stellar_rs::offers::prelude::*;
406/// use stellar_rs::models::Request;
407///
408/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
409/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
410///
411/// // Example: Fetching all effects
412/// let single_offer_request = SingleOfferRequest::new()
413///     .set_offer_id("1")
414///     .unwrap();
415/// let single_offer_response = horizon_client.get_single_offer(&single_offer_request).await?;
416///
417/// // Process the responses...
418/// # Ok(())
419/// # }
420/// ```
421///
422pub mod offers;
423
424/// Provides `Request` and `Response` structs for retrieving operations.
425///
426/// The `operations` module in the Stellar Horizon SDK includes structures and methods that facilitate
427/// querying operation data from the Horizon server.
428///
429/// # Usage
430///
431/// This module is used to construct requests for operation-related data and to parse the responses
432/// received from the Horizon server. It includes request and response structures for both
433/// individual operation queries and queries for a collection of operations.
434///
435/// # Example
436///
437/// To use this module, you can create an instance of a request struct, such as `SingleOperationRequest`
438/// or `AllOperationsRequest`, set any desired query parameters, and pass the request to the
439/// `HorizonClient`. The client will then execute the request and return the corresponding
440/// response struct, like `SingleOperationResponse` or `AllOperationsResponse`.
441///
442/// ```rust
443/// # use stellar_rs::horizon_client::HorizonClient;
444/// # use stellar_rs::operations::prelude::*;
445/// # use stellar_rs::models::Request;
446///
447/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
448/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
449///
450/// // Example: Fetching all operations
451/// let all_operations_request = AllOperationsRequest::new().set_limit(10)?;
452/// let operations_response = horizon_client.get_all_operations(&all_operations_request).await?;
453///
454/// // Process the responses...
455/// # Ok(())
456/// # }
457/// ```
458///
459pub mod operations;
460
461/// Provides `Request` and `Response` structs for retrieving order book details.
462///
463/// The `order_book` module in the Stellar Horizon SDK includes structures and methods that facilitate
464/// querying order book data from the Horizon server.
465///
466/// # Usage
467///
468/// This module is used to construct requests for order book-related data and to parse the responses
469/// received from the Horizon server. It includes request and response structures for querying
470/// order book details.
471///
472/// # Example
473///
474/// To use this module, you can create an instance of a request struct, such as `DetailsRequest`,
475/// set any desired query parameters, and pass the request to the `HorizonClient`. The client will
476/// then execute the request and return the corresponding response struct, like `DetailsResponse`.
477///
478/// ```rust
479/// use stellar_rs::horizon_client::HorizonClient;
480/// use stellar_rs::order_book::prelude::*;
481/// use stellar_rs::models::prelude::*;
482///
483/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
484/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
485///
486/// // Example: Fetching order book details
487/// let details_request = DetailsRequest::new()
488///    .set_buying_asset(AssetType::Native)?
489///   .set_selling_asset(AssetType::Alphanumeric4(AssetData {
490///      asset_code: "USDC".to_string(),
491///     asset_issuer: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5".to_string(),
492/// }))?;
493/// let details_response = horizon_client.get_order_book_details(&details_request).await?;
494///
495/// // Process the response...
496/// # Ok(())
497/// # }
498/// ```
499///
500pub mod order_book;
501
502/// Provides `Request` and `Response` structs for retrieving trade aggregation details.
503///
504/// The `trade_aggregations` module in the Stellar Horizon SDK includes structures and methods that facilitate
505/// querying trade aggregations data from the Horizon server.
506///
507/// # Usage
508///
509/// This module is used to construct requests for trade aggregations related data and to parse the responses
510/// received from the Horizon server. It includes request and response structures for querying
511/// trade aggregations.
512///
513/// # Example
514///
515/// To use this module, you can create an instance of a request struct, such as `TradeAggregationsRequest`,
516/// set any desired query parameters, and pass the request to the `HorizonClient`. The client will
517/// then execute the request and return the corresponding response struct, like `AllTradeAggregationsResponse`.
518///
519/// ```rust
520/// use stellar_rs::horizon_client::HorizonClient;
521/// use stellar_rs::trade_aggregations::prelude::*;
522/// use stellar_rs::models::prelude::*;
523///
524/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
525/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
526///
527/// // Example: Fetching trade aggregations
528/// let request = TradeAggregationsRequest::new()
529///     .set_base_asset(AssetType::Native).unwrap()
530///     .set_counter_asset(AssetType::Alphanumeric4(AssetData {
531///         asset_code: "USDC".to_string(),
532///         asset_issuer: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5".to_string(),
533///     })).unwrap()
534///     .set_resolution(Resolution(ResolutionData::Duration604800000)).unwrap();
535/// let response = horizon_client.get_trade_aggregations(&request).await?;
536///
537/// // Process the response...
538/// # Ok(())
539/// # }
540/// ```
541pub mod trade_aggregations;
542
543/// Provides `Request` and `Response` structs for retrieving transactions.
544///
545/// This module provides a set of specialized request and response structures designed for
546/// interacting with the transaction-related endpoints of the Horizon server. These structures
547/// facilitate the construction of requests to query transaction data and the interpretation of
548/// the corresponding responses.
549///
550/// # Usage
551///
552/// This module is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
553/// for making specific transaction-related API calls to the Horizon server. The request
554/// structures are designed to be passed to the client's methods, which handle the
555/// communication with the server and return the corresponding response structures.
556///
557/// # Example
558///
559/// /// To use this module, you can create an instance of a request struct, such as
560/// `SingleTransactionRequest`, set any desired query parameters, and pass the request to the
561/// `HorizonClient`. The client will then execute the request and return the corresponding
562/// response struct, like `TransactionResponse`.
563///
564/// ```rust
565/// use stellar_rs::horizon_client::HorizonClient;
566/// use stellar_rs::transactions::prelude::*;
567/// use stellar_rs::models::Request;
568///
569/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
570/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
571///
572/// // Example: Fetching a transaction
573/// let single_transaction_request = SingleTransactionRequest::new()
574///     .set_transaction_hash("be0d59c8706e8fd525d2ab10910a55ec57323663858c65b330a3f93afb13ab0f")
575///     .unwrap();
576/// let single_transaction_response = horizon_client.get_single_transaction(&single_transaction_request).await?;
577///
578/// // Process the responses...
579/// # Ok(())
580/// # }
581/// ```
582///
583pub mod transactions;
584
585/// Provides `Request` and `Response` structs for retrieving trades.
586///
587/// This module provides a set of specialized request and response structures designed for
588/// interacting with the trade-related endpoints of the Horizon server. These structures
589/// facilitate the construction of requests to query trade data and the interpretation of
590/// the corresponding responses.
591///
592/// # Usage
593///
594/// This module is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
595/// for making specific trade-related API calls to the Horizon server. The request
596/// structures are designed to be passed to the client's methods, which handle the
597/// communication with the server and return the corresponding response structures.
598///
599/// # Example
600///
601/// /// To use this module, you can create an instance of a request struct, such as
602/// `AllTradesRequest`, set any desired query parameters, and pass the request to the
603/// `HorizonClient`. The client will then execute the request and return the corresponding
604/// response struct, like `AllTradesResponse`.
605///
606/// ```rust
607/// use stellar_rs::horizon_client::HorizonClient;
608/// use stellar_rs::trades::prelude::*;
609/// use stellar_rs::models::Request;
610///
611/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
612/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
613///
614/// // Example: Fetching all trades
615/// let all_trades_request = AllTradesRequest::new();
616///
617/// let all_trades_response = horizon_client.get_all_trades(&all_trades_request).await?;
618///
619/// // Process the responses...
620/// # Ok(())
621/// # }
622/// ```
623///
624pub mod trades;
625
626/// Provides `Request` and `Response` structs for retrieving payment paths.
627///
628/// This module provides a set of specialized request and response structures designed for
629/// interacting with the payment path-related endpoints of the Horizon server. These structures
630/// facilitate the construction of requests to query payment paths and the interpretation of
631/// the corresponding responses.
632///
633/// # Usage
634///
635/// This module is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
636/// for making specific payment path-related API calls to the Horizon server. The request
637/// structures are designed to be passed to the client's methods, which handle the
638/// communication with the server and return the corresponding response structures.
639///
640/// # Example
641///
642/// To use this module, you can create an instance of a request struct, such as
643/// `FindPaymentPathsRequest`, `ListStrictReceivePaymentPathsRequest`, or `ListStrictSendPaymentPathsRequest`,
644/// set any desired query parameters, and pass the request to the `HorizonClient`. The client
645/// will then execute the request and return the corresponding response struct, like `PathsResponse`.
646///
647/// ```rust
648/// use stellar_rs::horizon_client::HorizonClient;
649/// use stellar_rs::paths::prelude::*;
650/// use stellar_rs::models::prelude::*;
651///
652/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
653/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
654///
655/// // Example: Fetching payment paths
656/// let request = FindPaymentsPathRequest::new()
657///     .set_destination_asset(AssetType::Native).unwrap() // Sets the destination asset to native XLM.
658///     .set_destination_amount("100.0".to_string()).unwrap() // Sets the amount of the destination asset.
659///     .set_source_account("GCDNJUBQSXK57MSKJ4NSXK5DT5CJMMXMWUE7BN6NTJ6JTH23HQVYXG2C".to_string()).unwrap() // Sets the source account.
660///     .set_destination_account("GAZD7JY7RCZN7KJ27SMUGKDPF7GQTYPXLDU7TFTJNSDB3MLO3M22DEIV".to_string()).unwrap(); // Sets the destination account.
661///
662/// let paths_response = horizon_client.get_find_payment_paths(&request).await?;
663///
664/// // Process the responses...
665/// # Ok(())
666/// # }
667/// ```
668pub mod paths;
669
670/// Provides `Request` and `Response` structs for retrieving payments.
671///
672/// This module provides a set of specialized request and response structures designed for
673/// interacting with the payment-related endpoints of the Horizon server. These structures
674/// facilitate the construction of requests to query trade data and the interpretation of
675/// the corresponding responses.
676///
677/// # Usage
678///
679/// This module is intended to be used in conjunction with the [`HorizonClient`](crate::horizon_client::HorizonClient)
680/// for making specific payment-related API calls to the Horizon server. The request
681/// structures are designed to be passed to the client's methods, which handle the
682/// communication with the server and return the corresponding response structures.
683///
684/// /// # Example
685///
686/// To use this module, you can create an instance of a request struct, such as
687/// `AllPaymentsRequest`, set any desired query parameters, and pass the request to the
688/// `HorizonClient`. The client will then execute the request and return the corresponding
689/// response struct, like `AllPaymentsResponse`.
690///
691/// ```rust
692/// use stellar_rs::horizon_client::HorizonClient;
693/// use stellar_rs::payments::prelude::*;
694/// use stellar_rs::models::Request;
695///
696/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
697/// let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;
698///
699/// // Example: Fetching all payments
700/// let all_payments_request = AllPaymentsRequest::new();
701///
702/// let all_payments_response = horizon_client.get_all_payments(&all_payments_request).await?;
703///
704/// // Process the responses...
705/// # Ok(())
706/// # }
707/// ```
708///
709pub mod payments;
710
711/// Contains core data structures and traits.
712///
713/// This module is used by the Stellar Rust SDK to interact with the Horizon API.
714/// It defines enums, traits, and functions that encapsulate the logic for
715/// creating and processing HTTP requests and responses, as well as handling the
716/// data involved in these operations.
717///
718/// The `models` module plays a critical role in abstracting the complexities
719/// of the Horizon API, allowing developers to work with high-level Rust constructs
720/// instead of raw HTTP requests and JSON responses.
721pub mod models;
722
723/// Extension trait for building query parameter strings from a vector of optional values.
724///
725/// This trait provides a method to construct a query string from a vector of optional
726/// values (`Option<T>`). It is designed to be used for generating query parameters in
727/// URL construction, where each parameter is only included if it has a value (`Some`).
728///
729/// # Usage
730/// This trait is typically used internally in constructing URLs with query parameters
731/// by implementors of the [`Request::get_query_parameters`](crate::models::Request::get_query_parameters)
732/// method. It enables a convenient and efficient way to handle optional parameters in
733/// a URL query string.
734///
735trait BuildQueryParametersExt<T> {
736    /// Constructs a query string for an HTTP request from the object's properties.
737    ///
738    /// This method transforms the properties of the implementing object into a URL-encoded query
739    /// string.
740    ///
741    fn build_query_parameters(self) -> String;
742}
743
744impl<T: ToString> BuildQueryParametersExt<Option<T>> for Vec<Option<T>> {
745    /// # Implementation for `Vec<Option<T>>`
746    /// Converts each property to a key-value pair, and concatenates pairs with '&'.
747    /// Properties that are `None` are omitted from the string.
748    ///
749    /// ## Returns
750    /// A `String` representing the query parameters of the HTTP request. If there
751    /// are no parameters, or all properties are `None`, an empty string is returned.
752    ///
753    fn build_query_parameters(self) -> String {
754        let params = self
755            .into_iter()
756            // Iterate over each element in the vector.
757            .filter_map(|x|
758                // Use filter_map to process each Option<T>.
759                // If the element is Some, it's transformed to its string representation.
760                // If the element is None, it's filtered out.
761                x.map(|val| val.to_string()))
762            // Collect the transformed values into a Vec<String>.
763            .collect::<Vec<String>>()
764            // Join the Vec<String> elements with '&' to create the query string.
765            .join("&");
766
767        // Check if the resulting params string is empty.
768        match params.is_empty() {
769            // If params is empty, return an empty string.
770            true => "".to_string(),
771            // If params is not empty, prepend a '?' to the params string.
772            false => format!("?{}", params),
773        }
774    }
775}