Skip to content

Commit

Permalink
Better Documentation For client.rs and Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed May 1, 2024
1 parent fb448f6 commit e36c284
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(dead_code)]
use std::sync::Arc;

use crate::config::Config;
Expand All @@ -8,14 +7,33 @@ use crate::types::Cluster;

use reqwest::Client;

/// The `Helius` struct is the main entry point to interacting with the SDK
///
/// This client is responsible for setting up the network and configuration settins used to interact with the various provided methods.
/// It also provides methods to access RPC client functionalities. The client ensures thread-safe access to the underlying RPC client
pub struct Helius {
/// The configuration which specifies an `api_key`, `cluster`, and the requisite `endpoints`
pub config: Arc<Config>,
/// An HTTP client used for making API requests. The client is reused for all requests made through this instance of `Helius`
pub client: Client,
/// A reference-counted RPC client tailored for making requests in a thread-safe manner
pub rpc_client: Arc<RpcClient>,
}

impl Helius {
/// Initializes a new instance of Helius
/// Creates a new instance of `Helius` configured with a specific API key and a target cluster
///
/// # Arguments
/// * `api_key` - The API key required for authenticating requests made
/// * `cluster` - The Solana cluster (Devnet or MainnetBeta) that defines the given network environment
///
/// # Returns
/// An instance of `Helius` if successful. A `HeliusError` is returned if an error occurs during configuration or initialization of the HTTP or RPC client
///
/// # Example
/// ```rust
/// let helius = Helius::new("your_api_key", Cluster::Devnet).expect("Failed to create a Helius client")
/// ```
pub fn new(api_key: &str, cluster: Cluster) -> Result<Self> {
let config: Arc<Config> = Arc::new(Config::new(api_key, cluster)?);
let client: Client = Client::new();
Expand All @@ -29,6 +47,9 @@ impl Helius {
}

/// Provides a thread-safe way to access RPC functionalities
///
/// # Returns
/// A cloned `Arc<RpcClient>` that can be safely shared across threads
pub fn rpc(&self) -> Arc<RpcClient> {
self.rpc_client.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reqwest::Client;

/// A factory for creating instances of `Helius`
///
/// This factor allows for a centralized configuration and creation of `Helius` client so work can be done across multiple clusters at the same time.
/// This factor allows for a centralized configuration and creation of `Helius` client so work can be done across multiple clusters at the same time.
/// Using a factory simplifies client code and enhances maintainability by ensuring that all `Helius` clients are configured consistently.
pub struct HeliusFactory {
api_key: String,
Expand Down

0 comments on commit e36c284

Please sign in to comment.