Skip to content

Commit 7285637

Browse files
authored
Merge pull request #174 from helius-labs/feat/more-comprehensive-comments
feat(docs): Add Doc Comments For Everything
2 parents d798595 + 2ad458d commit 7285637

8 files changed

Lines changed: 1208 additions & 26 deletions

File tree

src/client.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use solana_commitment_config::CommitmentConfig;
1313

1414
/// The `Helius` struct is the main entry point to interacting with the SDK
1515
///
16-
/// This client is responsible for setting up the network and configuration settins used to interact with the various provided methods.
16+
/// This client is responsible for setting up the network and configuration settings used to interact with the various provided methods.
1717
/// It also provides methods to access RPC client functionalities. The client ensures thread-safe access to the underlying RPC client
1818
pub struct Helius {
1919
/// The configuration which specifies an `api_key`, `cluster`, and the requisite `endpoints`
@@ -203,10 +203,21 @@ impl Helius {
203203
self.rpc_client.solana_client.clone()
204204
}
205205

206+
/// Returns the enhanced (Geyser) WebSocket client, if one was initialized.
207+
///
208+
/// The WebSocket client is only available when the `Helius` instance was created with
209+
/// `new_async()` or via `HeliusBuilder::with_websocket()`.
210+
///
211+
/// # Returns
212+
/// `Some(Arc<EnhancedWebsocket>)` if a WebSocket client is available, `None` otherwise
206213
pub fn ws(&self) -> Option<Arc<EnhancedWebsocket>> {
207214
self.ws_client.clone()
208215
}
209216

217+
/// Returns the client configuration.
218+
///
219+
/// # Returns
220+
/// A cloned `Arc<Config>` containing the API key, cluster, and endpoint settings
210221
pub fn config(&self) -> Arc<Config> {
211222
self.config.clone()
212223
}

src/error.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub enum HeliusError {
1414
/// Indicates an improperly formatted request
1515
///
1616
/// This error occurs when the request parameters do not meet the expected format, are missing required fields,
17-
/// or contains invalid data
17+
/// or contain invalid data
1818
#[error("Bad request to {path}: {text}")]
1919
BadRequest { path: String, text: String },
2020

@@ -24,7 +24,7 @@ pub enum HeliusError {
2424
#[error("Solana client error: {0}")]
2525
ClientError(#[from] ClientError),
2626

27-
/// Indicates if a client is not already initialized
27+
/// Indicates that a client has not been initialized
2828
///
2929
/// Returned when accessing `async_connection()` without enabling async via `HeliusBuilder` or `new_async()`
3030
#[error("Client not initialized: {text}")]
@@ -112,18 +112,33 @@ pub enum HeliusError {
112112
#[error("Unknown error has occurred: HTTP {code} - {text}")]
113113
Unknown { code: StatusCode, text: String },
114114

115+
/// Indicates a failure in the underlying WebSocket (tungstenite) connection
116+
///
117+
/// This captures connection errors, protocol violations, and other WebSocket-level failures
115118
#[error("Unable to connect to server: {0}")]
116119
Tungstenite(#[from] tokio_tungstenite::tungstenite::Error),
117120

118-
#[error("Websocket connection closed (({0})")]
121+
/// Indicates the WebSocket connection was closed unexpectedly
122+
///
123+
/// Includes a message describing the close reason or frame
124+
#[error("Websocket connection closed ({0})")]
119125
WebsocketClosed(String),
120126

127+
/// Represents errors specific to the Helius enhanced (Geyser) WebSocket
128+
///
129+
/// Returned for subscription failures, unsupported cluster configurations, or server-side errors
121130
#[error("Enhanced websocket: {message}: {reason}")]
122131
EnhancedWebsocket { reason: String, message: String },
123132

133+
/// Indicates a failure to parse a URL
134+
///
135+
/// Returned when a provided RPC or WebSocket URL is malformed
124136
#[error("Url parse error")]
125137
UrlParseError(#[from] url::ParseError),
126138

139+
/// Indicates a TLS/SSL handshake or configuration error
140+
///
141+
/// Returned when the HTTP client fails to establish a secure connection
127142
#[error("TLS error: {0}")]
128143
TlsError(String),
129144
}
@@ -154,12 +169,17 @@ impl From<SerdeJsonError> for HeliusError {
154169
}
155170

156171
impl From<SanitizeError> for HeliusError {
172+
/// Converts a Solana `SanitizeError` into [`HeliusError::InvalidInput`]
157173
fn from(err: SanitizeError) -> Self {
158174
HeliusError::InvalidInput(err.to_string())
159175
}
160176
}
161177

162178
impl From<ReqwestError> for HeliusError {
179+
/// Converts a `reqwest::Error` into the appropriate `HeliusError` variant
180+
///
181+
/// Builder errors (typically TLS configuration issues) are mapped to [`HeliusError::TlsError`],
182+
/// while all other request errors are mapped to [`HeliusError::ReqwestError`]
163183
fn from(err: reqwest::Error) -> Self {
164184
if err.is_builder() {
165185
HeliusError::TlsError(err.to_string())

src/rpc_client.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/// # RPC Client for Helius
22
///
3-
/// This module provides access to the Helius API using an RPC client with an embedded Solana client
3+
/// This module provides access to the Helius API using an RPC client with an embedded Solana client.
44
///
55
/// ## Errors
66
///
7-
/// Most methods in this client will return a `Result<T, HeliusError>`, where `HeliusError` can be:
7+
/// Most methods in this client will return a `Result<T, HeliusError>`, where common variants include:
88
/// - `BadRequest`: Incorrect request format or parameters. Check the path and the text for details
99
/// - `Unauthorized`: Incorrect or missing API key. Ensure you've provided the correct API key
1010
/// - `NotFound`: The requested resource was not found. This could mean an invalid ID or a non-existent endpoint
1111
/// - `RateLimitExceeded`: Too many requests have been sent in a short period. Consider implementing retries with an exponential backoff
1212
/// - `InternalError`: Server-side errors. These are rare and typically indicate issues on the server side. If these issues persist, please contact Helius support
13-
/// - `Network`: Errors during HTTP communication, typically from underlying network issues
13+
/// - `ReqwestError`: Errors during HTTP communication, typically from underlying network issues
1414
/// - `SerdeJson`: Errors during the serialization or deserialization process
1515
/// - `Unknown`: Catch-all for unclassified errors, with a status code and message provided for further investigation
1616
///
17-
/// Ensure to handle these errors gracefully in your application to maintain robustness and stellar UX
17+
/// See [`HeliusError`](crate::error::HeliusError) for the full list of error variants.
1818
use std::collections::HashMap;
1919
use std::fmt::Debug;
2020
use std::sync::Arc;
@@ -39,9 +39,21 @@ use serde::Serialize;
3939
use solana_client::rpc_client::RpcClient as SolanaRpcClient;
4040
use solana_commitment_config::CommitmentConfig;
4141

42+
/// Helius RPC client with an embedded Solana RPC client.
43+
///
44+
/// Provides methods for interacting with the Helius DAS API, priority fee estimation,
45+
/// and enhanced RPC V2 endpoints (`getProgramAccountsV2`, `getTokenAccountsByOwnerV2`,
46+
/// `getTransactionsForAddress`). The embedded Solana client handles standard Solana
47+
/// RPC calls.
48+
///
49+
/// Constructed internally by [`Helius`](crate::Helius) — use [`HeliusBuilder`](crate::HeliusBuilder)
50+
/// or [`Helius::new`](crate::Helius::new) to create a client.
4251
pub struct RpcClient {
52+
/// HTTP request handler for Helius API calls
4353
pub handler: RequestHandler,
54+
/// Shared SDK configuration (API key, endpoints)
4455
pub config: Arc<Config>,
56+
/// Embedded Solana RPC client for standard RPC methods
4557
pub solana_client: Arc<SolanaRpcClient>,
4658
}
4759

@@ -289,7 +301,7 @@ impl RpcClient {
289301
///
290302
/// # Pagination
291303
/// * If `pagination_key` is `Some`, pass it into the **next** request to continue
292-
/// * If `pagination_key` is `None`, ypu've reached the end
304+
/// * If `pagination_key` is `None`, you've reached the end
293305
/// * Note that if there are fewer than `limit` accounts in a given page it does not imply the end; always check the cursor
294306
///
295307
/// # Incremental Updates
@@ -321,7 +333,7 @@ impl RpcClient {
321333
///
322334
/// # Pagination
323335
/// * If `pagination_key` is `Some`, pass it into the **next** request to continue
324-
/// * If `pagination_key` is `None`, ypu've reached the end
336+
/// * If `pagination_key` is `None`, you've reached the end
325337
/// * Note that if there are fewer than `limit` accounts in a given page it does not imply the end; always check the cursor
326338
///
327339
/// # Incremental Updates

0 commit comments

Comments
 (0)