From 6ec934a8d78d7d92904774f28aa392a104824604 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Wed, 18 Mar 2020 17:00:12 -0700 Subject: [PATCH] impl FromStr for BlockHeaderHash This is very convenient for putting block hashes in the source code. --- zebra-chain/src/block.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index 2ffed136..86ce1dac 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -67,6 +67,18 @@ impl ZcashDeserialize for BlockHeaderHash { } } +impl std::str::FromStr for BlockHeaderHash { + type Err = SerializationError; + fn from_str(s: &str) -> Result { + 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