Skip to content

Commit

Permalink
Formattooorrr
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed Nov 28, 2024
1 parent 2f60d31 commit e35af6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
9 changes: 6 additions & 3 deletions examples/async_config_based_creation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use helius::config::Config;
use helius::error::Result;
use helius::types::Cluster;
use helius::config::Config;
use helius::Helius;

/// Demonstrates creating a Helius client with async Solana capabilities using the config-based approach
Expand All @@ -11,9 +11,12 @@ async fn main() -> Result<()> {

let config: Config = Config::new(api_key, cluster)?;
let async_client: Helius = config.create_client_with_async()?;

if let Ok(async_conn) = async_client.async_connection() {
println!("Async client - Get Block Height: {:?}", async_conn.get_block_height().await);
println!(
"Async client - Get Block Height: {:?}",
async_conn.get_block_height().await
);
}

Ok(())
Expand Down
30 changes: 13 additions & 17 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::error::{HeliusError, Result};
use crate::rpc_client::RpcClient;
use crate::types::{Cluster, HeliusEndpoints, MintApiAuthority};
use crate::websocket::{ EnhancedWebsocket, ENHANCED_WEBSOCKET_URL };
use crate::websocket::{EnhancedWebsocket, ENHANCED_WEBSOCKET_URL};
use crate::Helius;
use crate::rpc_client::RpcClient;
use std::sync::Arc;
use reqwest::Client;
use url::{ParseError, Url};
use solana_client::nonblocking::rpc_client::RpcClient as AsyncSolanaRpcClient;
use std::sync::Arc;
use url::{ParseError, Url};

/// Configuration settings for the Helius client
///
Expand Down Expand Up @@ -77,9 +77,8 @@ impl Config {
let client: Client = Client::builder().build().map_err(HeliusError::ReqwestError)?;
let mut rpc_url: Url = Url::parse(&self.endpoints.rpc)
.map_err(|e: ParseError| HeliusError::InvalidInput(format!("Invalid RPC URL: {}", e)))?;

rpc_url.query_pairs_mut()
.append_pair("api-key", &self.api_key);

rpc_url.query_pairs_mut().append_pair("api-key", &self.api_key);

let async_solana_client: Arc<AsyncSolanaRpcClient> = Arc::new(AsyncSolanaRpcClient::new(rpc_url.to_string()));
let rpc_client: Arc<RpcClient> = Arc::new(self.rpc_client_with_reqwest_client(client.clone())?);
Expand Down Expand Up @@ -108,11 +107,10 @@ impl Config {
) -> Result<Helius> {
let client: Client = Client::builder().build().map_err(HeliusError::ReqwestError)?;
let rpc_client: Arc<RpcClient> = Arc::new(self.rpc_client_with_reqwest_client(client.clone())?);

let wss: String = format!("{}{}", ENHANCED_WEBSOCKET_URL, self.api_key);
let ws_client: Arc<EnhancedWebsocket> = Arc::new(
EnhancedWebsocket::new(&wss, ping_interval_secs, pong_timeout_secs).await?
);
let ws_client: Arc<EnhancedWebsocket> =
Arc::new(EnhancedWebsocket::new(&wss, ping_interval_secs, pong_timeout_secs).await?);

Ok(Helius {
config: Arc::new(self),
Expand All @@ -138,19 +136,17 @@ impl Config {
) -> Result<Helius> {
let client: Client = Client::builder().build().map_err(HeliusError::ReqwestError)?;
let rpc_client: Arc<RpcClient> = Arc::new(self.rpc_client_with_reqwest_client(client.clone())?);

// Setup async client
let mut rpc_url: Url = Url::parse(&self.endpoints.rpc)
.map_err(|e: ParseError| HeliusError::InvalidInput(format!("Invalid RPC URL: {}", e)))?;
rpc_url.query_pairs_mut()
.append_pair("api-key", &self.api_key);
rpc_url.query_pairs_mut().append_pair("api-key", &self.api_key);
let async_solana_client = Arc::new(AsyncSolanaRpcClient::new(rpc_url.to_string()));

// Setup websocket
let wss: String = format!("{}{}", ENHANCED_WEBSOCKET_URL, self.api_key);
let ws_client: Arc<EnhancedWebsocket> = Arc::new(
EnhancedWebsocket::new(&wss, ping_interval_secs, pong_timeout_secs).await?
);
let ws_client: Arc<EnhancedWebsocket> =
Arc::new(EnhancedWebsocket::new(&wss, ping_interval_secs, pong_timeout_secs).await?);

Ok(Helius {
config: Arc::new(self),
Expand Down

0 comments on commit e35af6d

Please sign in to comment.