Compiletime automatic collect fork field from ChainConfig
This commit is contained in:
parent
6ef5fd78b7
commit
0a01ab1fe0
|
@ -8,7 +8,7 @@
|
||||||
# those terms.
|
# those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[options],
|
std/[options, strutils],
|
||||||
eth/common,
|
eth/common,
|
||||||
stew/endians2,
|
stew/endians2,
|
||||||
json_serialization,
|
json_serialization,
|
||||||
|
@ -189,34 +189,44 @@ type
|
||||||
name*: string
|
name*: string
|
||||||
time*: Option[EthTime]
|
time*: Option[EthTime]
|
||||||
|
|
||||||
|
func countTimeFields(): int {.compileTime.} =
|
||||||
|
var z = Chainconfig()
|
||||||
|
for name, _ in fieldPairs(z[]):
|
||||||
|
if name.endsWith("Time"):
|
||||||
|
inc result
|
||||||
|
|
||||||
|
func countBlockFields(): int {.compileTime.} =
|
||||||
|
var z = Chainconfig()
|
||||||
|
for name, _ in fieldPairs(z[]):
|
||||||
|
if name.endsWith("Block"):
|
||||||
|
inc result
|
||||||
|
|
||||||
|
const
|
||||||
|
timeFieldsCount = countTimeFields()
|
||||||
|
blockFieldsCount = countBlockFields()
|
||||||
|
|
||||||
|
func collectTimeFields(): array[timeFieldsCount, string] =
|
||||||
|
var z = Chainconfig()
|
||||||
|
var i = 0
|
||||||
|
for name, _ in fieldPairs(z[]):
|
||||||
|
if name.endsWith("Time"):
|
||||||
|
result[i] = name
|
||||||
|
inc i
|
||||||
|
|
||||||
|
func collectBlockFields(): array[blockFieldsCount, string] =
|
||||||
|
var z = Chainconfig()
|
||||||
|
var i = 0
|
||||||
|
for name, _ in fieldPairs(z[]):
|
||||||
|
if name.endsWith("Block"):
|
||||||
|
result[i] = name
|
||||||
|
inc i
|
||||||
|
|
||||||
const
|
const
|
||||||
# this table is used for generate
|
# this table is used for generate
|
||||||
# code at compile time to check
|
# code at compile time to check
|
||||||
# the order of blok number in ChainConfig
|
# the order of blok number in ChainConfig
|
||||||
forkBlockField* = [
|
forkBlockField* = collectBlockFields()
|
||||||
"homesteadBlock",
|
forkTimeField* = collectTimeFields()
|
||||||
"daoForkBlock",
|
|
||||||
"eip150Block",
|
|
||||||
"eip155Block",
|
|
||||||
"eip158Block",
|
|
||||||
"byzantiumBlock",
|
|
||||||
"constantinopleBlock",
|
|
||||||
"petersburgBlock",
|
|
||||||
"istanbulBlock",
|
|
||||||
"muirGlacierBlock",
|
|
||||||
"berlinBlock",
|
|
||||||
"londonBlock",
|
|
||||||
"arrowGlacierBlock",
|
|
||||||
"grayGlacierBlock",
|
|
||||||
"mergeForkBlock",
|
|
||||||
]
|
|
||||||
|
|
||||||
forkTimeField* = [
|
|
||||||
"shanghaiTime",
|
|
||||||
"cancunTime",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
func mergeForkTransitionThreshold*(conf: ChainConfig): MergeForkTransitionThreshold =
|
func mergeForkTransitionThreshold*(conf: ChainConfig): MergeForkTransitionThreshold =
|
||||||
|
|
Loading…
Reference in New Issue