BitcoinHash

Trait BitcoinHash 

Source
pub trait BitcoinHash:
    Copy
    + Clone
    + PartialEq
    + Eq
    + PartialOrd
    + Ord
    + Hash
    + Debug
    + Display
    + LowerHex
    + Index<RangeFull, Output = [u8], Output = [u8], Output = [u8], Output = [u8], Output = u8>
    + Index<RangeFrom<usize>>
    + Index<RangeTo<usize>>
    + Index<Range<usize>>
    + Index<usize>
    + Borrow<[u8]> {
    type Engine: HashEngine;
    type Bytes: FromHex + Copy;

    const LEN: usize;
    const DISPLAY_BACKWARD: bool = false;

    // Required methods
    fn from_engine(e: Self::Engine) -> Self;
    fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>;
    fn to_byte_array(self) -> Self::Bytes;
    fn as_byte_array(&self) -> &Self::Bytes;
    fn from_byte_array(bytes: Self::Bytes) -> Self;
    fn all_zeros() -> Self;

    // Provided methods
    fn engine() -> Self::Engine { ... }
    fn hash(data: &[u8]) -> Self { ... }
    fn hash_byte_chunks<B, I>(byte_slices: I) -> Self
       where B: AsRef<[u8]>,
             I: IntoIterator<Item = B> { ... }
}
Expand description

Trait which applies to hashes of all types.

Required Associated Constants§

Source

const LEN: usize

Length of the hash, in bytes.

Provided Associated Constants§

Source

const DISPLAY_BACKWARD: bool = false

Flag indicating whether user-visible serializations of this hash should be backward. For some reason Satoshi decided this should be true for Sha256dHash, so here we are.

Required Associated Types§

Source

type Engine: HashEngine

A hashing engine which bytes can be serialized into. It is expected to implement the io::Write trait, and to never return errors under any conditions.

Source

type Bytes: FromHex + Copy

The byte array that represents the hash internally.

Required Methods§

Source

fn from_engine(e: Self::Engine) -> Self

Produces a hash from the current state of a given engine.

Source

fn from_slice(sl: &[u8]) -> Result<Self, FromSliceError>

Copies a byte slice into a hash object.

Source

fn to_byte_array(self) -> Self::Bytes

Returns the underlying byte array.

Source

fn as_byte_array(&self) -> &Self::Bytes

Returns a reference to the underlying byte array.

Source

fn from_byte_array(bytes: Self::Bytes) -> Self

Constructs a hash from the underlying byte array.

Source

fn all_zeros() -> Self

Returns an all zero hash.

An all zeros hash is a made up construct because there is not a known input that can create it, however it is used in various places in Bitcoin e.g., the Bitcoin genesis block’s previous blockhash and the coinbase transaction’s outpoint txid.

Provided Methods§

Source

fn engine() -> Self::Engine

Constructs a new engine.

Source

fn hash(data: &[u8]) -> Self

Hashes some bytes.

Source

fn hash_byte_chunks<B, I>(byte_slices: I) -> Self
where B: AsRef<[u8]>, I: IntoIterator<Item = B>,

Hashes all the byte slices retrieved from the iterator together.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Hash for XKeyIdentifier

Source§

const LEN: usize = <hash160::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <hash160::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <XKeyIdentifier as Hash>::Engine

Source§

fn from_engine(e: <XKeyIdentifier as Hash>::Engine) -> XKeyIdentifier

Source§

fn from_slice(sl: &[u8]) -> Result<XKeyIdentifier, FromSliceError>

Source§

fn from_byte_array(bytes: <XKeyIdentifier as Hash>::Bytes) -> XKeyIdentifier

Source§

fn to_byte_array(self) -> <XKeyIdentifier as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<XKeyIdentifier as Hash>::Bytes

Source§

fn all_zeros() -> XKeyIdentifier

Source§

impl Hash for FilterHash

Source§

const LEN: usize = <sha256d::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <sha256d::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <FilterHash as Hash>::Engine

Source§

fn from_engine(e: <FilterHash as Hash>::Engine) -> FilterHash

Source§

fn from_slice(sl: &[u8]) -> Result<FilterHash, FromSliceError>

Source§

fn from_byte_array(bytes: <FilterHash as Hash>::Bytes) -> FilterHash

Source§

fn to_byte_array(self) -> <FilterHash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<FilterHash as Hash>::Bytes

Source§

fn all_zeros() -> FilterHash

