bitcoin: Move taproot module errors to error submodule
What changed, and why it matters
This commit is a routine code cleanup in the rust-bitcoin library. It moves error type definitions for the Taproot module into a new 'error' submodule and re-exports them so existing code keeps working. There are no functional changes to how the library behaves, and no security issue is present.
No security action needed. Treat as a normal refactoring/reorganization change during code review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors bitcoin/src/taproot/mod.rs by relocating all taproot error enums and structs (IncompleteBuilderError, HiddenNodesError, TaprootBuilderError, TaprootError, InvalidMerkleBranchSizeError, InvalidMerkleTreeDepthError, InvalidTaprootLeafVersionError, InvalidControlBlockSizeError, and SigFromSliceError) into a new pub mod error. It adds re-exports at the module root to preserve the public API, adjusts imports accordingly, and changes the visibility of the tuple fields in the Invalid*Error structs from private to pub(super). No logic, validation, or behavior changes are introduced.
Changed components
bitcoin/src/taproot/mod.rsInspect captured patch +297 / −267
diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs
index 04082545..c94941ab 100644
--- a/bitcoin/src/taproot/mod.rs
+++ b/bitcoin/src/taproot/mod.rs
@@ -7,7 +7,6 @@
pub mod merkle_branch;
use core::cmp::{Ordering, Reverse};
-use core::convert::Infallible;
use core::fmt;
use core::iter::FusedIterator;
@@ -15,9 +14,9 @@ use core::iter::FusedIterator;
use arbitrary::{Arbitrary, Unstructured};
use hashes::{hash_newtype, sha256t, sha256t_tag, HashEngine};
use internals::array::ArrayExt;
+use internals::impl_to_hex_from_lower_hex;
#[allow(unused)] // MSRV polyfill
use internals::slice::SliceExt;
-use internals::{impl_to_hex_from_lower_hex, write_err};
use io::Write;
use secp256k1::Scalar;
@@ -25,20 +24,24 @@ use crate::consensus::Encodable;
use crate::crypto::key::{
SerializedXOnlyPublicKey, TapTweak, TweakedPublicKey, UntweakedPublicKey,
};
-use crate::hex::{self, DecodeVariableLengthBytesError};
-use crate::key::ParseXOnlyPublicKeyError;
use crate::prelude::{BTreeMap, BTreeSet, BinaryHeap, Vec};
-use crate::{TapScript, TapScriptBuf};
+use crate::{hex, TapScript, TapScriptBuf};
// Re-export these so downstream only has to use one `taproot` module.
#[rustfmt::skip]
#[doc(inline)]
-pub use crate::crypto::taproot::{SerializedSignature, SigFromSliceError, Signature};
+pub use crate::crypto::taproot::{SerializedSignature, Signature};
#[doc(inline)]
pub use merkle_branch::TaprootMerkleBranch;
#[doc(inline)]
pub use merkle_branch::TaprootMerkleBranchBuf;
+#[doc(no_inline)]
+pub use self::error::{
+ HiddenNodesError, IncompleteBuilderError, InvalidControlBlockSizeError,
+ InvalidMerkleBranchSizeError, InvalidMerkleTreeDepthError, InvalidTaprootLeafVersionError,
+ SigFromSliceError, TaprootBuilderError, TaprootError,
+};
#[cfg(feature = "arbitrary")]
use crate::psbt::serialize::Deserialize;
#[doc(inline)]
@@ -646,90 +649,6 @@ impl Default for TaprootBuilder {
fn default() -> Self { Self::new() }
}
-/// Error happening when [`TapTree`] is constructed from a [`TaprootBuilder`]
-/// having hidden branches or not being finalized.
-#[derive(Debug, Clone, PartialEq, Eq)]
-#[non_exhaustive]
-pub enum IncompleteBuilderError {
- /// Indicates an attempt to construct a Taproot tree from a builder containing incomplete branches.
- NotFinalized(TaprootBuilder),
- /// Indicates an attempt to construct a Taproot tree from a builder containing hidden parts.
- HiddenParts(TaprootBuilder),
-}
-
-impl IncompleteBuilderError {
- /// Converts error into the original incomplete [`TaprootBuilder`] instance.
- pub fn into_builder(self) -> TaprootBuilder {
- match self {
- Self::NotFinalized(builder) | Self::HiddenParts(builder) => builder,
- }
- }
-}
-
-impl From<Infallible> for IncompleteBuilderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
-
-impl core::fmt::Display for IncompleteBuilderError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- f.write_str(match self {
- Self::NotFinalized(_) =>
- "an attempt to construct a Taproot tree from a builder containing incomplete branches",
- Self::HiddenParts(_) =>
- "an attempt to construct a Taproot tree from a builder containing hidden parts",
- })
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for IncompleteBuilderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::NotFinalized(_) | Self::HiddenParts(_) => None,
- }
- }
-}
-
-/// Error happening when [`TapTree`] is constructed from a [`NodeInfo`]
-/// having hidden branches.
-#[derive(Debug, Clone, PartialEq, Eq)]
-#[non_exhaustive]
-pub enum HiddenNodesError {
- /// Indicates an attempt to construct a Taproot tree from a builder containing hidden parts.
- HiddenParts(NodeInfo),
-}
-
-impl From<Infallible> for HiddenNodesError {
- fn from(never: Infallible) -> Self { match never {} }
-}
-
-impl HiddenNodesError {
- /// Converts error into the original incomplete [`NodeInfo`] instance.
- pub fn into_node_info(self) -> NodeInfo {
- match self {
- Self::HiddenParts(node_info) => node_info,
- }
- }
-}
-
-impl core::fmt::Display for HiddenNodesError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- f.write_str(match self {
- Self::HiddenParts(_) =>
- "an attempt to construct a Taproot tree from a node_info containing hidden parts",
- })
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for HiddenNodesError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::HiddenParts(_) => None,
- }
- }
-}
-
/// Taproot tree representing a complete binary tree without any hidden nodes.
///
/// This is in contrast to [`NodeInfo`], which allows hidden nodes.
@@ -1438,229 +1357,340 @@ impl<'de> serde::Deserialize<'de> for LeafVersion {
}
}
-/// Detailed error type for Taproot builder.
-#[derive(Debug, Clone, PartialEq, Eq)]
-#[non_exhaustive]
-pub enum TaprootBuilderError {
- /// Merkle tree depth must not be more than 128.
- InvalidMerkleTreeDepth(InvalidMerkleTreeDepthError),
- /// Nodes must be added specified in DFS walk order.
- NodeNotInDfsOrder,
- /// Two nodes at depth 0 are not allowed.
- OverCompleteTree,
- /// Called finalize on an empty tree.
- EmptyTree,
-}
+/// Error types for taproot.
+pub mod error {
+ use core::convert::Infallible;
+ use core::fmt;
-impl From<Infallible> for TaprootBuilderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ use internals::write_err;
-impl fmt::Display for TaprootBuilderError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Self::InvalidMerkleTreeDepth(ref e) => write_err!(f, "invalid Merkle tree depth"; e),
- Self::NodeNotInDfsOrder => {
- write!(f, "add_leaf/add_hidden must be called in DFS walk order",)
+ use super::{
+ NodeInfo, TaprootBuilder, TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_NODE_SIZE,
+ };
+ use crate::hex::DecodeVariableLengthBytesError;
+ use crate::key::ParseXOnlyPublicKeyError;
+
+ #[rustfmt::skip]
+ #[doc(inline)]
+ pub use crate::crypto::taproot::SigFromSliceError;
+
+ /// Error happening when [`TapTree`] is constructed from a [`TaprootBuilder`]
+ /// having hidden branches or not being finalized.
+ ///
+ /// [`TapTree`]: super::TapTree
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ #[non_exhaustive]
+ pub enum IncompleteBuilderError {
+ /// Indicates an attempt to construct a Taproot tree from a builder containing incomplete branches.
+ NotFinalized(TaprootBuilder),
+ /// Indicates an attempt to construct a Taproot tree from a builder containing hidden parts.
+ HiddenParts(TaprootBuilder),
+ }
+
+ impl IncompleteBuilderError {
+ /// Converts error into the original incomplete [`TaprootBuilder`] instance.
+ pub fn into_builder(self) -> TaprootBuilder {
+ match self {
+ Self::NotFinalized(builder) | Self::HiddenParts(builder) => builder,
}
- Self::OverCompleteTree => write!(
- f,
- "attempted to create a tree with two nodes at depth 0. There must\
- only be exactly one node at depth 0",
- ),
- Self::EmptyTree => {
- write!(f, "called finalize on an empty tree")
+ }
+ }
+
+ impl From<Infallible> for IncompleteBuilderError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
+ impl core::fmt::Display for IncompleteBuilderError {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ f.write_str(match self {
+ Self::NotFinalized(_) =>
+ "an attempt to construct a Taproot tree from a builder containing incomplete branches",
+ Self::HiddenParts(_) =>
+ "an attempt to construct a Taproot tree from a builder containing hidden parts",
+ })
+ }
+ }
+
+ #[cfg(feature = "std")]
+ impl std::error::Error for IncompleteBuilderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::NotFinalized(_) | Self::HiddenParts(_) => None,
}
}
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for TaprootBuilderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::InvalidMerkleTreeDepth(ref e) => Some(e),
- Self::NodeNotInDfsOrder | Self::OverCompleteTree | Self::EmptyTree => None,
+ /// Error happening when [`TapTree`] is constructed from a [`NodeInfo`]
+ /// having hidden branches.
+ ///
+ /// [`TapTree`]: super::TapTree
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ #[non_exhaustive]
+ pub enum HiddenNodesError {
+ /// Indicates an attempt to construct a Taproot tree from a builder containing hidden parts.
+ HiddenParts(NodeInfo),
+ }
+
+ impl From<Infallible> for HiddenNodesError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
+ impl HiddenNodesError {
+ /// Converts error into the original incomplete [`NodeInfo`] instance.
+ pub fn into_node_info(self) -> NodeInfo {
+ match self {
+ Self::HiddenParts(node_info) => node_info,
+ }
}
}
-}
-impl From<InvalidMerkleTreeDepthError> for TaprootBuilderError {
- fn from(e: InvalidMerkleTreeDepthError) -> Self { Self::InvalidMerkleTreeDepth(e) }
-}
+ impl core::fmt::Display for HiddenNodesError {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ f.write_str(match self {
+ Self::HiddenParts(_) =>
+ "an attempt to construct a Taproot tree from a node_info containing hidden parts",
+ })
+ }
+ }
-/// Detailed error type for Taproot utilities.
-#[derive(Debug, Clone, PartialEq, Eq)]
-#[non_exhaustive]
-#[allow(clippy::enum_variant_names)]
-pub enum TaprootError {
- /// Proof size must be a multiple of 32.
- InvalidMerkleBranchSize(InvalidMerkleBranchSizeError),
- /// Merkle tree depth must not be more than 128.
- InvalidMerkleTreeDepth(InvalidMerkleTreeDepthError),
- /// The last bit of tapleaf version must be zero.
- InvalidTaprootLeafVersion(InvalidTaprootLeafVersionError),
- /// Invalid control block size.
- InvalidControlBlockSize(InvalidControlBlockSizeError),
- /// Invalid Taproot internal key.
- InvalidInternalKey(ParseXOnlyPublicKeyError),
- /// Invalid control block hex
- InvalidControlBlockHex(DecodeVariableLengthBytesError),
-}
+ #[cfg(feature = "std")]
+ impl std::error::Error for HiddenNodesError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::HiddenParts(_) => None,
+ }
+ }
+ }
-impl From<Infallible> for TaprootError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ /// Detailed error type for Taproot builder.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ #[non_exhaustive]
+ pub enum TaprootBuilderError {
+ /// Merkle tree depth must not be more than 128.
+ InvalidMerkleTreeDepth(InvalidMerkleTreeDepthError),
+ /// Nodes must be added specified in DFS walk order.
+ NodeNotInDfsOrder,
+ /// Two nodes at depth 0 are not allowed.
+ OverCompleteTree,
+ /// Called finalize on an empty tree.
+ EmptyTree,
+ }
-impl fmt::Display for TaprootError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Self::InvalidMerkleBranchSize(ref e) => write_err!(f, "invalid Merkle branch size"; e),
- Self::InvalidMerkleTreeDepth(ref e) => write_err!(f, "invalid Merkle tree depth"; e),
- Self::InvalidTaprootLeafVersion(ref e) =>
- write_err!(f, "invalid Taproot leaf version"; e),
- Self::InvalidControlBlockSize(ref e) => write_err!(f, "invalid control block size"; e),
- Self::InvalidControlBlockHex(ref e) => write_err!(f, "invalid control block hex"; e),
- Self::InvalidInternalKey(ref e) => write_err!(f, "invalid internal x-only key"; e),
+ impl From<Infallible> for TaprootBuilderError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
+ impl fmt::Display for TaprootBuilderError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::InvalidMerkleTreeDepth(ref e) =>
+ write_err!(f, "invalid Merkle tree depth"; e),
+ Self::NodeNotInDfsOrder => {
+ write!(f, "add_leaf/add_hidden must be called in DFS walk order",)
+ }
+ Self::OverCompleteTree => write!(
+ f,
+ "attempted to create a tree with two nodes at depth 0. There must\
+ only be exactly one node at depth 0",
+ ),
+ Self::EmptyTree => {
+ write!(f, "called finalize on an empty tree")
+ }
+ }
}
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for TaprootError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::InvalidInternalKey(e) => Some(e),
- Self::InvalidTaprootLeafVersion(ref e) => Some(e),
- Self::InvalidMerkleTreeDepth(ref e) => Some(e),
- Self::InvalidControlBlockHex(ref e) => Some(e),
- Self::InvalidMerkleBranchSize(_) | Self::InvalidControlBlockSize(_) => None,
+ #[cfg(feature = "std")]
+ impl std::error::Error for TaprootBuilderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::InvalidMerkleTreeDepth(ref e) => Some(e),
+ Self::NodeNotInDfsOrder | Self::OverCompleteTree | Self::EmptyTree => None,
+ }
}
}
-}
-impl From<InvalidMerkleBranchSizeError> for TaprootError {
- fn from(e: InvalidMerkleBranchSizeError) -> Self { Self::InvalidMerkleBranchSize(e) }
-}
+ impl From<InvalidMerkleTreeDepthError> for TaprootBuilderError {
+ fn from(e: InvalidMerkleTreeDepthError) -> Self { Self::InvalidMerkleTreeDepth(e) }
+ }
+
+ /// Detailed error type for Taproot utilities.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ #[non_exhaustive]
+ #[allow(clippy::enum_variant_names)]
+ pub enum TaprootError {
+ /// Proof size must be a multiple of 32.
+ InvalidMerkleBranchSize(InvalidMerkleBranchSizeError),
+ /// Merkle tree depth must not be more than 128.
+ InvalidMerkleTreeDepth(InvalidMerkleTreeDepthError),
+ /// The last bit of tapleaf version must be zero.
+ InvalidTaprootLeafVersion(InvalidTaprootLeafVersionError),
+ /// Invalid control block size.
+ InvalidControlBlockSize(InvalidControlBlockSizeError),
+ /// Invalid Taproot internal key.
+ InvalidInternalKey(ParseXOnlyPublicKeyError),
+ /// Invalid control block hex
+ InvalidControlBlockHex(DecodeVariableLengthBytesError),
+ }
+
+ impl From<Infallible> for TaprootError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
+ impl fmt::Display for TaprootError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::InvalidMerkleBranchSize(ref e) =>
+ write_err!(f, "invalid Merkle branch size"; e),
+ Self::InvalidMerkleTreeDepth(ref e) =>
+ write_err!(f, "invalid Merkle tree depth"; e),
+ Self::InvalidTaprootLeafVersion(ref e) =>
+ write_err!(f, "invalid Taproot leaf version"; e),
+ Self::InvalidControlBlockSize(ref e) =>
+ write_err!(f, "invalid control block size"; e),
+ Self::InvalidControlBlockHex(ref e) =>
+ write_err!(f, "invalid control block hex"; e),
+ Self::InvalidInternalKey(ref e) => write_err!(f, "invalid internal x-only key"; e),
+ }
+ }
+ }
-impl From<InvalidMerkleTreeDepthError> for TaprootError {
- fn from(e: InvalidMerkleTreeDepthError) -> Self { Self::InvalidMerkleTreeDepth(e) }
-}
+ #[cfg(feature = "std")]
+ impl std::error::Error for TaprootError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::InvalidInternalKey(e) => Some(e),
+ Self::InvalidTaprootLeafVersion(ref e) => Some(e),
+ Self::InvalidMerkleTreeDepth(ref e) => Some(e),
+ Self::InvalidControlBlockHex(ref e) => Some(e),
+ Self::InvalidMerkleBranchSize(_) | Self::InvalidControlBlockSize(_) => None,
+ }
+ }
+ }
-impl From<InvalidTaprootLeafVersionError> for TaprootError {
- fn from(e: InvalidTaprootLeafVersionError) -> Self { Self::InvalidTaprootLeafVersion(e) }
-}
+ impl From<InvalidMerkleBranchSizeError> for TaprootError {
+ fn from(e: InvalidMerkleBranchSizeError) -> Self { Self::InvalidMerkleBranchSize(e) }
+ }
-impl From<InvalidControlBlockSizeError> for TaprootError {
- fn from(e: InvalidControlBlockSizeError) -> Self { Self::InvalidControlBlockSize(e) }
-}
+ impl From<InvalidMerkleTreeDepthError> for TaprootError {
+ fn from(e: InvalidMerkleTreeDepthError) -> Self { Self::InvalidMerkleTreeDepth(e) }
+ }
-/// Proof size must be a multiple of 32.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct InvalidMerkleBranchSizeError(usize);
+ impl From<InvalidTaprootLeafVersionError> for TaprootError {
+ fn from(e: InvalidTaprootLeafVersionError) -> Self { Self::InvalidTaprootLeafVersion(e) }
+ }
-impl InvalidMerkleBranchSizeError {
- /// Accessor for the invalid merkle branch size.
- pub fn invalid_merkle_branch_size(&self) -> usize { self.0 }
-}
+ impl From<InvalidControlBlockSizeError> for TaprootError {
+ fn from(e: InvalidControlBlockSizeError) -> Self { Self::InvalidControlBlockSize(e) }
+ }
-impl From<Infallible> for InvalidMerkleBranchSizeError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ /// Proof size must be a multiple of 32.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct InvalidMerkleBranchSizeError(pub(super) usize);
-impl fmt::Display for InvalidMerkleBranchSizeError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "Merkle branch size({}) must be a multiple of {}",
- self.0, TAPROOT_CONTROL_NODE_SIZE
- )
+ impl InvalidMerkleBranchSizeError {
+ /// Accessor for the invalid merkle branch size.
+ pub fn invalid_merkle_branch_size(&self) -> usize { self.0 }
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for InvalidMerkleBranchSizeError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
-}
+ impl From<Infallible> for InvalidMerkleBranchSizeError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
-/// Merkle tree depth must not be more than 128.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct InvalidMerkleTreeDepthError(usize);
+ impl fmt::Display for InvalidMerkleBranchSizeError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(
+ f,
+ "Merkle branch size({}) must be a multiple of {}",
+ self.0, TAPROOT_CONTROL_NODE_SIZE
+ )
+ }
+ }
-impl InvalidMerkleTreeDepthError {
- /// Accessor for the invalid merkle tree depth.
- pub fn invalid_merkle_tree_depth(&self) -> usize { self.0 }
-}
+ #[cfg(feature = "std")]
+ impl std::error::Error for InvalidMerkleBranchSizeError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+ }
-impl From<Infallible> for InvalidMerkleTreeDepthError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ /// Merkle tree depth must not be more than 128.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct InvalidMerkleTreeDepthError(pub(super) usize);
-impl fmt::Display for InvalidMerkleTreeDepthError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "Merkle tree depth({}) must be less than {}",
- self.0, TAPROOT_CONTROL_MAX_NODE_COUNT
- )
+ impl InvalidMerkleTreeDepthError {
+ /// Accessor for the invalid merkle tree depth.
+ pub fn invalid_merkle_tree_depth(&self) -> usize { self.0 }
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for InvalidMerkleTreeDepthError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
-}
+ impl From<Infallible> for InvalidMerkleTreeDepthError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
-/// The last bit of tapleaf version must be zero.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct InvalidTaprootLeafVersionError(u8);
+ impl fmt::Display for InvalidMerkleTreeDepthError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(
+ f,
+ "Merkle tree depth({}) must be less than {}",
+ self.0, TAPROOT_CONTROL_MAX_NODE_COUNT
+ )
+ }
+ }
-impl InvalidTaprootLeafVersionError {
- /// Accessor for the invalid leaf version.
- pub fn invalid_leaf_version(&self) -> u8 { self.0 }
-}
+ #[cfg(feature = "std")]
+ impl std::error::Error for InvalidMerkleTreeDepthError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+ }
-impl From<Infallible> for InvalidTaprootLeafVersionError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ /// The last bit of tapleaf version must be zero.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct InvalidTaprootLeafVersionError(pub(super) u8);
-impl fmt::Display for InvalidTaprootLeafVersionError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "leaf version({}) must have the least significant bit 0", self.0)
+ impl InvalidTaprootLeafVersionError {
+ /// Accessor for the invalid leaf version.
+ pub fn invalid_leaf_version(&self) -> u8 { self.0 }
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for InvalidTaprootLeafVersionError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
-}
+ impl From<Infallible> for InvalidTaprootLeafVersionError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
-/// Invalid control block size.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct InvalidControlBlockSizeError(usize);
+ impl fmt::Display for InvalidTaprootLeafVersionError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "leaf version({}) must have the least significant bit 0", self.0)
+ }
+ }
-impl InvalidControlBlockSizeError {
- /// Accessor for the invalid control block size.
- pub fn invalid_control_block_size(&self) -> usize { self.0 }
-}
+ #[cfg(feature = "std")]
+ impl std::error::Error for InvalidTaprootLeafVersionError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+ }
-impl From<Infallible> for InvalidControlBlockSizeError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ /// Invalid control block size.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct InvalidControlBlockSizeError(pub(super) usize);
-impl fmt::Display for InvalidControlBlockSizeError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "Control Block size({}) must be of the form 33 + 32*m where 0 <= m <= {} ",
- self.0, TAPROOT_CONTROL_MAX_NODE_COUNT
- )
+ impl InvalidControlBlockSizeError {
+ /// Accessor for the invalid control block size.
+ pub fn invalid_control_block_size(&self) -> usize { self.0 }
+ }
+
+ impl From<Infallible> for InvalidControlBlockSizeError {
+ fn from(never: Infallible) -> Self { match never {} }
}
-}
-#[cfg(feature = "std")]
-impl std::error::Error for InvalidControlBlockSizeError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+ impl fmt::Display for InvalidControlBlockSizeError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(
+ f,
+ "Control Block size({}) must be of the form 33 + 32*m where 0 <= m <= {} ",
+ self.0, TAPROOT_CONTROL_MAX_NODE_COUNT
+ )
+ }
+ }
+
+ #[cfg(feature = "std")]
+ impl std::error::Error for InvalidControlBlockSizeError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+ }
}
#[cfg(feature = "arbitrary")]
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.