impl FromStr for BlockHeaderHash
This is very convenient for putting block hashes in the source code.
@@ -67,6 +67,18 @@ impl ZcashDeserialize for BlockHeaderHash {
}
}
+impl std::str::FromStr for BlockHeaderHash {
+ type Err = SerializationError;
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let mut bytes = [0; 32];
+ if hex::decode_to_slice(s, &mut bytes[..]).is_err() {
+ Err(SerializationError::Parse("hex decoding error"))
+ } else {
+ Ok(BlockHeaderHash(bytes))
+ }
+ }
+}
+
/// Block header.
///
/// How are blocks chained together? They are chained together via the
