Package com.privatechain.core.model
Record Class BlockHeader
java.lang.Object
java.lang.Record
com.privatechain.core.model.BlockHeader
- Record Components:
version- protocol version (must be ≥ 1)bits- compact difficulty target used by PoW consensus; 0 for non-PoW enginesnonce- proof-of-work nonce discovered during miningmerkleRoot- hex-encoded SHA-256 Merkle root of the block's transactionstimestamp- instant at which the block was produced (UTC, non-null)
public record BlockHeader(int version, int bits, long nonce, String merkleRoot, Instant timestamp)
extends Record
Lightweight, immutable record representing the header of a
Block.
The header contains all metadata needed for chain validation without loading
the full transaction list, satisfying FR-CORE-05. It is a Java record
to guarantee immutability and provide auto-generated equals/hashCode/toString.
Fields follow Bitcoin-style naming conventions where applicable:
version— protocol version for future-compatibilitybits— compact difficulty target (PoW specific; ignored by other engines)nonce— mutable-during-mining counter; fixed after block is sealedmerkleRoot— SHA-256 root of the transaction Merkle treetimestamp— wall-clock time at block creation (UTC)
- Since:
- 1.0.0
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSentinel Merkle root used when a block contains no transactions. -
Constructor Summary
ConstructorsConstructorDescriptionBlockHeader(int version, int bits, long nonce, String merkleRoot, Instant timestamp) Canonical constructor with validation. -
Method Summary
Modifier and TypeMethodDescriptionintbits()Returns the value of thebitsrecord component.static BlockHeader.Builderbuilder()Returns a newBlockHeader.Builderpre-populated with sensible defaults.final booleanIndicates whether some other object is "equal to" this one.static BlockHeadergenesis()Creates a genesis-block header with a zero nonce and the empty Merkle root.final inthashCode()Returns a hash code value for this object.Returns the value of themerkleRootrecord component.longnonce()Returns the value of thenoncerecord component.static BlockHeaderCreates aBlockHeaderwith the current UTC timestamp and version 1.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.intversion()Returns the value of theversionrecord component.
-
Field Details
-
EMPTY_MERKLE_ROOT
Sentinel Merkle root used when a block contains no transactions.- See Also:
-
-
Constructor Details
-
BlockHeader
Canonical constructor with validation.- Parameters:
version- protocol version (must be ≥ 1)bits- compact difficulty target (≥ 0)nonce- mining noncemerkleRoot- Merkle root hex string (non-null, non-blank)timestamp- block timestamp (non-null)- Throws:
IllegalArgumentException- if version < 1, bits < 0, or strings are blankNullPointerException- if merkleRoot or timestamp is null
-
-
Method Details
-
of
Creates aBlockHeaderwith the current UTC timestamp and version 1.Convenience factory for common use cases where the caller does not need to control the timestamp (e.g., tests, quick demos).
- Parameters:
bits- compact difficulty targetnonce- mining noncemerkleRoot- Merkle root hex string- Returns:
- a new
BlockHeadertimestampedInstant.now()
-
genesis
Creates a genesis-block header with a zero nonce and the empty Merkle root.- Returns:
- a header suitable for use as the genesis block header
-
builder
Returns a newBlockHeader.Builderpre-populated with sensible defaults.- Returns:
- a mutable builder for constructing a
BlockHeader
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
version
public int version()Returns the value of theversionrecord component.- Returns:
- the value of the
versionrecord component
-
bits
public int bits()Returns the value of thebitsrecord component.- Returns:
- the value of the
bitsrecord component
-
nonce
public long nonce()Returns the value of thenoncerecord component.- Returns:
- the value of the
noncerecord component
-
merkleRoot
Returns the value of themerkleRootrecord component.- Returns:
- the value of the
merkleRootrecord component
-
timestamp
Returns the value of thetimestamprecord component.- Returns:
- the value of the
timestamprecord component
-