Package com.privatechain.core.model
Class Block.Builder
java.lang.Object
com.privatechain.core.model.Block.Builder
- Enclosing class:
Block
Fluent builder for
Block.
Calling build() computes the block hash automatically.
Supply minerAddress(String) for identity-based consensus engines
(PoA, RoundRobin, PBFT); omit it for PoW blocks.
// PoA block
Block block = Block.builder()
.index(1)
.previousHash(prev.getHash())
.transactions(txList)
.header(BlockHeader.builder().build())
.minerAddress(localAddress)
.build();
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns an immutableBlock.header(BlockHeader header) Sets the block header.index(int index) Sets the block index.minerAddress(String minerAddress) Sets the address of the node producing this block.previousHash(String previousHash) Sets the hash of the preceding block.transactions(List<Transaction> transactions) Sets the transaction list for this block.
-
Method Details
-
index
Sets the block index.- Parameters:
index- block index (≥ 0)- Returns:
- this builder
-
header
Sets the block header.- Parameters:
header- non-null block header- Returns:
- this builder
-
previousHash
Sets the hash of the preceding block.- Parameters:
previousHash- hex-encoded SHA-256 hash (non-null)- Returns:
- this builder
-
transactions
Sets the transaction list for this block.- Parameters:
transactions- list of transactions (non-null; may be empty)- Returns:
- this builder
-
minerAddress
Sets the address of the node producing this block.Required for identity-based consensus (PoA, RoundRobin, PBFT). Leave unset (or pass
null) for PoW blocks.- Parameters:
minerAddress- producing node address;nullis allowed- Returns:
- this builder
-
build
Builds and returns an immutableBlock.The block hash is computed automatically from all supplied fields including
minerAddress.- Returns:
- a new immutable
Blockwith a computed hash
-