Fully encapsulate bitcoinconsensus

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.
This commit is contained in:
Tobin C. Harding 2023-12-12 08:12:39 +11:00
parent 6fe073b324
commit 43b1ed1b86
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 4 additions and 8 deletions

View File

@ -51,13 +51,13 @@ pub fn verify_script_with_flags<F: Into<u32>>(
spending_tx: &[u8], spending_tx: &[u8],
flags: F, flags: F,
) -> Result<(), BitcoinconsensusError> { ) -> Result<(), BitcoinconsensusError> {
Ok(bitcoinconsensus::verify_with_flags( bitcoinconsensus::verify_with_flags(
script.as_bytes(), script.as_bytes(),
amount.to_sat(), amount.to_sat(),
spending_tx, spending_tx,
index, index,
flags.into(), flags.into(),
)?) ).map_err(BitcoinconsensusError)
} }
/// Verifies that this transaction is able to spend its inputs. /// Verifies that this transaction is able to spend its inputs.
@ -198,10 +198,6 @@ impl std::error::Error for BitcoinconsensusError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None } 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. /// An error during transaction validation.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive] #[non_exhaustive]

View File

@ -59,9 +59,9 @@ pub extern crate base64;
/// Encodes and decodes the Bech32 forrmat. /// Encodes and decodes the Bech32 forrmat.
pub extern crate bech32; pub extern crate bech32;
#[cfg(feature = "bitcoinconsensus")]
/// Bitcoin's libbitcoinconsensus with Rust binding. /// Bitcoin's libbitcoinconsensus with Rust binding.
pub extern crate bitcoinconsensus; #[cfg(feature = "bitcoinconsensus")]
extern crate bitcoinconsensus;
/// Rust implementation of cryptographic hash function algorithems. /// Rust implementation of cryptographic hash function algorithems.
pub extern crate hashes; pub extern crate hashes;