pub struct ConsensusProof;Expand description
Consensus Proof - wrapper struct for consensus validation functions
This struct provides a convenient API for accessing all consensus validation functions. All methods delegate to the corresponding module functions.
Implementations§
Source§impl ConsensusProof
impl ConsensusProof
Sourcepub fn new() -> ConsensusProof
pub fn new() -> ConsensusProof
Create a new ConsensusProof instance
Sourcepub fn validate_transaction(
&self,
tx: &Transaction,
) -> Result<ValidationResult, ConsensusError>
pub fn validate_transaction( &self, tx: &Transaction, ) -> Result<ValidationResult, ConsensusError>
Validate a transaction according to consensus rules
Sourcepub fn validate_tx_inputs(
&self,
tx: &Transaction,
utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
height: u64,
) -> Result<(ValidationResult, i64), ConsensusError>
pub fn validate_tx_inputs( &self, tx: &Transaction, utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, height: u64, ) -> Result<(ValidationResult, i64), ConsensusError>
Validate transaction inputs against UTXO set
Sourcepub fn validate_block(
&self,
block: &Block,
utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
height: u64,
) -> Result<(ValidationResult, HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>), ConsensusError>
👎Deprecated since 0.1.33: Use validate_block_with_time_context with explicit witnesses, network, and TimeContext
pub fn validate_block( &self, block: &Block, utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, height: u64, ) -> Result<(ValidationResult, HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>), ConsensusError>
Use validate_block_with_time_context with explicit witnesses, network, and TimeContext
Validate a complete block
Deprecated: builds empty witness stacks and defaults to Network::Mainnet with
wall-clock time. Use [validate_block_with_time_context] with explicit witnesses,
network, and median-time-past instead.
Sourcepub fn validate_block_with_time_context(
&self,
block: &Block,
witnesses: &[Vec<Vec<Vec<u8>>>],
utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
height: u64,
time_context: Option<TimeContext>,
network: Network,
) -> Result<(ValidationResult, HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>), ConsensusError>
pub fn validate_block_with_time_context( &self, block: &Block, witnesses: &[Vec<Vec<Vec<u8>>>], utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, height: u64, time_context: Option<TimeContext>, network: Network, ) -> Result<(ValidationResult, HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>), ConsensusError>
Validate a complete block with witness data and time context
Sourcepub fn verify_script(
&self,
script_sig: &Vec<u8>,
script_pubkey: &Vec<u8>,
witness: Option<&Vec<u8>>,
flags: u32,
) -> Result<bool, ConsensusError>
👎Deprecated since 0.1.33: Use verify_script_with_context via script module for witness-aware verification
pub fn verify_script( &self, script_sig: &Vec<u8>, script_pubkey: &Vec<u8>, witness: Option<&Vec<u8>>, flags: u32, ) -> Result<bool, ConsensusError>
Use verify_script_with_context via script module for witness-aware verification
Verify script execution (legacy API — see script::verify_script deprecation).
Sourcepub fn check_proof_of_work(
&self,
header: &BlockHeader,
) -> Result<bool, ConsensusError>
pub fn check_proof_of_work( &self, header: &BlockHeader, ) -> Result<bool, ConsensusError>
Check proof of work
Sourcepub fn get_block_subsidy(&self, height: u64) -> i64
pub fn get_block_subsidy(&self, height: u64) -> i64
Get block subsidy for height
Sourcepub fn total_supply(&self, height: u64) -> i64
pub fn total_supply(&self, height: u64) -> i64
Calculate total supply at height
Sourcepub fn get_next_work_required(
&self,
current_header: &BlockHeader,
prev_headers: &[BlockHeader],
) -> Result<u64, ConsensusError>
pub fn get_next_work_required( &self, current_header: &BlockHeader, prev_headers: &[BlockHeader], ) -> Result<u64, ConsensusError>
Get next work required for difficulty adjustment
Sourcepub fn accept_to_memory_pool(
&self,
tx: &Transaction,
utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
mempool: &Mempool,
height: u64,
time_context: Option<TimeContext>,
network: Network,
) -> Result<MempoolResult, ConsensusError>
pub fn accept_to_memory_pool( &self, tx: &Transaction, utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, mempool: &Mempool, height: u64, time_context: Option<TimeContext>, network: Network, ) -> Result<MempoolResult, ConsensusError>
Accept transaction to memory pool
Sourcepub fn is_standard_tx(&self, tx: &Transaction) -> Result<bool, ConsensusError>
pub fn is_standard_tx(&self, tx: &Transaction) -> Result<bool, ConsensusError>
Check if transaction is standard
Sourcepub fn replacement_checks(
&self,
new_tx: &Transaction,
existing_tx: &Transaction,
utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
mempool: &Mempool,
) -> Result<bool, ConsensusError>
pub fn replacement_checks( &self, new_tx: &Transaction, existing_tx: &Transaction, utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, mempool: &Mempool, ) -> Result<bool, ConsensusError>
Check if transaction can replace existing one (RBF)
Sourcepub fn create_new_block(
&self,
utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
mempool_txs: &[Transaction],
height: u64,
prev_header: &BlockHeader,
prev_headers: &[BlockHeader],
coinbase_script: &Vec<u8>,
coinbase_address: &Vec<u8>,
) -> Result<Block, ConsensusError>
pub fn create_new_block( &self, utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, mempool_txs: &[Transaction], height: u64, prev_header: &BlockHeader, prev_headers: &[BlockHeader], coinbase_script: &Vec<u8>, coinbase_address: &Vec<u8>, ) -> Result<Block, ConsensusError>
Create new block from mempool transactions
Sourcepub fn create_new_block_with_time(
&self,
utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
mempool_txs: &[Transaction],
height: u64,
prev_header: &BlockHeader,
prev_headers: &[BlockHeader],
coinbase_script: &Vec<u8>,
coinbase_address: &Vec<u8>,
block_time: u64,
network: Network,
mempool_witnesses: Option<&[Option<Vec<Vec<Vec<u8>>>>]>,
) -> Result<Block, ConsensusError>
pub fn create_new_block_with_time( &self, utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, mempool_txs: &[Transaction], height: u64, prev_header: &BlockHeader, prev_headers: &[BlockHeader], coinbase_script: &Vec<u8>, coinbase_address: &Vec<u8>, block_time: u64, network: Network, mempool_witnesses: Option<&[Option<Vec<Vec<Vec<u8>>>>]>, ) -> Result<Block, ConsensusError>
Create new block with explicit time, network, and optional per-tx witness stacks.
Sourcepub fn mine_block(
&self,
block: Block,
max_attempts: u64,
) -> Result<(Block, MiningResult), ConsensusError>
pub fn mine_block( &self, block: Block, max_attempts: u64, ) -> Result<(Block, MiningResult), ConsensusError>
Mine a block by finding valid nonce
Sourcepub fn create_block_template(
&self,
utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
mempool_txs: &[Transaction],
height: u64,
prev_header: &BlockHeader,
prev_headers: &[BlockHeader],
coinbase_script: &Vec<u8>,
coinbase_address: &Vec<u8>,
network: Network,
mempool_witnesses: Option<&[Option<Vec<Vec<Vec<u8>>>>]>,
) -> Result<BlockTemplate, ConsensusError>
pub fn create_block_template( &self, utxo_set: &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, mempool_txs: &[Transaction], height: u64, prev_header: &BlockHeader, prev_headers: &[BlockHeader], coinbase_script: &Vec<u8>, coinbase_address: &Vec<u8>, network: Network, mempool_witnesses: Option<&[Option<Vec<Vec<Vec<u8>>>>]>, ) -> Result<BlockTemplate, ConsensusError>
Create block template for mining
Sourcepub fn reorganize_chain(
&self,
new_chain: &[Block],
current_chain: &[Block],
current_utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
current_height: u64,
network: Network,
) -> Result<ReorganizationResult, ConsensusError>
👎Deprecated since 0.1.33: Use reorganize_chain_with_witnesses with explicit witness data for SegWit chains
pub fn reorganize_chain( &self, new_chain: &[Block], current_chain: &[Block], current_utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, current_height: u64, network: Network, ) -> Result<ReorganizationResult, ConsensusError>
Use reorganize_chain_with_witnesses with explicit witness data for SegWit chains
Reorganize chain when a longer chain is found (legacy: synthesizes empty witnesses).
Sourcepub fn reorganize_chain_with_witnesses(
&self,
new_chain: &[Block],
new_chain_witnesses: &[Vec<Vec<Vec<Vec<u8>>>>],
new_chain_headers: Option<&[BlockHeader]>,
current_chain: &[Block],
current_utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
current_height: u64,
network_time: u64,
network: Network,
) -> Result<ReorganizationResult, ConsensusError>
pub fn reorganize_chain_with_witnesses( &self, new_chain: &[Block], new_chain_witnesses: &[Vec<Vec<Vec<Vec<u8>>>>], new_chain_headers: Option<&[BlockHeader]>, current_chain: &[Block], current_utxo_set: HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, current_height: u64, network_time: u64, network: Network, ) -> Result<ReorganizationResult, ConsensusError>
Reorganize chain with explicit witness data (preferred API).
Sourcepub fn should_reorganize(
&self,
new_chain: &[Block],
current_chain: &[Block],
) -> Result<bool, ConsensusError>
pub fn should_reorganize( &self, new_chain: &[Block], current_chain: &[Block], ) -> Result<bool, ConsensusError>
Check if reorganization is beneficial
Sourcepub fn calculate_transaction_weight(
&self,
tx: &Transaction,
witness: Option<&Vec<Vec<u8>>>,
) -> Result<u64, ConsensusError>
pub fn calculate_transaction_weight( &self, tx: &Transaction, witness: Option<&Vec<Vec<u8>>>, ) -> Result<u64, ConsensusError>
Calculate transaction weight for SegWit
Sourcepub fn validate_segwit_block(
&self,
block: &Block,
witnesses: &[Vec<Vec<u8>>],
max_block_weight: u64,
) -> Result<bool, ConsensusError>
pub fn validate_segwit_block( &self, block: &Block, witnesses: &[Vec<Vec<u8>>], max_block_weight: u64, ) -> Result<bool, ConsensusError>
Validate SegWit block
Sourcepub fn validate_taproot_transaction(
&self,
tx: &Transaction,
witness: Option<&Vec<Vec<u8>>>,
) -> Result<bool, ConsensusError>
pub fn validate_taproot_transaction( &self, tx: &Transaction, witness: Option<&Vec<Vec<u8>>>, ) -> Result<bool, ConsensusError>
Validate Taproot transaction
Sourcepub fn is_taproot_output(&self, output: &TransactionOutput) -> bool
pub fn is_taproot_output(&self, output: &TransactionOutput) -> bool
Check if transaction output is Taproot
Trait Implementations§
Source§impl Clone for ConsensusProof
impl Clone for ConsensusProof
Source§fn clone(&self) -> ConsensusProof
fn clone(&self) -> ConsensusProof
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ConsensusProof
Source§impl Debug for ConsensusProof
impl Debug for ConsensusProof
Source§impl Default for ConsensusProof
impl Default for ConsensusProof
Source§fn default() -> ConsensusProof
fn default() -> ConsensusProof
Auto Trait Implementations§
impl Freeze for ConsensusProof
impl RefUnwindSafe for ConsensusProof
impl Send for ConsensusProof
impl Sync for ConsensusProof
impl Unpin for ConsensusProof
impl UnsafeUnpin for ConsensusProof
impl UnwindSafe for ConsensusProof
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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