-
Notifications
You must be signed in to change notification settings - Fork 10
/
initconfig.go
61 lines (50 loc) · 1.19 KB
/
initconfig.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
package chari
import (
"errors"
"os"
"strings"
)
const (
defaultConfig string = `
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
proxy_app = "tcp://127.0.0.1:33453"
#moniker = "$moniker"
fast_sync = true
db_backend = "leveldb"
log_level = "state:error,*:error"
[consensus]
create_empty_blocks = false
[rpc]
laddr = "tcp://127.0.0.1:44453"
[p2p]
laddr = "tcp://0.0.0.0:$laddr_port"
seeds = "$seeds"
`
)
const (
proxy_app string = "127.0.0.1:33453"
rpc_laddr string = "tcp://127.0.0.1:44453"
)
func initConfig() error {
if os.Getenv("BFT_P2P_PORT") == "" {
return errors.New("BFT_P2P_PORT not found")
}
if os.Getenv("BFT_P2P_SEEDS") == "" {
return errors.New("BFT_P2P_SEEDS not found")
}
var config string
config = strings.Replace(defaultConfig, "$laddr_port", os.Getenv("BFT_P2P_PORT"), 1)
config = strings.Replace(config, "$seeds", os.Getenv("BFT_P2P_SEEDS"), 1)
file, err := os.OpenFile("/etc/hyperledger/chari/config.toml", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)
if err != nil {
logger.Error(err)
return err
}
defer file.Close()
if _, err = file.WriteString(config); err != nil {
logger.Error(err)
return err
}
return nil
}