Skip to main content

BitcoinProtocolEngine

Struct BitcoinProtocolEngine 

Source
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

Source

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

Source

pub fn validate_transaction_with_protocol( &self, tx: &Transaction, context: &ProtocolValidationContext, ) -> Result<ValidationResult, ProtocolError>

Validate a transaction with protocol-specific rules

Source§

impl BitcoinProtocolEngine

Source

pub fn new(version: ProtocolVersion) -> Result<Self>

Create a new protocol engine for the specified variant with default configuration

Source

pub fn with_config( version: ProtocolVersion, config: ProtocolConfig, ) -> Result<Self>

Create a new protocol engine with custom configuration

Source

pub fn get_config(&self) -> &ProtocolConfig

Get the protocol configuration

Source

pub fn get_config_mut(&mut self) -> &mut ProtocolConfig

Get mutable reference to protocol configuration

Source

pub fn get_protocol_version(&self) -> ProtocolVersion

Get the current protocol version

Source

pub fn get_network_params(&self) -> &NetworkParameters

Get network parameters for this protocol

Source

pub fn validate_block( &self, block: &Block, utxos: &UtxoSet, height: u64, ) -> Result<ValidationResult>

Validate a block using this protocol’s rules

Source

pub fn validate_transaction(&self, tx: &Transaction) -> Result<ValidationResult>

Validate a transaction using this protocol’s rules

Source

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 connect
  • witnesses - Witness data for each transaction in the block
  • utxos - Current UTXO set (will be cloned, not mutated)
  • height - Current block height
  • recent_headers - Optional recent block headers for median time-past calculation (BIP113)
  • context - Protocol validation context
§Returns

Returns (ValidationResult, UtxoSet) where:

  • ValidationResult indicates if the block is valid
  • UtxoSet is 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,
)?;
Source

pub fn supports_feature(&self, feature: &str) -> bool

Check if this protocol supports a specific feature

Source

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

Source

pub fn get_economic_parameters(&self) -> EconomicParameters

Get economic parameters for this protocol

Source

pub fn get_feature_registry(&self) -> FeatureRegistry

Get feature activation registry for this protocol

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more