Skip to content

Commit

Permalink
Common Type Fixes (ethereumjs#3307)
Browse files Browse the repository at this point in the history
* Common: Improve typing for getHardforkBy()

* Common: Fixes type issue in paramByHardfork()
  • Loading branch information
holgerd77 authored Mar 11, 2024
1 parent 5e3cfdd commit 435606e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/common/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,9 @@ export class Common {
* @returns The name of the HF
*/
getHardforkBy(opts: HardforkByOpts): string {
let { blockNumber, timestamp, td } = opts

blockNumber = toType(blockNumber, TypeOutput.BigInt)
td = toType(td, TypeOutput.BigInt)
timestamp = toType(timestamp, TypeOutput.BigInt)
const blockNumber: bigint | undefined = toType(opts.blockNumber, TypeOutput.BigInt)
const td: bigint | undefined = toType(opts.td, TypeOutput.BigInt)
const timestamp: bigint | undefined = toType(opts.timestamp, TypeOutput.BigInt)

// Filter out hardforks with no block number, no ttd or no timestamp (i.e. unapplied hardforks)
const hfs = this.hardforks().filter(
Expand All @@ -353,10 +351,8 @@ export class Common {
// discovering/checking number hardforks.
let hfIndex = hfs.findIndex(
(hf) =>
(blockNumber !== undefined &&
hf.block !== null &&
BigInt(hf.block) > (blockNumber as bigint)) ||
(timestamp !== undefined && hf.timestamp !== undefined && hf.timestamp > timestamp)
(blockNumber !== undefined && hf.block !== null && BigInt(hf.block) > blockNumber) ||
(timestamp !== undefined && hf.timestamp !== undefined && BigInt(hf.timestamp) > timestamp)
)

if (hfIndex === -1) {
Expand Down Expand Up @@ -601,7 +597,7 @@ export class Common {
* @returns The value requested or `BigInt(0)` if not found
*/
paramByHardfork(topic: string, name: string, hardfork: string | Hardfork): bigint {
let value = null
let value: bigint | null = null
for (const hfChanges of this.HARDFORK_CHANGES) {
// EIP-referencing HF config (e.g. for berlin)
if ('eips' in hfChanges[1]) {
Expand Down

0 comments on commit 435606e

Please sign in to comment.