#![allow(dead_code)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::large_enum_variant)]
#![allow(clippy::type_complexity)] #![allow(clippy::arc_with_non_send_sync)] #![allow(clippy::field_reassign_with_default)] #![allow(clippy::collapsible_match)] #![allow(unused_doc_comments, unused_imports, unused_variables, unused_mut)] #[cfg(all(not(target_os = "windows"), feature = "mimalloc", not(test)))]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
pub mod bip21;
pub mod cli;
pub mod config;
#[cfg(feature = "miniscript")]
pub mod miniscript;
pub mod module;
pub mod network;
pub mod node;
pub mod payment;
pub mod rpc;
pub mod storage;
pub mod utils;
#[cfg(feature = "production")]
pub mod validation;
#[cfg(feature = "zmq")]
extern crate zeromq; #[cfg(feature = "zmq")]
pub mod zmq;
pub use config::*;
pub use blvm_protocol::mempool::Mempool;
pub use blvm_protocol::{
tx_inputs, tx_outputs, Block, BlockHeader, ByteString, ConsensusError, Hash, Integer, Natural,
OutPoint, Result, Transaction, TransactionInput, TransactionOutput, UtxoSet, ValidationResult,
UTXO,
};
pub use blvm_protocol::{BitcoinProtocolEngine, ProtocolVersion};
pub struct Node {
protocol: BitcoinProtocolEngine,
storage: Option<std::sync::Arc<crate::storage::Storage>>,
network_manager: Option<std::sync::Arc<tokio::sync::RwLock<crate::network::NetworkManager>>>,
mempool_manager: Option<std::sync::Arc<crate::node::mempool::MempoolManager>>,
}
impl Node {
pub fn new(version: Option<ProtocolVersion>) -> anyhow::Result<Self> {
let version = version.unwrap_or(ProtocolVersion::Regtest);
Ok(Self {
protocol: BitcoinProtocolEngine::new(version)?,
storage: None,
network_manager: None,
mempool_manager: None,
})
}
pub fn with_storage(mut self, storage: std::sync::Arc<crate::storage::Storage>) -> Self {
self.storage = Some(storage);
self
}
pub fn with_network_manager(
mut self,
network_manager: std::sync::Arc<tokio::sync::RwLock<crate::network::NetworkManager>>,
) -> Self {
self.network_manager = Some(network_manager);
self
}
pub fn with_mempool_manager(
mut self,
mempool_manager: std::sync::Arc<crate::node::mempool::MempoolManager>,
) -> Self {
self.mempool_manager = Some(mempool_manager);
self
}
pub fn protocol(&self) -> &BitcoinProtocolEngine {
&self.protocol
}
pub fn storage(&self) -> Option<&std::sync::Arc<crate::storage::Storage>> {
self.storage.as_ref()
}
pub fn network_manager(
&self,
) -> Option<&std::sync::Arc<tokio::sync::RwLock<crate::network::NetworkManager>>> {
self.network_manager.as_ref()
}
pub fn mempool_manager(&self) -> Option<&std::sync::Arc<crate::node::mempool::MempoolManager>> {
self.mempool_manager.as_ref()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_protocol_integration() {
let node = Node::new(Some(ProtocolVersion::Regtest)).unwrap();
let protocol = node.protocol();
assert_eq!(protocol.get_protocol_version(), ProtocolVersion::Regtest);
assert!(protocol.supports_feature("fast_mining"));
}
#[test]
fn test_consensus_integration() {
let node = Node::new(None).unwrap(); let protocol = node.protocol();
let tx = Transaction {
version: 1,
inputs: blvm_protocol::tx_inputs![],
outputs: blvm_protocol::tx_outputs![TransactionOutput {
value: 1000,
script_pubkey: vec![blvm_protocol::opcodes::OP_1],
}],
lock_time: 0,
};
let result = protocol.validate_transaction(&tx);
assert!(result.is_ok());
}
#[test]
fn test_node_creation() {
let node = Node::new(None).unwrap();
assert_eq!(
node.protocol().get_protocol_version(),
ProtocolVersion::Regtest
);
let mainnet_node = Node::new(Some(ProtocolVersion::BitcoinV1)).unwrap();
assert_eq!(
mainnet_node.protocol().get_protocol_version(),
ProtocolVersion::BitcoinV1
);
}
}