Skip to content

Commit

Permalink
Populate src Directory and Initial Client / Config Code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed Apr 17, 2024
1 parent f365aa2 commit 959333c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::config::Config;
use crate::error::Result;
use crate::types::Cluster;

use reqwest::Client;

pub struct Helius {
config: Config,
client: Client,
}

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

Ok(Helius {config, client})
}
}
34 changes: 34 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::error::{ HeliusError, Result };
use crate::types::{ Cluster, HeliusEndpoints };

pub struct Config {
pub api_key: String,
pub cluster: Cluster,
pub endpoints: HeliusEndpoints,
}

impl Config {
pub fn new(api_key: &str, cluster: Cluster) -> Result<Self> {
if api_key.is_empty() {
return Err(HeliusError::InvalidInput("API key must not be empty".to_string()));
}


let endpoints: HeliusEndpoints = match cluster {
Cluster::Devnet => HeliusEndpoints {
api: "https://api-devnet.helius-rpc.com".to_string(),
rpc: "https://devnet.helius-rpc.com".to_string(),
},
Cluster::MainnetBeta => HeliusEndpoints {
api: "https://api-mainnet.helius-rpc.com".to_string(),
rpc: "https://mainnet.helius-rpc.com".to_string(),
},
};

Ok(Config {
api_key: api_key.to_string(),
cluster,
endpoints,
})
}
}
1 change: 1 addition & 0 deletions src/das_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub enum HeliusError {
#[error("Internal server error: {code} - {text}")]
InternalError { code: StatusCode, text: String},

#[error("Invalid input: {0}")]
InvalidInput(String),

#[error("Too many requests made to {path}")]
RateLimitExceeded { path: String },

Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod client;
mod config;
mod das_api;
mod error;
mod mint_api;
mod webhook;
mod rpc;
mod types;
mod utils;
mod webhook;

pub use client::Helius;
pub use client::Helius;
1 change: 1 addition & 0 deletions src/mint_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/rpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/webhook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 959333c

Please sign in to comment.