Source§

impl Hash for FilterHeader

Source§

const LEN: usize = <sha256d::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <sha256d::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <FilterHeader as Hash>::Engine

Source§

fn from_engine(e: <FilterHeader as Hash>::Engine) -> FilterHeader

Source§

fn from_slice(sl: &[u8]) -> Result<FilterHeader, FromSliceError>

Source§

fn from_byte_array(bytes: <FilterHeader as Hash>::Bytes) -> FilterHeader

Source§

fn to_byte_array(self) -> <FilterHeader as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<FilterHeader as Hash>::Bytes

Source§

fn all_zeros() -> FilterHeader

Source§

impl Hash for BlockHash

Source§

const LEN: usize = <sha256d::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <sha256d::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <BlockHash as Hash>::Engine

Source§

fn from_engine(e: <BlockHash as Hash>::Engine) -> BlockHash

Source§

fn from_slice(sl: &[u8]) -> Result<BlockHash, FromSliceError>

Source§

fn from_byte_array(bytes: <BlockHash as Hash>::Bytes) -> BlockHash

Source§

fn to_byte_array(self) -> <BlockHash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<BlockHash as Hash>::Bytes

Source§

fn all_zeros() -> BlockHash

Source§

impl Hash for TxMerkleNode

Source§

const LEN: usize = <sha256d::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <sha256d::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <TxMerkleNode as Hash>::Engine

Source§

fn from_engine(e: <TxMerkleNode as Hash>::Engine) -> TxMerkleNode

Source§

fn from_slice(sl: &[u8]) -> Result<TxMerkleNode, FromSliceError>

Source§

fn from_byte_array(bytes: <TxMerkleNode as Hash>::Bytes) -> TxMerkleNode

Source§

fn to_byte_array(self) -> <TxMerkleNode as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<TxMerkleNode as Hash>::Bytes

Source§

fn all_zeros() -> TxMerkleNode

Source§

impl Hash for WitnessCommitment

Source§

impl Hash for WitnessMerkleNode

Source§

impl Hash for ScriptHash

Source§

const LEN: usize = <hash160::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <hash160::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <ScriptHash as Hash>::Engine

Source§

fn from_engine(e: <ScriptHash as Hash>::Engine) -> ScriptHash

Source§

fn from_slice(sl: &[u8]) -> Result<ScriptHash, FromSliceError>

Source§

fn from_byte_array(bytes: <ScriptHash as Hash>::Bytes) -> ScriptHash

Source§

fn to_byte_array(self) -> <ScriptHash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<ScriptHash as Hash>::Bytes

Source§

fn all_zeros() -> ScriptHash

Source§

impl Hash for WScriptHash

Source§

const LEN: usize = <sha256::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <sha256::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <WScriptHash as Hash>::Engine

Source§

fn from_engine(e: <WScriptHash as Hash>::Engine) -> WScriptHash

Source§

fn from_slice(sl: &[u8]) -> Result<WScriptHash, FromSliceError>

Source§

fn from_byte_array(bytes: <WScriptHash as Hash>::Bytes) -> WScriptHash

Source§

fn to_byte_array(self) -> <WScriptHash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<WScriptHash as Hash>::Bytes

Source§

fn all_zeros() -> WScriptHash

Source§

impl Hash for Txid

Source§

const LEN: usize = <sha256d::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <sha256d::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <Txid as Hash>::Engine

Source§

fn from_engine(e: <Txid as Hash>::Engine) -> Txid

Source§

fn from_slice(sl: &[u8]) -> Result<Txid, FromSliceError>

Source§

fn from_byte_array(bytes: <Txid as Hash>::Bytes) -> Txid

Source§

fn to_byte_array(self) -> <Txid as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<Txid as Hash>::Bytes

Source§

fn all_zeros() -> Txid

Source§

impl Hash for Wtxid

Source§

const LEN: usize = <sha256d::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <sha256d::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <Wtxid as Hash>::Engine

Source§

fn from_engine(e: <Wtxid as Hash>::Engine) -> Wtxid

Source§

fn from_slice(sl: &[u8]) -> Result<Wtxid, FromSliceError>

Source§

fn from_byte_array(bytes: <Wtxid as Hash>::Bytes) -> Wtxid

Source§

fn to_byte_array(self) -> <Wtxid as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<Wtxid as Hash>::Bytes

Source§

fn all_zeros() -> Wtxid

Source§

impl Hash for PubkeyHash

