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 (witness-blind).
The block weight check is a lower bound only. Use
[validate_block_with_protocol_and_witnesses] for accurate BIP141 weight enforcement.
Sourcepub fn validate_block_with_protocol_and_witnesses(
&self,
block: &Block,
witnesses: &[Vec<Witness>],
_utxos: &UtxoSet,
_height: u64,
context: &ProtocolValidationContext,
) -> Result<ValidationResult, ProtocolError>
pub fn validate_block_with_protocol_and_witnesses( &self, block: &Block, witnesses: &[Vec<Witness>], _utxos: &UtxoSet, _height: u64, context: &ProtocolValidationContext, ) -> Result<ValidationResult, ProtocolError>
Validate a block with protocol-specific rules and witness data.
Performs a full BIP141 weight check using the provided witnesses.
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 with_signet_challenge(self, script: Option<Vec<u8>>) -> Self
pub fn with_signet_challenge(self, script: Option<Vec<u8>>) -> Self
Override the BIP325 signet challenge script (custom signet networks).
Sourcepub fn connect_block_validation_context<H: AsRef<BlockHeader>>(
&self,
recent_headers: Option<&[H]>,
network_time: u64,
) -> BlockValidationContext
pub fn connect_block_validation_context<H: AsRef<BlockHeader>>( &self, recent_headers: Option<&[H]>, network_time: u64, ) -> BlockValidationContext
Build consensus [BlockValidationContext] including signet challenge from network params.
Sourcepub fn validate_block(
&self,
block: &Block,
utxos: &UtxoSet,
height: u64,
) -> Result<ValidationResult>
👎Deprecated since 0.1.0: Use validate_and_connect_block with explicit witnesses and a ProtocolValidationContext
pub fn validate_block( &self, block: &Block, utxos: &UtxoSet, height: u64, ) -> Result<ValidationResult>
Use validate_and_connect_block with explicit witnesses and a ProtocolValidationContext
Validate a block using this protocol’s rules.
Deprecated: this API builds empty witness vectors for every input and passes
None for the time context, so:
- SegWit and Taproot scripts are validated against empty witness stacks (always fail on witness-dependent scripts).
- Time-dependent checks fall back to wall-clock time instead of the median-time-past computed from actual block headers.
Prefer [validate_and_connect_block], which accepts explicit witnesses and a
validation::ProtocolValidationContext with a correct median_time_past.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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