Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add support for eip-4788 parentBeaconBlockRoot header field #43

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ethers-core/src/main/kotlin/io/ethers/core/types/Block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class BlockWithHashes(
override val withdrawalsRoot: Hash?,
override val blobGasUsed: Long,
override val excessBlobGas: Long,
override val parentBeaconBlockRoot: Hash?,
override val otherFields: Map<String, JsonNode> = emptyMap(),
) : Block<Hash>

Expand Down Expand Up @@ -75,6 +76,7 @@ data class BlockWithTransactions(
override val withdrawalsRoot: Hash?,
override val blobGasUsed: Long,
override val excessBlobGas: Long,
override val parentBeaconBlockRoot: Hash?,
override val otherFields: Map<String, JsonNode> = emptyMap(),
) : Block<RPCTransaction>

Expand Down Expand Up @@ -104,6 +106,7 @@ interface Block<T> {
val withdrawalsRoot: Hash?
val blobGasUsed: Long
val excessBlobGas: Long
val parentBeaconBlockRoot: Hash?
val otherFields: Map<String, JsonNode>
}

Expand Down Expand Up @@ -149,6 +152,7 @@ private class BlockWithHashesDeserializer : GenericBlockDeserializer<Hash, Block
withdrawalsRoot: Hash?,
blobGasUsed: Long,
excessBlobGas: Long,
parentBeaconBlockRoot: Hash?,
otherFields: Map<String, JsonNode>,
): BlockWithHashes {
return BlockWithHashes(
Expand Down Expand Up @@ -177,6 +181,7 @@ private class BlockWithHashesDeserializer : GenericBlockDeserializer<Hash, Block
withdrawalsRoot,
blobGasUsed,
excessBlobGas,
parentBeaconBlockRoot,
otherFields,
)
}
Expand Down Expand Up @@ -213,6 +218,7 @@ private class BlockWithTransactionDeserialize : GenericBlockDeserializer<RPCTran
withdrawalsRoot: Hash?,
blobGasUsed: Long,
excessBlobGas: Long,
parentBeaconBlockRoot: Hash?,
otherFields: Map<String, JsonNode>,
): BlockWithTransactions {
return BlockWithTransactions(
Expand Down Expand Up @@ -241,6 +247,7 @@ private class BlockWithTransactionDeserialize : GenericBlockDeserializer<RPCTran
withdrawalsRoot,
blobGasUsed,
excessBlobGas,
parentBeaconBlockRoot,
otherFields,
)
}
Expand Down Expand Up @@ -277,6 +284,7 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
var withdrawalsRoot: Hash? = null
var blobGasUsed: Long = -1L
var excessBlobGas: Long = -1L
var parentBeaconBlockRoot: Hash? = null
var otherFields: MutableMap<String, JsonNode>? = null

p.forEachObjectField { field ->
Expand Down Expand Up @@ -309,6 +317,7 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
"withdrawalsRoot" -> withdrawalsRoot = p.readOrNull { readHash() }
"blobGasUsed" -> blobGasUsed = p.readHexLong()
"excessBlobGas" -> excessBlobGas = p.readHexLong()
"parentBeaconBlockRoot" -> parentBeaconBlockRoot = p.readOrNull { readHash() }
else -> {
if (otherFields == null) {
otherFields = HashMap()
Expand Down Expand Up @@ -344,6 +353,7 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
withdrawalsRoot,
blobGasUsed,
excessBlobGas,
parentBeaconBlockRoot,
otherFields ?: emptyMap(),
)
}
Expand Down Expand Up @@ -376,6 +386,7 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
withdrawalsRoot: Hash?,
blobGasUsed: Long,
excessBlobGas: Long,
parentBeaconBlockRoot: Hash?,
otherFields: Map<String, JsonNode>,
): T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class BlockTest : FunSpec({
"withdrawalsRoot": "0x1276b1e90b9f4a76b24e5fad4adce2a5e6ffef7351bfaa2e128955950a9027b0",
"baseFeePerGas": "0x2e22eacf",
"miner": "0x3b64216ad1a58f61538b4fa1b27327675ab7ed67",
"blobGasUsed": "0x1276b0",
"excessBlobGas": "0x01276b",
"parentBeaconBlockRoot": "0xc74b35721eec9b338589ea735f8d322b3e27f3259d9e924ef354a4336fb715a8",
"transactions": [
"0xc74b35721eec9b338589ea735f8d322b3e27f3259d9e924ef354a4336fb715a8",
"0x5c4ca94fca565ef1c983e3a3cd4bc6d6da1091a487f5d64b8a1bb3434a12d876",
Expand Down Expand Up @@ -106,8 +109,9 @@ class BlockTest : FunSpec({
Withdrawal(20789864, 599445, Address("0xe839a3e9efb32c6a56ab7128e51056585275506c"), 16657613L),
),
withdrawalsRoot = Hash("0x1276b1e90b9f4a76b24e5fad4adce2a5e6ffef7351bfaa2e128955950a9027b0"),
blobGasUsed = -1L,
excessBlobGas = -1L,
blobGasUsed = 1210032,
excessBlobGas = 75627,
parentBeaconBlockRoot = Hash("0xc74b35721eec9b338589ea735f8d322b3e27f3259d9e924ef354a4336fb715a8"),
otherFields = mapOf(
"test" to Jackson.MAPPER.readTree("""{"k1":"v1","k2":"v2"}"""),
),
Expand Down Expand Up @@ -278,6 +282,7 @@ class BlockTest : FunSpec({
withdrawalsRoot = Hash("0x1276b1e90b9f4a76b24e5fad4adce2a5e6ffef7351bfaa2e128955950a9027b0"),
blobGasUsed = -1L,
excessBlobGas = -1L,
parentBeaconBlockRoot = null,
otherFields = mapOf(
"test" to Jackson.MAPPER.readTree("""{"k1":"v1","k2":"v2"}"""),
),
Expand Down