use super::{Block, Header};
use essential_hash::Address;
use essential_types::ContentAddress;
impl Address for Block {
fn content_address(&self) -> ContentAddress {
from_block(self)
}
}
pub fn from_block(block: &Block) -> ContentAddress {
let solution_addrs = block.solution_sets.iter().map(essential_hash::content_addr);
from_header_and_solution_set_addrs(&block.header, solution_addrs)
}
pub fn from_header_and_solution_set_addrs(
header: &Header,
solution_set_addrs: impl IntoIterator<Item = ContentAddress>,
) -> ContentAddress {
let solution_set_addrs: Vec<ContentAddress> = solution_set_addrs.into_iter().collect();
from_header_and_solution_set_addrs_slice(header, &solution_set_addrs)
}
pub fn from_header_and_solution_set_addrs_slice(
header: &Header,
solution_set_addrs: &[ContentAddress],
) -> ContentAddress {
ContentAddress(essential_hash::hash(&(
header.number,
header.timestamp,
solution_set_addrs,
)))
}