-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (69 loc) · 1.66 KB
/
main.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"goevm/simulation"
"os"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"
)
var (
StorageFlag = &cli.StringFlag{
Name: "storage",
Usage: "Type of storage to use for simulation (simple/remote)",
Value: "simple",
}
Datadir = &cli.StringFlag{
Name: "datadir",
Usage: "Path to use for opening remote geth database",
Value: "",
}
ContractAddressFlag = &cli.StringFlag{
Name: "contract-address",
Usage: "Contract address to be used for remote simulation",
Value: "",
}
simulateCommand = &cli.Command{
Name: "simulate",
Usage: "Simulate EVM opcodes",
Action: runSimulator,
Flags: []cli.Flag{
StorageFlag,
Datadir,
ContractAddressFlag,
},
}
)
func initSimulator() *cli.App {
app := cli.NewApp()
app.Name = "evm-simulator"
app.Usage = "Simulate EVM opcodes"
app.Commands = []*cli.Command{simulateCommand}
return app
}
func main() {
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true)))
simulator := initSimulator()
if err := simulator.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func runSimulator(c *cli.Context) error {
storageType := c.String("storage")
if storageType == "simple" {
simulation.RunSimpleSimulation()
return nil
}
if storageType == "remote" {
contractAddress := c.String("contract-address")
path := c.String("datadir")
if contractAddress == "" || path == "" {
log.Error("Contract address and datadir are required for remote simulation")
return nil
}
simulation.RunRemoteSimulation(path, contractAddress)
return nil
}
log.Error("Invalid simulation type, exiting")
return nil
}