Skip to content

Commit

Permalink
feat(core): add "blobGasUsed" and "excessBlobGas" as Block fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialPB committed Dec 21, 2023
1 parent 22fb026 commit 906d538
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 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 @@ -43,6 +43,8 @@ data class BlockWithHashes(
override val uncles: List<Hash>,
override val withdrawals: List<Withdrawal>?,
override val withdrawalsRoot: Hash?,
override val blobGasUsed: Long,
override val excessBlobGas: Long,
override val otherFields: Map<String, JsonNode> = emptyMap(),
) : Block<Hash>

Expand Down Expand Up @@ -71,6 +73,8 @@ data class BlockWithTransactions(
override val uncles: List<Hash>,
override val withdrawals: List<Withdrawal>?,
override val withdrawalsRoot: Hash?,
override val blobGasUsed: Long,
override val excessBlobGas: Long,
override val otherFields: Map<String, JsonNode> = emptyMap(),
) : Block<RPCTransaction>

Expand Down Expand Up @@ -98,6 +102,8 @@ interface Block<T> {
val uncles: List<Hash>
val withdrawals: List<Withdrawal>?
val withdrawalsRoot: Hash?
val blobGasUsed: Long
val excessBlobGas: Long
val otherFields: Map<String, JsonNode>
}

Expand Down Expand Up @@ -141,6 +147,8 @@ private class BlockWithHashesDeserializer : GenericBlockDeserializer<Hash, Block
uncles: List<Hash>,
withdrawals: List<Withdrawal>?,
withdrawalsRoot: Hash?,
blobGasUsed: Long,
excessBlobGas: Long,
otherFields: Map<String, JsonNode>,
): BlockWithHashes {
return BlockWithHashes(
Expand All @@ -167,6 +175,8 @@ private class BlockWithHashesDeserializer : GenericBlockDeserializer<Hash, Block
uncles,
withdrawals,
withdrawalsRoot,
blobGasUsed,
excessBlobGas,
otherFields,
)
}
Expand Down Expand Up @@ -201,6 +211,8 @@ private class BlockWithTransactionDeserialize : GenericBlockDeserializer<RPCTran
uncles: List<Hash>,
withdrawals: List<Withdrawal>?,
withdrawalsRoot: Hash?,
blobGasUsed: Long,
excessBlobGas: Long,
otherFields: Map<String, JsonNode>,
): BlockWithTransactions {
return BlockWithTransactions(
Expand All @@ -227,6 +239,8 @@ private class BlockWithTransactionDeserialize : GenericBlockDeserializer<RPCTran
uncles,
withdrawals,
withdrawalsRoot,
blobGasUsed,
excessBlobGas,
otherFields,
)
}
Expand Down Expand Up @@ -261,6 +275,8 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
var uncles: List<Hash>? = null
var withdrawals: List<Withdrawal>? = null
var withdrawalsRoot: Hash? = null
var blobGasUsed: Long = -1L
var excessBlobGas: Long = -1L
var otherFields: MutableMap<String, JsonNode>? = null

p.forEachObjectField { field ->
Expand Down Expand Up @@ -291,6 +307,8 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
"uncles" -> uncles = p.readOrNull { readListOfHashes() }
"withdrawals" -> withdrawals = p.readOrNull { readListOf(Withdrawal::class.java) }
"withdrawalsRoot" -> withdrawalsRoot = p.readOrNull { readHash() }
"blobGasUsed" -> blobGasUsed = p.readHexLong()
"excessBlobGas" -> excessBlobGas = p.readHexLong()
else -> {
if (otherFields == null) {
otherFields = HashMap()
Expand Down Expand Up @@ -324,6 +342,8 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
uncles ?: emptyList(),
withdrawals,
withdrawalsRoot,
blobGasUsed,
excessBlobGas,
otherFields ?: emptyMap(),
)
}
Expand Down Expand Up @@ -354,6 +374,8 @@ private abstract class GenericBlockDeserializer<TX, T : Block<TX>> : JsonDeseria
uncles: List<Hash>,
withdrawals: List<Withdrawal>?,
withdrawalsRoot: Hash?,
blobGasUsed: Long,
excessBlobGas: Long,
otherFields: Map<String, JsonNode>,
): T
}
Expand Down
4 changes: 4 additions & 0 deletions ethers-core/src/test/kotlin/io/ethers/core/types/BlockTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class BlockTest : FunSpec({
Withdrawal(20789864, 599445, Address("0xe839a3e9efb32c6a56ab7128e51056585275506c"), 16657613L),
),
withdrawalsRoot = Hash("0x1276b1e90b9f4a76b24e5fad4adce2a5e6ffef7351bfaa2e128955950a9027b0"),
blobGasUsed = -1L,
excessBlobGas = -1L,
otherFields = mapOf(
"test" to Jackson.MAPPER.readTree("""{"k1":"v1","k2":"v2"}"""),
),
Expand Down Expand Up @@ -274,6 +276,8 @@ class BlockTest : FunSpec({
Withdrawal(20789864, 599445, Address("0xe839a3e9efb32c6a56ab7128e51056585275506c"), 16657613L),
),
withdrawalsRoot = Hash("0x1276b1e90b9f4a76b24e5fad4adce2a5e6ffef7351bfaa2e128955950a9027b0"),
blobGasUsed = -1L,
excessBlobGas = -1L,
otherFields = mapOf(
"test" to Jackson.MAPPER.readTree("""{"k1":"v1","k2":"v2"}"""),
),
Expand Down

0 comments on commit 906d538

Please sign in to comment.