-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevm-utils.go
76 lines (63 loc) · 1.68 KB
/
evm-utils.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
package main
import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"sync"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/node"
)
func makePasswordList(passwordFile string) []string {
text, err := ioutil.ReadFile(passwordFile)
if err != nil {
utils.Fatalf("Failed to read password file: %v", err)
}
lines := strings.Split(string(text), "\n")
// Sanitise DOS line endings.
for i := range lines {
lines[i] = strings.TrimRight(lines[i], "\r")
}
return lines
}
func accountCreate(dir string, password string, wg *sync.WaitGroup) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.Mkdir(dir, 0700)
if err != nil {
panic(err)
}
}
cfg := node.DefaultConfig
cfg.Name = "ftm"
cfg.HTTPModules = append(cfg.HTTPModules, "eth", "shh")
cfg.WSModules = append(cfg.WSModules, "eth", "shh")
cfg.IPCPath = "geth.ipc"
scryptN := keystore.StandardScryptN
scryptP := keystore.StandardScryptP
address, err := keystore.StoreKey(path.Join(dir, "keystore"), password, scryptN, scryptP)
if err != nil {
utils.Fatalf("Failed to create account: %v", err)
}
addr := fmt.Sprintf("%x", address)
err = ioutil.WriteFile(path.Join(dir, "evm-address"), []byte(addr), 0600)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(path.Join(dir, "pwd.txt"), []byte(password), 0600)
if err != nil {
panic(err)
}
evmlFile, err := os.Create(path.Join(dir, "evml.toml"))
if err != nil {
panic(err)
}
if _, err := fmt.Fprint(evmlFile, "[lachesis]\nstore = true\nheartbeat = \"50ms\"\ntimeout = \"200ms\"\n"); err != nil {
panic(err)
}
wg.Done()
if err := evmlFile.Close(); err != nil {
panic(err)
}
}