anya_core/bitcoin/
manager.rs1use crate::bitcoin::adapters::BitcoinAdapter;
3use crate::AnyaResult;
4use std::sync::{Arc, Mutex};
5
6#[derive(Clone, Debug)]
8pub struct BitcoinManagerConfig {
9 pub enabled: bool,
11 pub network: String,
13 pub rpc_url: Option<String>,
15 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
30pub struct BitcoinManager {
32 config: BitcoinManagerConfig,
33 adapter: Arc<BitcoinAdapter>,
34 metrics: Arc<Mutex<crate::core::PrometheusMetrics>>,
35}
36
37impl BitcoinManager {
38 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 pub fn is_enabled(&self) -> bool {
53 self.config.enabled
54 }
55
56 pub fn get_network(&self) -> &str {
58 &self.config.network
59 }
60
61 pub fn get_adapter(&self) -> Arc<BitcoinAdapter> {
63 self.adapter.clone()
64 }
65
66 pub async fn get_block_height(&self) -> AnyaResult<u32> {
68 {
70 let mut metrics = self.metrics.lock().unwrap();
71 metrics.increment_counter("bitcoin_api_calls", "method", "get_block_height");
72 }
73
74 Ok(32) }
77}