use amplify::hex::{self, FromHex};
use amplify::{Bytes32, Bytes32StrRev, Wrapper};
use crate::LIB_NAME_BITCOIN;
#[derive(Wrapper, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, From)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_BITCOIN)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", transparent)
)]
#[wrapper(BorrowSlice, Index, RangeOps, Debug, LowerHex, UpperHex, Display, FromStr)]
pub struct BlockHash(
#[from]
#[from([u8; 32])]
Bytes32StrRev,
);
impl FromHex for BlockHash {
fn from_byte_iter<I>(iter: I) -> Result<Self, hex::Error>
where I: Iterator<Item = Result<u8, hex::Error>> + ExactSizeIterator + DoubleEndedIterator {
Bytes32StrRev::from_byte_iter(iter).map(Self)
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(StrictType, StrictEncode, StrictDecode, StrictDumb)]
#[strict_type(lib = LIB_NAME_BITCOIN)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct BlockHeader {
pub version: i32,
pub prev_block_hash: BlockHash,
pub merkle_root: Bytes32,
pub time: u32,
pub bits: u32,
pub nonce: u32,
}