add uint64 support

This commit is contained in:
klim0v 2025-09-15 16:45:59 +08:00
parent 59d12cf269
commit 39d0fb95c9
2 changed files with 12 additions and 1 deletions

View file

@ -107,13 +107,17 @@ func (c *ChainConfig) LoadForks(file []byte) error {
name := key[:len(key)-len("_FORK_VERSION")] name := key[:len(key)-len("_FORK_VERSION")]
switch version := value.(type) { switch version := value.(type) {
case int: case int:
versions[name] = big.NewInt(int64(version)).FillBytes(make([]byte, 4)) versions[name] = new(big.Int).SetUint64(uint64(version)).FillBytes(make([]byte, 4))
case uint64:
versions[name] = new(big.Int).SetUint64(version).FillBytes(make([]byte, 4))
case string: case string:
v, err := hexutil.Decode(version) v, err := hexutil.Decode(version)
if err != nil { if err != nil {
return fmt.Errorf("failed to decode hex fork id %q in beacon chain config file: %v", version, err) return fmt.Errorf("failed to decode hex fork id %q in beacon chain config file: %v", version, err)
} }
versions[name] = v versions[name] = v
default:
return fmt.Errorf("invalid fork version %q in beacon chain config file", version)
} }
} }
if strings.HasSuffix(key, "_FORK_EPOCH") { if strings.HasSuffix(key, "_FORK_EPOCH") {
@ -121,12 +125,16 @@ func (c *ChainConfig) LoadForks(file []byte) error {
switch epoch := value.(type) { switch epoch := value.(type) {
case int: case int:
epochs[name] = uint64(epoch) epochs[name] = uint64(epoch)
case uint64:
epochs[name] = epoch
case string: case string:
v, err := strconv.ParseUint(epoch, 10, 64) v, err := strconv.ParseUint(epoch, 10, 64)
if err != nil { if err != nil {
return fmt.Errorf("failed to parse epoch number %q in beacon chain config file: %v", epoch, err) return fmt.Errorf("failed to parse epoch number %q in beacon chain config file: %v", epoch, err)
} }
epochs[name] = v epochs[name] = v
default:
return fmt.Errorf("invalid fork epoch %q in beacon chain config file", epoch)
} }
} }
} }

View file

@ -12,6 +12,9 @@ GENESIS_FORK_VERSION: 0x00000000
ALTAIR_FORK_VERSION: 0x00000001 ALTAIR_FORK_VERSION: 0x00000001
ALTAIR_FORK_EPOCH: 1 ALTAIR_FORK_EPOCH: 1
EIP7928_FORK_VERSION: 0xb0000038
EIP7928_FORK_EPOCH: 18446744073709551615
BLOB_SCHEDULE: [] BLOB_SCHEDULE: []
` `
c := &ChainConfig{} c := &ChainConfig{}