Package com.privatechain.core.builder
Class BlockchainConfig.Builder
java.lang.Object
com.privatechain.core.builder.BlockchainConfig.Builder
- Enclosing class:
BlockchainConfig
Fluent builder for
BlockchainConfig.
All fields have production-ready defaults so that builder().build()
produces a working in-memory chain (FR-CFG-02).
-
Method Summary
Modifier and TypeMethodDescriptionblockTimeSeconds(int seconds) Sets the target block time in seconds.build()Builds the configuration and returns a ready-to-startBlockchainNode.Builds and returns the rawBlockchainConfigwithout wrapping it in a node.Sets the stable chain identifier embedded in the genesis block.consensusEngine(ConsensusEngine engine) Sets the consensus engine.difficulty(int difficulty) Sets the PoW difficulty (number of leading zero bits).eventBus(BlockchainEventBus eventBus) Replaces the default event bus with a custom instance.eventListener(BlockchainEventListener listener) Registers an event listener that will receive all blockchain events.maxMempoolSize(int maxSize) Sets the maximum pool capacity (Milestone 8).maxPeers(int maxPeers) Sets the maximum number of simultaneous peer connections.mempoolTtl(Duration ttl) Sets the TTL for unconfirmed transactions in the mempool (Milestone 8).networkPort(int port) Sets the TCP port for the P2P node server.storage(BlockchainStorage storage) Sets the storage backend.transactionPrioritizer(TransactionPrioritizer prioritizer) Sets the transaction prioritizer for mempool ordering (FR-MEMPOOL-02).transactionValidator(TransactionValidator validator) Appends a transaction validator to the validation chain (FR-TX-03).
-
Method Details
-
consensusEngine
Sets the consensus engine.If not set, defaults to a no-op engine (accepts all blocks). Production chains must supply a real engine.
- Parameters:
engine- the engine to use (non-null)- Returns:
- this builder
- Throws:
NullPointerException- if engine is null
-
transactionValidator
Appends a transaction validator to the validation chain (FR-TX-03).- Parameters:
validator- the validator to add (non-null)- Returns:
- this builder
- Throws:
NullPointerException- if validator is null
-
storage
Sets the storage backend.If not set, defaults to in-memory storage (ephemeral).
- Parameters:
storage- the persistence backend (non-null)- Returns:
- this builder
- Throws:
NullPointerException- if storage is null
-
eventBus
Replaces the default event bus with a custom instance.- Parameters:
eventBus- the event bus to use (non-null)- Returns:
- this builder
- Throws:
NullPointerException- if eventBus is null
-
eventListener
Registers an event listener that will receive all blockchain events.- Parameters:
listener- the listener to register (non-null)- Returns:
- this builder
- Throws:
NullPointerException- if listener is null
-
transactionPrioritizer
Sets the transaction prioritizer for mempool ordering (FR-MEMPOOL-02).- Parameters:
prioritizer- the ordering strategy (non-null)- Returns:
- this builder
- Throws:
NullPointerException- if prioritizer is null
-
networkPort
Sets the TCP port for the P2P node server.- Parameters:
port- port number (1024–65535)- Returns:
- this builder
- Throws:
IllegalArgumentException- if port is out of range
-
blockTimeSeconds
Sets the target block time in seconds.- Parameters:
seconds- block time (≥ 1)- Returns:
- this builder
- Throws:
IllegalArgumentException- if seconds < 1
-
difficulty
Sets the PoW difficulty (number of leading zero bits).- Parameters:
difficulty- difficulty level (≥ 1)- Returns:
- this builder
- Throws:
IllegalArgumentException- if difficulty < 1
-
maxPeers
Sets the maximum number of simultaneous peer connections.- Parameters:
maxPeers- max peers (≥ 1)- Returns:
- this builder
- Throws:
IllegalArgumentException- if maxPeers < 1
-
chainId
Sets the stable chain identifier embedded in the genesis block.- Parameters:
chainId- non-null, non-blank identifier- Returns:
- this builder
- Throws:
NullPointerException- if chainId is nullIllegalArgumentException- if chainId is blank
-
mempoolTtl
Sets the TTL for unconfirmed transactions in the mempool (Milestone 8).Default: 30 minutes.
- Parameters:
ttl- positive duration (non-null)- Returns:
- this builder
- Throws:
NullPointerException- if ttl is nullIllegalArgumentException- if ttl is zero or negative
-
maxMempoolSize
Sets the maximum pool capacity (Milestone 8).Default: unbounded (
Integer.MAX_VALUE).- Parameters:
maxSize- max pool capacity (≥ 1)- Returns:
- this builder
- Throws:
IllegalArgumentException- if maxSize < 1
-
build
Builds the configuration and returns a ready-to-startBlockchainNode.Lazy defaults are resolved here so that
blockchain-corenever hard-imports classes fromblockchain-consensusorblockchain-storage.- Returns:
- a configured, not-yet-started
BlockchainNode
-
buildConfig
Builds and returns the rawBlockchainConfigwithout wrapping it in a node.Useful for testing or DI containers that construct the node separately.
- Returns:
- a fully configured, immutable
BlockchainConfig
-