use super::*;
fn target_as_block_hash(target: bitcoin::Target) -> BlockHash {
BlockHash::from_raw_hash(Hash::from_byte_array(target.to_le_bytes()))
}
#[derive(Boilerplate)]
pub(crate) struct BlockHtml {
hash: BlockHash,
target: BlockHash,
best_height: Height,
block: Block,
height: Height,
inscription_count: usize,
featured_inscriptions: Vec<InscriptionId>,
}
impl BlockHtml {
pub(crate) fn new(
block: Block,
height: Height,
best_height: Height,
inscription_count: usize,
featured_inscriptions: Vec<InscriptionId>,
) -> Self {
Self {
hash: block.header.block_hash(),
target: target_as_block_hash(block.header.target()),
block,
height,
best_height,
inscription_count,
featured_inscriptions,
}
}
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct BlockJson {
pub hash: BlockHash,
pub target: BlockHash,
pub best_height: u32,
pub height: u32,
pub inscriptions: Vec<InscriptionId>,
}
impl BlockJson {
pub(crate) fn new(