Skip to content

Commit

Permalink
Fully encapsulate bitcoinconsensus
Browse files Browse the repository at this point in the history
The `bitcoinconsensus` crate is not fully under our control because it
exposes code from Core, so we cannot guarantee its stability across
versions. To make our semver compliance easier we can fully encapsulate
the `bitcoinconsensus` crate so it does not appear in our public API.
However, it is useful to have the crate itself exported, here we add an
"unstable" feature and only publicly export the `bitcoinconsensus` crate
if the "unstable" feature is enabled.
  • Loading branch information
tcharding committed Dec 13, 2023
1 parent 6fe073b commit 43b1ed1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions bitcoin/src/consensus/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ pub fn verify_script_with_flags<F: Into<u32>>(
spending_tx: &[u8],
flags: F,
) -> Result<(), BitcoinconsensusError> {
Ok(bitcoinconsensus::verify_with_flags(
bitcoinconsensus::verify_with_flags(
script.as_bytes(),
amount.to_sat(),
spending_tx,
index,
flags.into(),
)?)
).map_err(BitcoinconsensusError)
}

/// Verifies that this transaction is able to spend its inputs.
Expand Down Expand Up @@ -198,10 +198,6 @@ impl std::error::Error for BitcoinconsensusError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
}

impl From<bitcoinconsensus::Error> for BitcoinconsensusError {
fn from(e: bitcoinconsensus::Error) -> Self { Self(e) }
}

/// An error during transaction validation.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ pub extern crate base64;
/// Encodes and decodes the Bech32 forrmat.
pub extern crate bech32;

#[cfg(feature = "bitcoinconsensus")]
/// Bitcoin's libbitcoinconsensus with Rust binding.
pub extern crate bitcoinconsensus;
#[cfg(feature = "bitcoinconsensus")]
extern crate bitcoinconsensus;

/// Rust implementation of cryptographic hash function algorithems.
pub extern crate hashes;
Expand Down

0 comments on commit 43b1ed1

Please sign in to comment.