forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (49 loc) · 1.54 KB
/
main.go
File metadata and controls
60 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"math/big"
"os"
"path/filepath"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/core"
"github.com/erigontech/erigon/zk/zk_config"
"github.com/erigontech/erigon/zk/zk_config/cfg_dynamic_genesis"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: genesisroot <config-dir> [chain-name]\n")
fmt.Fprintf(os.Stderr, " config-dir: directory containing <chain>-allocs.json, <chain>-chainspec.json, <chain>-conf.json\n")
fmt.Fprintf(os.Stderr, " chain-name: chain name (default: dynamic-hermez-dev)\n")
os.Exit(1)
}
configDir := os.Args[1]
chain := "dynamic-hermez-dev"
if len(os.Args) > 2 {
chain = os.Args[2]
}
absDir, err := filepath.Abs(configDir)
if err != nil {
fmt.Fprintf(os.Stderr, "invalid config dir: %v\n", err)
os.Exit(1)
}
zk_config.ZKDynamicConfigPath = absDir
zk_config.ZkUnionConfigPath = ""
dConf := cfg_dynamic_genesis.NewDynamicGenesisConfig(chain)
genesis := core.DynamicGenesisBlock(chain)
genesis.Timestamp = dConf.Timestamp
genesis.GasLimit = dConf.GasLimit
genesis.Difficulty = big.NewInt(dConf.Difficulty)
tmpDir, err := os.MkdirTemp("", "genesisroot-*")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create temp dir: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)
block, _, _, err := core.GenesisToBlock(genesis, tmpDir, log.Root())
if err != nil {
fmt.Fprintf(os.Stderr, "GenesisToBlock failed: %v\n", err)
os.Exit(1)
}
fmt.Println("State Root:", block.Root().Hex())
fmt.Println("Block Hash:", block.Hash().Hex())
}