Skip to content

Commit

Permalink
Add HeliusFactory Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed Apr 19, 2024
1 parent ce3fb48 commit 9bc79c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/factory.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::sync::Arc;

use crate::client::Helius;
use crate::config::Config;
use crate::types::Cluster;
use crate::error::Result;
use crate::rpc_client::RpcClient;
use crate::types::Cluster;

use reqwest::Client;

Expand All @@ -17,10 +20,15 @@ impl HeliusFactory {
}

pub fn create(&self, cluster: Cluster) -> Result<Helius> {
let config = Config::new(&self.api_key, cluster)?;
let client = Client::new();

Ok(Helius { config, client })
let config: Config = Config::new(&self.api_key, cluster)?;
let client: Client = Client::new();
let rpc_client = RpcClient::new(Arc::new(client), Arc::new(config.clone()))?;

Ok(Helius {
config,
client,
rpc_client,
})
}
}

Expand All @@ -36,4 +44,4 @@ impl HeliusFactory {

// let helius_main = factory.create(Cluster::MainnetBeta).unwrap();
// // helius_main.request_name(...).await;
// }
// }
4 changes: 2 additions & 2 deletions tests/test_factory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use helius_sdk::{ Helius, HeliusFactory };
use helius_sdk::types::Cluster;
use helius_sdk::{Helius, HeliusFactory};

#[test]
fn test_factory_create_devnet_instance() {
Expand All @@ -19,4 +19,4 @@ fn test_factory_create_mainnet_instance() {
assert_eq!(helius.config.api_key, "valid_api_key");
assert_eq!(helius.config.endpoints.api, "https://api-mainnet.helius-rpc.com");
assert_eq!(helius.config.endpoints.rpc, "https://mainnet.helius-rpc.com");
}
}

0 comments on commit 9bc79c7

Please sign in to comment.