1use std::fs;
2use std::path::{Path, PathBuf};
3use std::result::Result;
4
5#[derive(Debug, Clone, Default)]
7pub struct BitcoinConfig {
8 pub network: String,
9 pub rpc_url: String,
10 pub auth_method: String,
11 pub username: Option<String>,
12 pub password: Option<String>,
13 pub timeout_seconds: u64,
14}
15
16const BIP341_SILENT_LEAF: bool = true;
18
19#[derive(Debug)]
21pub struct BIPCompliance {
22 pub taproot_enabled: bool,
23 pub schnorr_enabled: bool,
24 pub psbt_version: u8,
25}
26pub struct ConfigManager {
27 path: PathBuf,
28}
29
30impl ConfigManager {
31 pub fn new(install_dir: &Path) -> Self {
32 Self {
33 path: install_dir.join("conf/bitcoin.conf"),
34 }
35 }
36
37 pub fn generate(&self, _config: &BitcoinConfig) -> Result<(), std::io::Error> {
38 let content = format!(
39 "network=mainnet\n\
40 taproot=1\n\
41 silent_leaf={BIP341_SILENT_LEAF}\n\
42 psbt_version=2"
43 );
44 fs::write(&self.path, content)
45 }
46
47 pub fn validate_bips(&self) -> Result<BIPCompliance, std::io::Error> {
48 let content = fs::read_to_string(&self.path)?;
49
50 let taproot_enabled = content.contains("taproot=1");
52 let schnorr_enabled = content.contains("schnorr=1") || taproot_enabled; let psbt_version = if content.contains("psbt_version=") {
56 let line = content
57 .lines()
58 .find(|line| line.starts_with("psbt_version="))
59 .unwrap_or("psbt_version=0");
60
61 line.split('=')
62 .nth(1)
63 .and_then(|v| v.parse::<u8>().ok())
64 .unwrap_or(0)
65 } else {
66 0 };
68
69 Ok(BIPCompliance {
70 taproot_enabled,
71 schnorr_enabled,
72 psbt_version,
73 })
74 }
75}