Newer
Older
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package config
import (
"github.com/eris-ltd/eris-db/files"
"github.com/naoina/toml"
)
// Standard configuration file for the server.
type (
ErisDBConfig struct {
DB DB `toml:"db"`
TMSP TMSP `toml:"tmsp"`
Tendermint Tendermint `toml:"tendermint"`
Server ServerConfig `toml":server"`
}
DB struct {
Backend string `toml:"backend"`
}
TMSP struct {
Listener string `toml:"listener"`
}
Tendermint struct {
Host string `toml:"host"`
}
ServerConfig struct {
Bind Bind `toml:"bind"`
TLS TLS `toml:"TLS"`
CORS CORS `toml:"CORS"`
HTTP HTTP `toml:"HTTP"`
WebSocket WebSocket `toml:"web_socket"`
Logging Logging `toml:"logging"`
}
Bind struct {
Address string `toml:"address"`
Port uint16 `toml:"port"`
}
TLS struct {
TLS bool `toml:"tls"`
CertPath string `toml:"cert_path"`
KeyPath string `toml:"key_path"`
}
// Options stores configurations
CORS struct {
Enable bool `toml:"enable"`
AllowOrigins []string `toml:"allow_origins"`
AllowCredentials bool `toml:"allow_credentials"`
AllowMethods []string `toml:"allow_methods"`
AllowHeaders []string `toml:"allow_headers"`
ExposeHeaders []string `toml:"expose_headers"`
MaxAge uint64 `toml:"max_age"`
}
HTTP struct {
JsonRpcEndpoint string `toml:"json_rpc_endpoint"`
}
WebSocket struct {
WebSocketEndpoint string `toml:"websocket_endpoint"`
MaxWebSocketSessions uint `toml:"max_websocket_sessions"`
ReadBufferSize uint `toml:"read_buffer_size"`
WriteBufferSize uint `toml:"write_buffer_size"`
}
Logging struct {
ConsoleLogLevel string `toml:"console_log_level"`
FileLogLevel string `toml:"file_log_level"`
LogFile string `toml:"log_file"`
VMLog bool `toml:"vm_log"`
}
)
func DefaultServerConfig() ServerConfig {
cp := ""
kp := ""
return ServerConfig{
Bind: Bind{
Address: "",
Port: 1337,
},
TLS: TLS{TLS: false,
CertPath: cp,
KeyPath: kp,
},
CORS: CORS{},
HTTP: HTTP{JsonRpcEndpoint: "/rpc"},
WebSocket: WebSocket{
WebSocketEndpoint: "/socketrpc",
MaxWebSocketSessions: 50,
ReadBufferSize: 4096,
WriteBufferSize: 4096,
},
Logging: Logging{
ConsoleLogLevel: "info",
FileLogLevel: "warn",
LogFile: "",
},
}
}
func DefaultErisDBConfig() *ErisDBConfig {
return &ErisDBConfig{
DB: DB{
Backend: "leveldb",
},
TMSP: TMSP{
Listener: "tcp://0.0.0.0:46658",
},
Tendermint: Tendermint{
Host: "0.0.0.0:46657",
},
Server: DefaultServerConfig(),
}
}
// Read a TOML server configuration file.
func ReadErisDBConfig(filePath string) (*ErisDBConfig, error) {
bts, err := files.ReadFile(filePath)
if err != nil {
return nil, err
}
cfg := &ErisDBConfig{}
err2 := toml.Unmarshal(bts, cfg)
if err2 != nil {
return nil, err2
}
return cfg, nil
}
// Write a server configuration file.
func WriteErisDBConfig(filePath string, cfg *ErisDBConfig) error {
bts, err := toml.Marshal(*cfg)
if err != nil {
return err
}
return files.WriteAndBackup(filePath, bts)
}