use anyhow::Result;
use std::cmp::Ordering;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub enum InstallationSource {
LocalBuild,
GitRepository(String),
PreBuiltBinary(String),
}
#[derive(Debug, Clone)]
pub struct BitcoinConfig {
pub network: String,
pub data_dir: PathBuf,
}
pub struct AnyaInstaller {
installation_source: InstallationSource,
#[allow(dead_code)]
bitcoin_config: BitcoinConfig,
}
impl AnyaInstaller {
pub fn new(install_source: InstallationSource, bitcoin_config: BitcoinConfig) -> Result<Self> {
Ok(Self {
installation_source: install_source,
bitcoin_config,
})
}
pub async fn install(&self, target_dir: PathBuf) -> Result<()> {
self.validate_source()?;
self.execute_installation(&target_dir).await?;
Ok(())
}
fn validate_source(&self) -> Result<()> {
match &self.installation_source {
InstallationSource::LocalBuild => {
Ok(())
}
InstallationSource::GitRepository(url) => {
if url.is_empty() {
anyhow::bail!("Git repository URL cannot be empty");
}
Ok(())
}
InstallationSource::PreBuiltBinary(path) => {
if path.is_empty() {
anyhow::bail!("Binary path cannot be empty");
}
Ok(())
}
}
}
async fn execute_installation(&self, _target_dir: &Path) -> Result<()> {
Ok(())
}
}
pub mod protocol {
use super::*;
pub fn verify_bip_support(required_bips: &[u32], installed_bips: &[u32]) -> Result<()> {
let missing: Vec<_> = required_bips
.iter()
.filter(|bip| !installed_bips.contains(bip))
.collect();
if !missing.is_empty() {
anyhow::bail!("Missing required BIPs: {:?}", missing);
}
Ok(())
}
pub fn check_taproot_activation(height: u64) -> Result<()> {
const TAPROOT_ACTIVATION_HEIGHT: u64 = 709632;
if height < TAPROOT_ACTIVATION_HEIGHT {
anyhow::bail!(
"Taproot not active until block {}",
TAPROOT_ACTIVATION_HEIGHT
);
}
Ok(())
}
}
pub fn version_compare(v1: &str, v2: &str) -> Ordering {
v1.cmp(v2)
}