From 9bc79c7db9de736fe2e0fe1c313a85a7794aa5d2 Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Fri, 19 Apr 2024 03:11:00 -0400 Subject: [PATCH] Add HeliusFactory Functionality --- src/factory.rs | 20 ++++++++++++++------ tests/test_factory.rs | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/factory.rs b/src/factory.rs index d6fabf5..3160189 100644 --- a/src/factory.rs +++ b/src/factory.rs @@ -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; @@ -17,10 +20,15 @@ impl HeliusFactory { } pub fn create(&self, cluster: Cluster) -> Result { - 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, + }) } } @@ -36,4 +44,4 @@ impl HeliusFactory { // let helius_main = factory.create(Cluster::MainnetBeta).unwrap(); // // helius_main.request_name(...).await; -// } \ No newline at end of file +// } diff --git a/tests/test_factory.rs b/tests/test_factory.rs index 0ead8d2..33e3ce1 100644 --- a/tests/test_factory.rs +++ b/tests/test_factory.rs @@ -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() { @@ -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"); -} \ No newline at end of file +}