Package com.privatechain.core.builder
Class GenesisBlockFactory
java.lang.Object
com.privatechain.core.builder.GenesisBlockFactory
Factory for creating the genesis block (index 0) of a new blockchain.
The genesis block is special in two ways (FR-CORE-07):
- Its
previousHashis the 64-character all-zero string, representing "no previous block". - It contains no transactions; its Merkle root is the empty-tree sentinel.
The factory creates a deterministic genesis block: the same
chainId always produces the same block hash, which is important for
nodes in the same network to agree on the starting point.
Usage
Block genesis = GenesisBlockFactory.create("my-private-chain");
The genesis block created here is accepted by all built-in
ConsensusEngine implementations without
requiring consensus (it is the initial state, not a mined block).
- Since:
- 1.0.0
-
Method Details
-
create
Creates a deterministic genesis block for the given chain identifier.The chain ID is embedded in the block's Merkle root computation to ensure that two chains with different IDs cannot share the same genesis block hash, preventing accidental cross-chain block acceptance.
- Parameters:
chainId- a stable, non-blank identifier for this blockchain network (e.g.,"acme-supply-chain-v1"); must not change across restarts- Returns:
- the fully constructed, hash-verified genesis block
- Throws:
NullPointerException- if chainId is nullIllegalArgumentException- if chainId is blank
-
createDefault
Creates a genesis block with the default chain ID"private-blockchain".Suitable for quick-start scenarios and tests that do not need a custom network identifier.
- Returns:
- the default genesis block
-