Source§

const LEN: usize = <hash160::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <hash160::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <PubkeyHash as Hash>::Engine

Source§

fn from_engine(e: <PubkeyHash as Hash>::Engine) -> PubkeyHash

Source§

fn from_slice(sl: &[u8]) -> Result<PubkeyHash, FromSliceError>

Source§

fn from_byte_array(bytes: <PubkeyHash as Hash>::Bytes) -> PubkeyHash

Source§

fn to_byte_array(self) -> <PubkeyHash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<PubkeyHash as Hash>::Bytes

Source§

fn all_zeros() -> PubkeyHash

Source§

impl Hash for WPubkeyHash

Source§

const LEN: usize = <hash160::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <hash160::Hash as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <WPubkeyHash as Hash>::Engine

Source§

fn from_engine(e: <WPubkeyHash as Hash>::Engine) -> WPubkeyHash

Source§

fn from_slice(sl: &[u8]) -> Result<WPubkeyHash, FromSliceError>

Source§

fn from_byte_array(bytes: <WPubkeyHash as Hash>::Bytes) -> WPubkeyHash

Source§

fn to_byte_array(self) -> <WPubkeyHash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<WPubkeyHash as Hash>::Bytes

Source§

fn all_zeros() -> WPubkeyHash

Source§

impl Hash for LegacySighash

Source§

impl Hash for SegwitV0Sighash

Source§

impl Hash for TapSighash

Source§

const LEN: usize = <::bitcoin_hashes::sha256t::Hash<TapSighashTag> as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = { false }

Source§

type Engine = <Hash<TapSighashTag> as Hash>::Engine

Source§

type Bytes = <Hash<TapSighashTag> as Hash>::Bytes

Source§

fn engine() -> <TapSighash as Hash>::Engine

Source§

fn from_engine(e: <TapSighash as Hash>::Engine) -> TapSighash

Source§

fn from_slice(sl: &[u8]) -> Result<TapSighash, FromSliceError>

Source§

fn from_byte_array(bytes: <TapSighash as Hash>::Bytes) -> TapSighash

Source§

fn to_byte_array(self) -> <TapSighash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<TapSighash as Hash>::Bytes

Source§

fn all_zeros() -> TapSighash

Source§

impl Hash for TapLeafHash

Source§

impl Hash for TapNodeHash

Source§

impl Hash for TapTweakHash

Source§

impl Hash for Hash

Source§

const LEN: usize = <sha256d::Hash as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = { false }

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

fn engine() -> <Hash as Hash>::Engine

Source§

fn from_engine(e: <Hash as Hash>::Engine) -> Hash

Source§

fn from_slice(sl: &[u8]) -> Result<Hash, FromSliceError>

Source§

fn from_byte_array(bytes: <Hash as Hash>::Bytes) -> Hash

Source§

fn to_byte_array(self) -> <Hash as Hash>::Bytes

Source§

fn as_byte_array(&self) -> &<Hash as Hash>::Bytes

Source§

fn all_zeros() -> Hash

Implementors§

Source§

impl Hash for bitcoin_hashes::hash160::Hash

Source§

impl Hash for bitcoin_hashes::ripemd160::Hash

Source§

impl Hash for bitcoin_hashes::sha1::Hash

Source§

impl Hash for bitcoin_hashes::sha256::Hash

Source§

impl Hash for bitcoin_hashes::sha256d::Hash

Source§

impl Hash for bitcoin_hashes::sha384::Hash

Source§

impl Hash for bitcoin_hashes::sha512::Hash

Source§

impl Hash for bitcoin_hashes::sha512_256::Hash

Source§

impl Hash for bitcoin_hashes::siphash24::Hash

Source§

impl Hash for TransactionId

Source§

const LEN: usize = <Sha256 as ::bitcoin_hashes::Hash>::LEN

Source§

const DISPLAY_BACKWARD: bool = <Sha256 as ::bitcoin_hashes::Hash>::DISPLAY_BACKWARD

Source§

type Engine = <Hash as Hash>::Engine

Source§

type Bytes = <Hash as Hash>::Bytes

Source§

impl<T> Hash for Hmac<T>
where T: Hash,

Source§

const LEN: usize = T::LEN

Source§

type Engine = HmacEngine<T>

Source§

type Bytes = <T as Hash>::Bytes

Source§

impl<T> Hash for bitcoin_hashes::sha256t::Hash<T>
where T: Tag,