use std::path::PathBuf;
#[derive(Clone, Copy, PartialEq)]
#[allow(dead_code)] pub enum Ledger {
Herominers,
TwoMiners,
K1Pool,
None,
}
pub struct Pool {
pub label: &'static str,
pub host: &'static str,
pub port: u16,
pub ledger: Ledger,
pub payout_erg: f64,
pub solo: Option<Solo>,
}
#[derive(Clone, Copy)]
pub enum Solo {
Prefix(&'static str),
Endpoint(&'static str, u16),
}
pub const POOLS: &[Pool] = &[
Pool {
label: "herominers",
host: "ergo.herominers.com",
port: 1180,
ledger: Ledger::Herominers,
payout_erg: 0.5,
solo: Some(Solo::Prefix("solo:")),
},
Pool {
label: "2miners",
host: "erg.2miners.com",
port: 8888,
ledger: Ledger::TwoMiners,
payout_erg: 1.0,
solo: Some(Solo::Endpoint("solo-erg.2miners.com", 8888)),
},
];
pub fn has_ledger(idx: usize) -> bool {
POOLS.get(idx).map(|p| p.ledger != Ledger::None).unwrap_or(false)
}
pub fn get(idx: usize) -> &'static Pool {
POOLS.get(idx).unwrap_or(&POOLS[0])
}
pub fn endpoint(idx: usize, solo: bool) -> (&'static str, u16, &'static str) {
let p = get(idx);
match (solo, p.solo) {
(true, Some(Solo::Prefix(pre))) => (p.host, p.port, pre),
(true, Some(Solo::Endpoint(h, port))) => (h, port, ""),
_ => (p.host, p.port, ""),
}
}
pub fn has_solo(idx: usize) -> bool {
get(idx).solo.is_some()
}
fn config_path() -> Option<PathBuf> {
let home = std::env::var_os("HOME")?;
Some(PathBuf::from(home).join("Library/Application Support/ai.cyber.erga/pool"))
}
pub fn load_choice() -> usize {
let Some(p) = config_path() else { return 0 };
std::fs::read_to_string(p)
.ok()
.and_then(|s| {
let want = s.trim().to_string();
POOLS.iter().position(|p| p.label == want)
})
.unwrap_or(0)
}
pub fn save_choice(idx: usize) {
let Some(p) = config_path() else { return };
if let Some(dir) = p.parent() {
let _ = std::fs::create_dir_all(dir);
}
if let Some(pool) = POOLS.get(idx) {
let _ = std::fs::write(p, pool.label);
}
}