pub mod enhanced_transaction_types;
pub mod enhanced_websocket;
pub mod enums;
pub mod inner;
pub mod options;
pub mod zk_compression_types;
pub use self::enhanced_transaction_types::*;
pub use self::enhanced_websocket::{
FullTransactionNotification, RpcTransactionsConfig, TransactionCommitment, TransactionNotification,
TransactionSubscribeFilter, TransactionSubscribeOptions, UiEnhancedTransactionEncoding,
};
pub use self::enums::*;
pub use self::inner::*;
pub use self::options::*;
pub use self::zk_compression_types::*;
pub use self::inner::{
AdminBillingCycle, AdminSubscriptionDetails, AdminUsageBreakdown, BalanceChange, BalancesPagination,
BalancesResponse, BatchIdentityRequest, FundingSource, HistoryResponse, HistoryTransaction, Identity, Nft,
Pagination, ProjectUsage, TokenAccountsOption, TokenBalance, Transfer, TransferDirection, TransfersResponse,
};
use crate::error::{HeliusError, Result};
use url::Url;
#[derive(Clone, Debug)]
pub struct ApiKey(String);
impl ApiKey {
pub fn new(key: impl Into<String>) -> Result<Self> {
let key = key.into();
let trimmed = key.trim();
if trimmed.is_empty() {
return Err(HeliusError::InvalidInput("API key cannot be empty".to_string()));
}
Ok(ApiKey(key))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<ApiKey> for String {
fn from(key: ApiKey) -> String {
key.0
}
}
pub fn validate_rpc_url(url: &str) -> Result<Url> {
let parsed = Url::parse(url)
.map_err(|e| HeliusError::InvalidInput(format!("Invalid URL format: {}. Expected: https://example.com/", e)))?;
match parsed.scheme() {
"http" | "https" => {}
scheme => {
return Err(HeliusError::InvalidInput(format!(
"Invalid URL scheme '{}'. Only 'http' and 'https' are allowed for RPC endpoints.",
scheme
)))
}
}
if !parsed.username().is_empty() || parsed.password().is_some() {
return Err(HeliusError::InvalidInput(
"URL contains embedded credentials. Remove them and use .with_api_key() instead.".to_string(),
));
}
Ok(parsed)
}
pub fn validate_ws_url(url: &str) -> Result<Url> {
let parsed = Url::parse(url).map_err(|e| HeliusError::InvalidInput(format!("Invalid WebSocket URL: {}", e)))?;
match parsed.scheme() {
"ws" | "wss" => {}
scheme => {
return Err(HeliusError::InvalidInput(format!(
"Invalid WebSocket scheme '{}'. Only 'ws' and 'wss' are allowed.",
scheme
)))
}
}
if !parsed.username().is_empty() || parsed.password().is_some() {
return Err(HeliusError::InvalidInput(
"WebSocket URL contains embedded credentials.".to_string(),
));
}
Ok(parsed)
}