pub struct BitcoinProtocolEngine { /* private fields */ }Expand description
Bitcoin Protocol Engine
Provides protocol abstraction for different Bitcoin variants and evolution. Acts as a bridge between blvm-consensus (pure math) and blvm-node (implementation).
Implementations§
Source§impl BitcoinProtocolEngine
impl BitcoinProtocolEngine
Sourcepub fn validate_block_with_protocol(
&self,
block: &Block,
_utxos: &UtxoSet,
_height: u64,
context: &ProtocolValidationContext,
) -> Result<ValidationResult, ProtocolError>
pub fn validate_block_with_protocol( &self, block: &Block, _utxos: &UtxoSet, _height: u64, context: &ProtocolValidationContext, ) -> Result<ValidationResult, ProtocolError>
Validate a block with protocol-specific rules
Sourcepub fn validate_transaction_with_protocol(
&self,
tx: &Transaction,
context: &ProtocolValidationContext,
) -> Result<ValidationResult, ProtocolError>
pub fn validate_transaction_with_protocol( &self, tx: &Transaction, context: &ProtocolValidationContext, ) -> Result<ValidationResult, ProtocolError>
Validate a transaction with protocol-specific rules
Source§impl BitcoinProtocolEngine
impl BitcoinProtocolEngine
Sourcepub fn new(version: ProtocolVersion) -> Result<Self>
pub fn new(version: ProtocolVersion) -> Result<Self>
Create a new protocol engine for the specified variant with default configuration
Sourcepub fn with_config(
version: ProtocolVersion,
config: ProtocolConfig,
) -> Result<Self>
pub fn with_config( version: ProtocolVersion, config: ProtocolConfig, ) -> Result<Self>
Create a new protocol engine with custom configuration
Sourcepub fn get_config(&self) -> &ProtocolConfig
pub fn get_config(&self) -> &ProtocolConfig
Get the protocol configuration
Sourcepub fn get_config_mut(&mut self) -> &mut ProtocolConfig
pub fn get_config_mut(&mut self) -> &mut ProtocolConfig
Get mutable reference to protocol configuration
Sourcepub fn get_protocol_version(&self) -> ProtocolVersion
pub fn get_protocol_version(&self) -> ProtocolVersion
Get the current protocol version
Sourcepub fn get_network_params(&self) -> &NetworkParameters
pub fn get_network_params(&self) -> &NetworkParameters
Get network parameters for this protocol
Sourcepub fn validate_block(
&self,
block: &Block,
utxos: &UtxoSet,
height: u64,
) -> Result<ValidationResult>
pub fn validate_block( &self, block: &Block, utxos: &UtxoSet, height: u64, ) -> Result<ValidationResult>
Validate a block using this protocol’s rules
Sourcepub fn validate_transaction(&self, tx: &Transaction) -> Result<ValidationResult>
pub fn validate_transaction(&self, tx: &Transaction) -> Result<ValidationResult>
Validate a transaction using this protocol’s rules
Sourcepub fn validate_and_connect_block(
&self,
block: &Block,
witnesses: &[Vec<Witness>],
utxos: &UtxoSet,
height: u64,
recent_headers: Option<&[BlockHeader]>,
context: &ProtocolValidationContext,
) -> Result<(ValidationResult, UtxoSet)>
pub fn validate_and_connect_block( &self, block: &Block, witnesses: &[Vec<Witness>], utxos: &UtxoSet, height: u64, recent_headers: Option<&[BlockHeader]>, context: &ProtocolValidationContext, ) -> Result<(ValidationResult, UtxoSet)>
Validate block with protocol rules and update UTXO set
This method combines protocol validation (size limits, feature flags) with consensus validation and UTXO set updates. This is the recommended method for node implementations that need both validation and state updates.
§Arguments
block- The block to validate and connectwitnesses- Witness data for each transaction in the blockutxos- Current UTXO set (will be cloned, not mutated)height- Current block heightrecent_headers- Optional recent block headers for median time-past calculation (BIP113)context- Protocol validation context
§Returns
Returns (ValidationResult, UtxoSet) where:
ValidationResultindicates if the block is validUtxoSetis the updated UTXO set after applying the block’s transactions
§Example
use blvm_protocol::{BitcoinProtocolEngine, ProtocolVersion};
use blvm_protocol::validation::ProtocolValidationContext;
use blvm_protocol::{Block, UtxoSet};
let engine = BitcoinProtocolEngine::new(ProtocolVersion::BitcoinV1)?;
let context = ProtocolValidationContext::new(ProtocolVersion::BitcoinV1, 0)?;
// Create a test block
let block = Block {
header: blvm_consensus::BlockHeader {
version: 1,
prev_block_hash: [0u8; 32],
merkle_root: [0u8; 32],
timestamp: 1231006505,
bits: 0x1d00ffff,
nonce: 0,
},
transactions: vec![].into_boxed_slice(),
};
let witnesses = vec![];
let utxos = UtxoSet::default();
let (result, new_utxo_set) = engine.validate_and_connect_block(
&block,
&witnesses,
&utxos,
0,
None,
&context,
)?;Sourcepub fn supports_feature(&self, feature: &str) -> bool
pub fn supports_feature(&self, feature: &str) -> bool
Check if this protocol supports a specific feature
Sourcepub fn is_feature_active(
&self,
feature: &str,
height: u64,
timestamp: u64,
) -> bool
pub fn is_feature_active( &self, feature: &str, height: u64, timestamp: u64, ) -> bool
Check if a feature is active at a specific block height and timestamp
Sourcepub fn get_economic_parameters(&self) -> EconomicParameters
pub fn get_economic_parameters(&self) -> EconomicParameters
Get economic parameters for this protocol
Sourcepub fn get_feature_registry(&self) -> FeatureRegistry
pub fn get_feature_registry(&self) -> FeatureRegistry
Get feature activation registry for this protocol
Sourcepub fn feature_context(&self, height: u64, timestamp: u64) -> FeatureContext
pub fn feature_context(&self, height: u64, timestamp: u64) -> FeatureContext
Create a feature context for a specific block height and timestamp This consolidates all feature activation checks into a single context
Auto Trait Implementations§
impl Freeze for BitcoinProtocolEngine
impl RefUnwindSafe for BitcoinProtocolEngine
impl Send for BitcoinProtocolEngine
impl Sync for BitcoinProtocolEngine
impl Unpin for BitcoinProtocolEngine
impl UnsafeUnpin for BitcoinProtocolEngine
impl UnwindSafe for BitcoinProtocolEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more