pub struct StockHeader {
pub version: u32,
pub prev_block_hash: BlockHash,
pub merkle_root: [u8; 32],
pub time: u32,
pub bits: u32,
pub nonce: u32,
}Expand description
The 80-byte Bitcoin block header (btc:BlockHeader in the kernel’s
schema/core.jsonld).
Layout, all little-endian: version (4) ‖ prev_block_hash (32) ‖
merkle_root (32) ‖ time (4) ‖ bits (4) ‖ nonce (4). The block
hash is SHA-256d of these bytes, printed byte-reversed.
Beside a stock parent siding builds every header with
version = 0x2000_0000 and bit 31 clear (siding/lib/block.mjs
buildBlock); the height lives only in the coinbase’s BIP 34 push, so
this struct has no height field. version is held as u32 rather than
Bitcoin’s i32: the two agree for every header this crate accepts,
because a set bit 31 is rejected by StockHeader::decode.
use sidestr_header::{StockHeader, Target};
// sidestr:dreamlab block 0 (agentbox ADR-2103), beside tbtc4.
let bytes = hex::decode(
"0000002000000000000000000000000000000000000000000000000000000000000000003a87d59ecf60ab58ee75948cc39d1bb44ac4285747e64b5a1e7a960d37764cb40e67b26affff7f2002000000",
).unwrap();
let h = StockHeader::decode(&bytes).unwrap();
assert_eq!(h.version, 0x2000_0000);
assert_eq!(h.time, 1_790_076_686);
assert_eq!(h.nonce, 2);
assert_eq!(h.hash().to_string(),
"4db37517728bd509c0cb96ee5a2e3e2a77f9e965a092e9f67948b413d453dbc0");
let pow_limit = Target::from_hex("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap();
assert!(h.check_pow(&pow_limit).is_ok());
assert_eq!(h.encode().as_slice(), bytes.as_slice());Fields§
§version: u32Block version. Bit 31 must be clear (see the struct docs).
prev_block_hash: BlockHashThe previous block’s hash; all zeros for a genesis.
merkle_root: [u8; 32]The transaction merkle root in wire (internal) order — the bytes as serialised, not as an explorer prints them.
time: u32Block time, Unix seconds.
bits: u32Compact proof-of-work target; on a sidestr chain always the compact
form of powLimit.
nonce: u32The proof-of-work nonce.
Implementations§
Source§impl StockHeader
impl StockHeader
Sourcepub fn decode(bytes: &[u8]) -> Result<Self, Error>
pub fn decode(bytes: &[u8]) -> Result<Self, Error>
Decodes exactly 80 bytes. Rejects any other length
(Error::WrongLength) and a version with bit 31 set
(Error::VersionBit31Set).
Sourcepub fn hash(&self) -> BlockHash
pub fn hash(&self) -> BlockHash
The block hash: SHA-256d of the 80 bytes, in display order. It is also
the proof-of-work hash (the kernel’s sha256d powHash).
Sourcepub fn meets_target(&self) -> bool
pub fn meets_target(&self) -> bool
hash ≤ target(bits): the kernel’s checkProofOfWork. False when
bits does not decode.
Sourcepub fn check_pow(&self, pow_limit: &Target) -> Result<(), Error>
pub fn check_pow(&self, pow_limit: &Target) -> Result<(), Error>
SPEC 4 step 1 as siding applies it: bits must be the compact form
of pow_limit and the hash must meet it.
Sourcepub fn signet_preimage(&self, stripped_merkle_root: [u8; 32]) -> [u8; 72]
pub fn signet_preimage(&self, stripped_merkle_root: [u8; 32]) -> [u8; 72]
The first 72 header bytes — version ‖ prev ‖ merkle_root ‖ time —
with merkle_root replaced by stripped_merkle_root, the root over
the coinbase stripped of its solution. This is what BIP-325’s block
data hashes (siding/lib/block.mjs blockData).
Trait Implementations§
Source§impl Clone for StockHeader
impl Clone for StockHeader
impl Copy for StockHeader
Source§impl Debug for StockHeader
impl Debug for StockHeader
impl Eq for StockHeader
Source§impl PartialEq for StockHeader
impl PartialEq for StockHeader
impl StructuralPartialEq for StockHeader
Auto Trait Implementations§
impl Freeze for StockHeader
impl RefUnwindSafe for StockHeader
impl Send for StockHeader
impl Sync for StockHeader
impl Unpin for StockHeader
impl UnsafeUnpin for StockHeader
impl UnwindSafe for StockHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.