-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
57 lines (47 loc) · 1.02 KB
/
config.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
package main
import (
"errors"
"github.com/artheranet/arthera-node/params"
"github.com/ethereum/go-ethereum/common"
"gopkg.in/urfave/cli.v1"
"github.com/artheranet/perftool/utils/toml"
)
var ConfigFileFlag = cli.StringFlag{
Name: "config",
Usage: "TOML configuration file",
Value: "txgen.toml",
}
type PerfConfig struct {
ChainId int64 // chain id for sign transactions
Payer common.Address
URLs []string // WS nodes API URL
}
func DefaultConfig() *PerfConfig {
return &PerfConfig{
ChainId: int64(params.FakeNetworkID),
URLs: []string{
"ws://127.0.0.1:4500",
},
}
}
func OpenConfig(ctx *cli.Context) *PerfConfig {
cfg := DefaultConfig()
f := ctx.GlobalString(ConfigFileFlag.Name)
err := cfg.Load(f)
if err != nil {
panic(err)
}
return cfg
}
func (cfg *PerfConfig) Load(file string) error {
data, err := toml.ParseFile(file)
if err != nil {
return err
}
err = toml.Settings.UnmarshalTable(data, cfg)
if err != nil {
err = errors.New(file + ", " + err.Error())
return err
}
return nil
}