Move the transaction hash types over to primitives
Move the `Txid` and `Wtxid` hash wrapper types over to `primitives`. This introduces to `primitves` an unconditional dependency on `hashes`.
This commit is contained in:
parent
7e454d756d
commit
0403e52ce3
|
@ -113,6 +113,7 @@ dependencies = [
|
|||
"bitcoin-internals",
|
||||
"bitcoin-io",
|
||||
"bitcoin-units",
|
||||
"bitcoin_hashes",
|
||||
"mutagen",
|
||||
"ordered",
|
||||
"serde",
|
||||
|
|
|
@ -112,6 +112,7 @@ dependencies = [
|
|||
"bitcoin-internals",
|
||||
"bitcoin-io",
|
||||
"bitcoin-units",
|
||||
"bitcoin_hashes",
|
||||
"mutagen",
|
||||
"ordered",
|
||||
"serde",
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue