anya_core/bitcoin/
manager.rs

1// Bitcoin Manager Implementation
2use crate::bitcoin::adapters::BitcoinAdapter;
3use crate::AnyaResult;
4use std::sync::{Arc, Mutex};
5
6/// Configuration for the Bitcoin manager
7#[derive(Clone, Debug)]
8pub struct BitcoinManagerConfig {
9    /// Whether Bitcoin functionality is enabled
10    pub enabled: bool,
11    /// Network to use (mainnet, testnet, regtest)
12    pub network: String,
13    /// RPC connection details
14    pub rpc_url: Option<String>,
15    /// Authentication credentials
16    pub auth: Option<(String, String)>,
17}
18
19impl Default for BitcoinManagerConfig {
20    fn default() -> Self {
21        Self {
22            enabled: true,
23            network: "testnet".to_string(),
24            rpc_url: None,
25            auth: None,
26        }
27    }
28}
29
30/// Bitcoin manager for Anya Core
31pub struct BitcoinManager {
32    config: BitcoinManagerConfig,
33    adapter: Arc<BitcoinAdapter>,
34    metrics: Arc<Mutex<crate::core::PrometheusMetrics>>,
35}
36
37impl BitcoinManager {
38    /// Create a new Bitcoin manager
39    pub fn new(
40        config: BitcoinManagerConfig,
41        adapter: Arc<BitcoinAdapter>,
42        metrics: Arc<Mutex<crate::core::PrometheusMetrics>>,
43    ) -> Self {
44        Self {
45            config,
46            adapter,
47            metrics,
48        }
49    }
50
51    /// Check if Bitcoin functionality is enabled
52    pub fn is_enabled(&self) -> bool {
53        self.config.enabled
54    }
55
56    /// Get the current Bitcoin network
57    pub fn get_network(&self) -> &str {
58        &self.config.network
59    }
60
61    /// Get the underlying Bitcoin adapter
62    pub fn get_adapter(&self) -> Arc<BitcoinAdapter> {
63        self.adapter.clone()
64    }
65
66    /// Get the current block height
67    pub async fn get_block_height(&self) -> AnyaResult<u32> {
68        // Increment metrics counter
69        {
70            let mut metrics = self.metrics.lock().unwrap();
71            metrics.increment_counter("bitcoin_api_calls", "method", "get_block_height");
72        }
73
74        // Forward to adapter
75        Ok(32) // Placeholder - should be implemented with actual adapter call
76    }
77}