use serde::{Deserialize, Serialize};
use solana_sdk::commitment_config::CommitmentConfig;
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct PriorityFee {
pub unit_limit: Option<u32>,
pub unit_price: Option<u64>,
}
impl PriorityFee {
pub fn new(unit_limit: Option<u32>, unit_price: Option<u64>) -> Self {
PriorityFee {
unit_limit,
unit_price,
}
}
}
#[derive(Debug, Clone)]
pub struct RpcEndpoint {
pub http: String,
pub ws: String,
}
impl RpcEndpoint {
pub fn new(http: String, ws: String) -> Self {
RpcEndpoint { http, ws }
}
}
#[derive(Debug, Clone)]
pub struct Cluster {
pub rpc: RpcEndpoint,
pub commitment: CommitmentConfig,
pub priority_fee: PriorityFee,
}
impl Cluster {
pub fn new(
http: String,
ws: String,
commitment: CommitmentConfig,
priority_fee: PriorityFee,
) -> Self {
Self {
rpc: RpcEndpoint { http, ws },
commitment,
priority_fee,
}
}
pub fn mainnet(commitment: CommitmentConfig, priority_fee: PriorityFee) -> Self {
Self::new(
"https://api.mainnet-beta.solana.com".to_string(),
"wss://api.mainnet-beta.solana.com".to_string(),
commitment,
priority_fee,
)
}
pub fn devnet(commitment: CommitmentConfig, priority_fee: PriorityFee) -> Self {
Self::new(
"https://api.devnet.solana.com".to_string(),
"wss://api.devnet.solana.com".to_string(),
commitment,
priority_fee,
)
}
pub fn testnet(commitment: CommitmentConfig, priority_fee: PriorityFee) -> Self {
Self::new(
"https://api.testnet.solana.com".to_string(),
"wss://api.testnet.solana.com".to_string(),
commitment,
priority_fee,
)
}
pub fn localnet(commitment: CommitmentConfig, priority_fee: PriorityFee) -> Self {
Self::new(
"http://localhost:8899".to_string(),
"ws://localhost:8900".to_string(),
commitment,
priority_fee,
)
}
}