impl FromStr for BlockHeaderHash

This is very convenient for putting block hashes in the source code.
This commit is contained in:
Henry de Valence 2020-03-18 17:00:12 -07:00 committed by Deirdre Connolly
parent dd8ba287bf
commit 6ec934a8d7
1 changed files with 12 additions and 0 deletions

View File

@ -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