Skip to main content

bitcoin_primitives/hash_types/
txid.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! The `Txid` type.
4//!
5//! In order to print and parse txids enable the "hex" feature.
6
7#[cfg(feature = "hex")]
8use core::{fmt, str};
9
10#[cfg(feature = "arbitrary")]
11use arbitrary::{Arbitrary, Unstructured};
12use hashes::sha256d;
13
14#[cfg(doc)]
15use crate::OutPoint;
16
17/// A bitcoin transaction hash/transaction ID.
18///
19/// For compatibility with the existing Bitcoin infrastructure and historical and current
20/// versions of the Bitcoin Core software itself, this and other [`sha256d::Hash`] types, are
21/// serialized in reverse byte order when converted to a hex string via [`std::fmt::Display`]
22/// trait operations.
23#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
24pub struct Txid(sha256d::Hash);
25
26super::impl_debug!(Txid);
27
28impl Txid {
29    /// The `Txid` used in a coinbase prevout.
30    ///
31    /// This is used as the "txid" of the dummy input of a coinbase transaction. This is not a real
32    /// TXID and should not be used in any other contexts. See [`OutPoint::COINBASE_PREVOUT`].
33    pub const COINBASE_PREVOUT: Self = Self::from_byte_array([0; 32]);
34}
35
36// The new hash wrapper type.
37type HashType = Txid;
38// The inner hash type from `hashes`.
39type Inner = sha256d::Hash;
40
41include!("./generic.rs");