pub struct Hash(/* private fields */);Expand description
A 32-byte hash used for transaction IDs, block hashes, and merkle trees.
When displayed as a string, the bytes are reversed to match Bitcoin’s standard representation (little-endian internal, big-endian display).
Implementations§
Source§impl Hash
impl Hash
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, PrimitivesError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, PrimitivesError>
Sourcepub fn from_hex(hex_str: &str) -> Result<Self, PrimitivesError>
pub fn from_hex(hex_str: &str) -> Result<Self, PrimitivesError>
Create a Hash from a byte-reversed hex string.
This matches the Go SDK’s NewHashFromHex / Decode function.
The hex string represents bytes in display order (reversed from
internal storage). Short strings are zero-padded on the high end.
§Arguments
hex_str- A hex string of up to 64 characters.
§Returns
Ok(Hash) on success, or an error for invalid input.
Sourcepub fn clone_bytes(&self) -> Vec<u8> ⓘ
pub fn clone_bytes(&self) -> Vec<u8> ⓘ
Return a copy of the internal bytes.
§Returns
A Vec<u8> containing the 32 hash bytes in internal order.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Hash
Deserialize from a hex string in JSON.
impl<'de> Deserialize<'de> for Hash
Deserialize from a hex string in JSON.
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for Hash
Display the hash as byte-reversed hex (Bitcoin convention).
impl Display for Hash
Display the hash as byte-reversed hex (Bitcoin convention).
Internal bytes [0x06, 0xe5, ...] display as "...e506".
Source§impl FromStr for Hash
Parse a byte-reversed hex string into a Hash.
impl FromStr for Hash
Parse a byte-reversed hex string into a Hash.
Equivalent to Hash::from_hex.