Make the BlockHeaderHash conversions work on borrows.

This commit is contained in:
Henry de Valence 2020-02-07 09:21:23 -08:00
parent 5f6bf188ff
commit 3c6fda8e0b
2 changed files with 9 additions and 3 deletions

View File

@ -43,8 +43,8 @@ impl fmt::Debug for BlockHeaderHash {
}
}
impl From<BlockHeader> for BlockHeaderHash {
fn from(block_header: BlockHeader) -> Self {
impl<'a> From<&'a BlockHeader> for BlockHeaderHash {
fn from(block_header: &'a BlockHeader) -> Self {
let mut hash_writer = Sha256dWriter::default();
block_header
.zcash_serialize(&mut hash_writer)
@ -169,6 +169,12 @@ pub struct Block {
pub transactions: Vec<Transaction>,
}
impl<'a> From<&'a Block> for BlockHeaderHash {
fn from(block: &'a Block) -> BlockHeaderHash {
(&block.header).into()
}
}
impl ZcashSerialize for Block {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
self.header.zcash_serialize(&mut writer)?;

View File

@ -77,7 +77,7 @@ fn blockheaderhash_from_blockheader() {
solution: EquihashSolution([0; 1344]),
};
let hash = BlockHeaderHash::from(blockheader);
let hash = BlockHeaderHash::from(&blockheader);
assert_eq!(
format!("{:?}", hash),