|
|
|
@ -30,6 +30,7 @@ import java.util.OptionalLong; |
|
|
|
|
|
|
|
|
|
import org.apache.tuweni.bytes.Bytes; |
|
|
|
|
import org.apache.tuweni.bytes.Bytes32; |
|
|
|
|
import org.apache.tuweni.units.bigints.UInt64; |
|
|
|
|
|
|
|
|
|
/** A utility class for building block headers. */ |
|
|
|
|
public class BlockHeaderBuilder { |
|
|
|
@ -76,6 +77,7 @@ public class BlockHeaderBuilder { |
|
|
|
|
private Long blobGasUsed = null; |
|
|
|
|
private BlobGas excessBlobGas = null; |
|
|
|
|
private Bytes32 parentBeaconBlockRoot = null; |
|
|
|
|
private UInt64 targetBlobCount = null; |
|
|
|
|
|
|
|
|
|
public static BlockHeaderBuilder create() { |
|
|
|
|
return new BlockHeaderBuilder(); |
|
|
|
@ -124,7 +126,8 @@ public class BlockHeaderBuilder { |
|
|
|
|
.blobGasUsed(header.getBlobGasUsed().orElse(null)) |
|
|
|
|
.excessBlobGas(header.getExcessBlobGas().orElse(null)) |
|
|
|
|
.parentBeaconBlockRoot(header.getParentBeaconBlockRoot().orElse(null)) |
|
|
|
|
.requestsHash(header.getRequestsHash().orElse(null)); |
|
|
|
|
.requestsHash(header.getRequestsHash().orElse(null)) |
|
|
|
|
.targetBlobCount(header.getTargetBlobCount().orElse(null)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static BlockHeaderBuilder fromBuilder(final BlockHeaderBuilder fromBuilder) { |
|
|
|
@ -149,6 +152,7 @@ public class BlockHeaderBuilder { |
|
|
|
|
.excessBlobGas(fromBuilder.excessBlobGas) |
|
|
|
|
.parentBeaconBlockRoot(fromBuilder.parentBeaconBlockRoot) |
|
|
|
|
.requestsHash(fromBuilder.requestsHash) |
|
|
|
|
.targetBlobCount(fromBuilder.targetBlobCount) |
|
|
|
|
.blockHeaderFunctions(fromBuilder.blockHeaderFunctions); |
|
|
|
|
toBuilder.nonce = fromBuilder.nonce; |
|
|
|
|
return toBuilder; |
|
|
|
@ -179,6 +183,7 @@ public class BlockHeaderBuilder { |
|
|
|
|
excessBlobGas, |
|
|
|
|
parentBeaconBlockRoot, |
|
|
|
|
requestsHash, |
|
|
|
|
targetBlobCount, |
|
|
|
|
blockHeaderFunctions); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -194,7 +199,8 @@ public class BlockHeaderBuilder { |
|
|
|
|
timestamp, |
|
|
|
|
baseFee, |
|
|
|
|
mixHashOrPrevRandao, |
|
|
|
|
parentBeaconBlockRoot); |
|
|
|
|
parentBeaconBlockRoot, |
|
|
|
|
targetBlobCount); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public SealableBlockHeader buildSealableBlockHeader() { |
|
|
|
@ -220,7 +226,8 @@ public class BlockHeaderBuilder { |
|
|
|
|
blobGasUsed, |
|
|
|
|
excessBlobGas, |
|
|
|
|
parentBeaconBlockRoot, |
|
|
|
|
requestsHash); |
|
|
|
|
requestsHash, |
|
|
|
|
targetBlobCount); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void validateBlockHeader() { |
|
|
|
@ -260,6 +267,7 @@ public class BlockHeaderBuilder { |
|
|
|
|
baseFee(processableBlockHeader.getBaseFee().orElse(null)); |
|
|
|
|
processableBlockHeader.getPrevRandao().ifPresent(this::prevRandao); |
|
|
|
|
processableBlockHeader.getParentBeaconBlockRoot().ifPresent(this::parentBeaconBlockRoot); |
|
|
|
|
processableBlockHeader.getTargetBlobCount().ifPresent(this::targetBlobCount); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -285,6 +293,7 @@ public class BlockHeaderBuilder { |
|
|
|
|
sealableBlockHeader.getExcessBlobGas().ifPresent(this::excessBlobGas); |
|
|
|
|
sealableBlockHeader.getParentBeaconBlockRoot().ifPresent(this::parentBeaconBlockRoot); |
|
|
|
|
requestsHash(sealableBlockHeader.getRequestsHash().orElse(null)); |
|
|
|
|
sealableBlockHeader.getTargetBlobCount().ifPresent(this::targetBlobCount); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -418,4 +427,9 @@ public class BlockHeaderBuilder { |
|
|
|
|
this.parentBeaconBlockRoot = parentBeaconBlockRoot; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public BlockHeaderBuilder targetBlobCount(final UInt64 targetBlobCount) { |
|
|
|
|
this.targetBlobCount = targetBlobCount; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|