diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index 8646c016f..a6dd5ab4a 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -113,6 +113,7 @@ dependencies = [ "bitcoin-internals", "bitcoin-io", "bitcoin-units", + "bitcoin_hashes", "mutagen", "ordered", "serde", diff --git a/Cargo-recent.lock b/Cargo-recent.lock index af67f9316..2be0c9915 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -112,6 +112,7 @@ dependencies = [ "bitcoin-internals", "bitcoin-io", "bitcoin-units", + "bitcoin_hashes", "mutagen", "ordered", "serde", diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 7f2a9b94f..6fbfc953d 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -35,31 +35,9 @@ use crate::{Amount, FeeRate, SignedAmount, VarInt}; #[doc(inline)] pub use primitives::transaction::*; -hashes::hash_newtype! { - /// A bitcoin transaction hash/transaction ID. - /// - /// For compatibility with the existing Bitcoin infrastructure and historical and current - /// versions of the Bitcoin Core software itself, this and other [`sha256d::Hash`] types, are - /// serialized in reverse byte order when converted to a hex string via [`std::fmt::Display`] - /// trait operations. - /// - /// See [`hashes::Hash::DISPLAY_BACKWARD`] for more details. - pub struct Txid(sha256d::Hash); - - /// A bitcoin witness transaction ID. - pub struct Wtxid(sha256d::Hash); -} impl_hashencode!(Txid); impl_hashencode!(Wtxid); -impl Txid { - /// The `Txid` used in a coinbase prevout. - /// - /// This is used as the "txid" of the dummy input of a coinbase transaction. This is not a real - /// TXID and should not be used in any other contexts. See [`OutPoint::COINBASE_PREVOUT`]. - pub const COINBASE_PREVOUT: Self = Self::from_byte_array([0; 32]); -} - crate::internal_macros::define_extension_trait! { /// Extension functionality for the [`Txid`] type. pub trait TxidExt impl for Txid { @@ -69,15 +47,6 @@ crate::internal_macros::define_extension_trait! { } } -impl Wtxid { - /// The `Wtxid` of a coinbase transaction. - /// - /// This is used as the wTXID for the coinbase transaction when constructing blocks (in the - /// witness commitment tree) since the coinbase transaction contains a commitment to all - /// transactions' wTXIDs but naturally cannot commit to its own. - pub const COINBASE: Self = Self::from_byte_array([0; 32]); -} - crate::internal_macros::define_extension_trait! { /// Extension functionality for the [`Wtxid`] type. pub trait WtxidExt impl for Wtxid { diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 9a293fdaf..64329f9d1 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -16,11 +16,12 @@ exclude = ["tests", "contrib"] [features] default = ["std"] -std = ["alloc", "internals/std", "io/std", "units/std"] -alloc = ["internals/alloc", "io/alloc", "units/alloc"] -serde = ["dep:serde", "internals/serde", "units/serde", "alloc"] +std = ["alloc", "hashes/std", "internals/std", "io/std", "units/std"] +alloc = ["hashes/alloc", "internals/alloc", "io/alloc", "units/alloc"] +serde = ["dep:serde", "hashes/serde", "internals/serde", "units/serde", "alloc"] [dependencies] +hashes = { package = "bitcoin_hashes", version = "0.14.0", default-features = false, features = ["bitcoin-io"] } internals = { package = "bitcoin-internals", version = "0.3.0" } io = { package = "bitcoin-io", version = "0.1.1", default-features = false } units = { package = "bitcoin-units", version = "0.1.0", default-features = false } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 0383ffca9..e6743bc1e 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -42,7 +42,11 @@ pub use units::*; #[cfg(feature = "alloc")] pub use self::locktime::{absolute, relative}; #[doc(inline)] -pub use self::{pow::CompactTarget, sequence::Sequence}; +pub use self::{ + pow::CompactTarget, + sequence::Sequence, + transaction::{Txid, Wtxid}, +}; #[rustfmt::skip] #[allow(unused_imports)] diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs index 7b0701002..6d705e724 100644 --- a/primitives/src/transaction.rs +++ b/primitives/src/transaction.rs @@ -12,6 +12,40 @@ use core::fmt; +use hashes::sha256d; + +hashes::hash_newtype! { + /// A bitcoin transaction hash/transaction ID. + /// + /// For compatibility with the existing Bitcoin infrastructure and historical and current + /// versions of the Bitcoin Core software itself, this and other [`sha256d::Hash`] types, are + /// serialized in reverse byte order when converted to a hex string via [`std::fmt::Display`] + /// trait operations. + /// + /// See [`hashes::Hash::DISPLAY_BACKWARD`] for more details. + pub struct Txid(sha256d::Hash); + + /// A bitcoin witness transaction ID. + pub struct Wtxid(sha256d::Hash); +} + +impl Txid { + /// The `Txid` used in a coinbase prevout. + /// + /// This is used as the "txid" of the dummy input of a coinbase transaction. This is not a real + /// TXID and should not be used in any other contexts. See `OutPoint::COINBASE_PREVOUT`. + pub const COINBASE_PREVOUT: Self = Self::from_byte_array([0; 32]); +} + +impl Wtxid { + /// The `Wtxid` of a coinbase transaction. + /// + /// This is used as the wTXID for the coinbase transaction when constructing blocks (in the + /// witness commitment tree) since the coinbase transaction contains a commitment to all + /// transactions' wTXIDs but naturally cannot commit to its own. + pub const COINBASE: Self = Self::from_byte_array([0; 32]); +} + /// The transaction version. /// /// Currently, as specified by [BIP-68], only version 1 and 2 are considered standard.