pub struct TxId(/* private fields */);
Expand description
A transaction identifier (TxId) represented as a 32-byte hash.
TxId
is a specialized wrapper around a 32-byte array representing a transaction’s
unique identifier in the Zcash blockchain. Transaction IDs are double-SHA256 hashes
of the transaction data (with specific rules for what parts are included in the hash).
§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
Transaction IDs 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 TxId
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 TxId from a byte array
let tx_bytes = [0u8; 32];
let txid = TxId::from_bytes(tx_bytes);
// Display the TxId in the conventional reversed format used by explorers
// Note: this would display as a string of 64 hex characters (zeros in this example)
println!("Transaction ID: {}", txid);
Implementations§
Source§impl TxId
impl TxId
Sourcepub fn from_bytes(bytes: [u8; 32]) -> Self
pub fn from_bytes(bytes: [u8; 32]) -> Self
Creates a new TxId
from a 32-byte array.
This is the primary constructor for TxId
when you have the raw transaction
hash available.
§Examples
// Usually this would be a real transaction hash
let bytes = [0u8; 32];
let txid = TxId::from_bytes(bytes);
Sourcepub fn from_hex(hex: &str) -> Result<Self, HexParseError>
pub fn from_hex(hex: &str) -> Result<Self, HexParseError>
Parses a TxId
from a canonically-encoded (byte-reversed) hexadecimal string.
§Examples
let hex = "0000000000000000000000000000000000000000000000000000000000000001";
let blob = TxId::from_hex(hex).unwrap();
let mut expected = [0u8; 32];
expected[0] = 1;
assert_eq!(blob.as_ref(), &expected);
Sourcepub fn read<R: Read>(reader: R) -> Result<Self>
pub fn read<R: Read>(reader: R) -> Result<Self>
Reads a TxId
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 TxId from the cursor
let txid = TxId::read(&mut cursor)?;
Sourcepub fn write<W: Write>(&self, writer: W) -> Result<()>
pub fn write<W: Write>(&self, writer: W) -> Result<()>
Writes a TxId
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 = TxId::from_bytes([0u8; 32]);
let mut buffer = Vec::new();
// Write the TxId 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 TxId
impl Ord for TxId
Source§impl PartialOrd for TxId
impl PartialOrd for TxId
impl Copy for TxId
impl Eq for TxId
impl StructuralPartialEq for TxId
Auto Trait Implementations§
impl Freeze for TxId
impl RefUnwindSafe for TxId
impl Send for TxId
impl Sync for TxId
impl Unpin for TxId
impl UnwindSafe for TxId
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