-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (40 loc) · 917 Bytes
/
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
package main
import (
"encoding/hex"
"errors"
"flag"
"fmt"
space_evm "space/evm"
"strconv"
)
func parseFlags(bytecode string, gas string) ([]byte, uint64, error) {
if bytecode == "" {
return nil, 0, errors.New("missing flag --bytecode")
}
gasLimit, err := strconv.Atoi(gas)
if err != nil {
return nil, 0, errors.New("gas should be a valid decimal")
}
code, err := hex.DecodeString(bytecode)
if err != nil {
return nil, 0, err
}
return code, uint64(gasLimit), nil
}
func main() {
// bytecode required, gas optional
var (
bytecode string
gas string
)
flag.StringVar(&bytecode, "bytecode", "", "bytecode to be executed")
flag.StringVar(&gas, "gas", "1000000000", "gas limit for the execution")
flag.Parse()
code, gasLimit, err := parseFlags(bytecode, gas)
if err != nil {
fmt.Println(err)
return
}
evm := space_evm.NewEVM(space_evm.Moon)
evm.RunCode(code, gasLimit)
}