pub struct BlockHash(/* private fields */);
Expand description
A transaction identifier (BlockHash) represented as a 32-byte hash.
BlockHash
is a specialized wrapper around a 32-byte array representing a block’s
unique identifier in the Zcash blockchain.
§Zcash Concept Relation
In Zcash (and Bitcoin-derived cryptocurrencies), transaction IDs are critical identifiers used to reference transactions throughout the protocol:
- In transaction inputs to reference previous outputs being spent
- In block data structures to identify included transactions
- In client APIs and explorers to look up transaction details
Block hashes are displayed in reverse byte order by convention (to match Bitcoin’s historical display format), while stored internally in little-endian order.
§Data Preservation
The BlockHash
type preserves the exact 32-byte transaction identifier as found in wallet
data files, ensuring that transaction references maintain their cryptographic integrity
during wallet migrations.
§Examples
// Create a BlockHash from a byte array
let tx_bytes = [0u8; 32];
let txid = BlockHash::from_bytes(tx_bytes);
// Display the BlockHash in the conventional reversed format used by explorers
// Note: this would display as a string of 64 hex characters (zeros in this example)
println!("Block Hash: {}", txid);
Implementations§
Source§impl BlockHash
impl BlockHash
Sourcepub fn from_bytes(bytes: [u8; 32]) -> Self
pub fn from_bytes(bytes: [u8; 32]) -> Self
Creates a new BlockHash
from a 32-byte array.
This is the primary constructor for BlockHash
when you have the raw transaction
hash available.
§Examples
// Usually this would be a real transaction hash
let bytes = [0u8; 32];
let txid = BlockHash::from_bytes(bytes);
Sourcepub fn from_hex(hex: &str) -> Result<Self, HexParseError>
pub fn from_hex(hex: &str) -> Result<Self, HexParseError>
Parses a BlockHash
from a canonically-encoded (byte-reversed) hexadecimal string.
§Examples
let hex = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
let block_hash = BlockHash::from_hex(hex).unwrap();
assert_eq!(block_hash.as_ref()[0], 0x6f);
assert_eq!(format!("{}", block_hash), hex);
Sourcepub fn read<R: Read>(reader: R) -> Result<Self>
pub fn read<R: Read>(reader: R) -> Result<Self>
Reads a BlockHash
from any source implementing the Read
trait.
This method is useful when reading transaction IDs directly from files or other byte streams.
§Errors
Returns an IO error if reading fails or if there aren’t enough bytes available.
§Examples
// Create a cursor with 32 bytes
let data = vec![0u8; 32];
let mut cursor = Cursor::new(data);
// Read a BlockHash from the cursor
let txid = BlockHash::read(&mut cursor)?;
Sourcepub fn write<W: Write>(&self, writer: W) -> Result<()>
pub fn write<W: Write>(&self, writer: W) -> Result<()>
Writes a BlockHash
to any destination implementing the Write
trait.
This method is useful when serializing transaction IDs to files or other byte streams.
§Errors
Returns an IO error if writing fails.
§Examples
let txid = BlockHash::from_bytes([0u8; 32]);
let mut buffer = Vec::new();
// Write the BlockHash to the buffer
txid.write(&mut buffer)?;
// The buffer now contains the 32-byte transaction ID
assert_eq!(buffer.len(), 32);
Trait Implementations§
Source§impl Ord for BlockHash
impl Ord for BlockHash
Source§impl PartialOrd for BlockHash
impl PartialOrd for BlockHash
impl Copy for BlockHash
impl Eq for BlockHash
impl StructuralPartialEq for BlockHash
Auto Trait Implementations§
impl Freeze for BlockHash
impl RefUnwindSafe for BlockHash
impl Send for BlockHash
impl Sync for BlockHash
impl Unpin for BlockHash
impl UnwindSafe for BlockHash
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> EnvelopeEncodable for T
impl<T> EnvelopeEncodable for T
Source§fn into_envelope(self) -> Envelope
fn into_envelope(self) -> Envelope
Converts the value into an envelope by using its Into<Envelope>
implementation.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more