Crate stellar_rs

Source
Expand description

Stellar Horizon SDK for Rust

This Rust library provides a user-friendly interface to the Stellar Horizon API, allowing developers to easily query and transact on the Stellar network. Centered around the HorizonClient, the SDK abstracts the underlying HTTP request and response mechanisms into a set of simple, high-level methods.

The SDK is designed with a focus on developer experience, providing clear abstractions, sensible defaults, and streamlined error handling.

§Status

The SDK is under active development. It is functional but should be considered a work-in-progress. Features may be added or changed, and the SDK may evolve before stabilization.

§Supported endpoints:

100%

  • Accounts
  • Assets
  • Claimable balance
  • Effects
  • Fee stats
  • Ledgers
  • Liquidity pools
  • Operations
  • Offers
  • Orderbook
  • Paths
  • Payments
  • Trades
  • Trade aggregations
  • Transactions

§Example Usage

The following example demonstrates how to use the HorizonClient to retrieve a list of accounts with a specific signer:

use stellar_rs::horizon_client::HorizonClient;
use stellar_rs::accounts::prelude::{AccountsRequest, AccountsResponse};
use stellar_rs::models::{Request, Response};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the Horizon client with the testnet server
    let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org")?;

    // Create a request to fetch accounts with a specific signer
    let accounts_request = AccountsRequest::new()
        .set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")?
        .set_limit(10)?;

    // Perform the request using the Horizon client
    let accounts_response =
        horizon_client.get_account_list(&accounts_request)
        .await;

    // Check for success and handle the response or error
    match accounts_response {
        Ok(response) => {
            // Process the response
        },
        Err(e) => {
            // Handle the error
        }
    }

    Ok(())
}

This example initializes a HorizonClient, constructs an AccountsRequest to filter accounts by signer, and calls get_account_list to retrieve the relevant data. The result is then handled in a match expression, demonstrating the SDK’s straightforward error handling.

Visit the documentation for HorizonClient and endpoint-specific request and response types for more examples and detailed usage instructions.

Modules§

accounts
Provides Request and Response structs for retrieving accounts.
assets
Provides Request and Response structs for retrieving assets.
claimable_balances
Provides Request and Response structs for retrieving claimable balances.
effects
Provides Request and Response structs for retrieving effects.
fee_stats
Provides Request and Response structs for retrieving fee stats.
horizon_client
Client for calling the Stellar Horizon API
ledgers
Provides Request and Response structs for retrieving ledgers.
liquidity_pools
Provides Request and Response structs for retrieving liquidity pools.
models
Contains core data structures and traits.
offers
Provides Request and Response structs for retrieving offers.
operations
Provides Request and Response structs for retrieving operations.
order_book
Provides Request and Response structs for retrieving order book details.
paths
Provides Request and Response structs for retrieving payment paths.
payments
Provides Request and Response structs for retrieving payments.
trade_aggregations
Provides Request and Response structs for retrieving trade aggregation details.
trades
Provides Request and Response structs for retrieving trades.
transactions
Provides Request and Response structs for retrieving transactions.