1mod balances;
2mod enhanced_transactions;
3mod name;
4mod nft;
5mod rpc_client;
6mod token_metadata;
7mod webhook;
8mod das;
9
10pub use {
11 balances::*, enhanced_transactions::*, name::*, nft::*, rpc_client::*, token_metadata::*,
12 webhook::*,
13 das::*,
14};
15
16use crate::{common::Cluster, util::rpc_url_from_cluster};
17use solana_client::rpc_client::RpcClient;
18use crate::request_handler::RequestHandler;
19
20const API_URL_V1: &str = "https://api.helius.xyz/v1";
21const API_URL_V0: &str = "https://api.helius.xyz/v0";
22const DEV_API_URL_V0: &str = "https://api-devnet.helius.xyz/v0";
23const DAS_URL: &str = "https://mainnet.helius-rpc.com";
24
25pub struct Helius {
26 api_key: String,
27 cluster: Cluster,
28 pub rpc: HeliusRpc,
29 handler: RequestHandler
30}
31
32impl Helius {
33 pub fn new(api_key: String, cluster: Cluster) -> Helius {
34 let endpoint = rpc_url_from_cluster(api_key.clone(), cluster);
35 let connection = RpcClient::new(endpoint);
36 return Helius {
37 api_key,
38 cluster,
39 rpc: HeliusRpc::new(connection),
40 handler: RequestHandler::new()
41 };
42 }
43
44 pub fn get_url_v1(&self, method: &str) -> String {
45 return self.make_url(API_URL_V1, method);
46 }
47
48 pub fn get_url_v0(&self, method: &str) -> String {
49 let url = match self.cluster {
50 Cluster::MainnetBeta => API_URL_V0,
51 Cluster::Devnet => DEV_API_URL_V0,
52 };
53 return self.make_url(url, method);
54 }
55
56 pub fn get_das_url(&self) -> String {
57 return self.make_url(DAS_URL, "");
58 }
59
60 fn make_url(&self, base: &str, method: &str) -> String {
61 return format!("{base}/{method}?api-key={}", self.api_key);
62 }
63}