/
hermes_config.go
174 lines (156 loc) · 4.36 KB
/
hermes_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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package hermes
import (
"fmt"
"strconv"
"strings"
)
// NewConfig returns a hermes Config with an entry for each of the provided ChainConfigs.
// The defaults were adapted from the sample config file found here: https://github.com/informalsystems/hermes/blob/master/config.toml
func NewConfig(chainConfigs ...ChainConfig) Config {
var chains []Chain
for _, hermesCfg := range chainConfigs {
chainCfg := hermesCfg.cfg
gasPricesStr, err := strconv.ParseFloat(strings.ReplaceAll(chainCfg.GasPrices, chainCfg.Denom, ""), 32)
if err != nil {
panic(err)
}
chains = append(chains, Chain{
ID: chainCfg.ChainID,
RPCAddr: hermesCfg.rpcAddr,
GrpcAddr: fmt.Sprintf("http://%s", hermesCfg.grpcAddr),
WebsocketAddr: strings.ReplaceAll(fmt.Sprintf("%s/websocket", hermesCfg.rpcAddr), "http", "ws"),
RPCTimeout: "10s",
AccountPrefix: chainCfg.Bech32Prefix,
KeyName: hermesCfg.keyName,
AddressType: AddressType{
Derivation: "cosmos",
},
StorePrefix: "ibc",
DefaultGas: 100000,
MaxGas: 400000,
GasPrice: GasPrice{
Price: gasPricesStr,
Denom: chainCfg.Denom,
},
GasMultiplier: chainCfg.GasAdjustment,
MaxMsgNum: 30,
MaxTxSize: 2097152,
ClockDrift: "5s",
MaxBlockTime: "30s",
TrustingPeriod: "14days",
TrustThreshold: TrustThreshold{
Numerator: "1",
Denominator: "3",
},
MemoPrefix: "hermes",
},
)
}
return Config{
Global: Global{
LogLevel: "info",
},
Mode: Mode{
Clients: Clients{
Enabled: true,
Refresh: true,
Misbehaviour: true,
},
Connections: Connections{
Enabled: true,
},
Channels: Channels{
Enabled: true,
},
Packets: Packets{
Enabled: true,
ClearInterval: 0,
ClearOnStart: true,
TxConfirmation: false,
},
},
Rest: Rest{
Enabled: false,
},
Telemetry: Telemetry{
Enabled: false,
},
Chains: chains,
}
}
type Config struct {
Global Global `toml:"global"`
Mode Mode `toml:"mode"`
Rest Rest `toml:"rest"`
Telemetry Telemetry `toml:"telemetry"`
Chains []Chain `toml:"chains"`
}
type Global struct {
LogLevel string `toml:"log_level"`
}
type Clients struct {
Enabled bool `toml:"enabled"`
Refresh bool `toml:"refresh"`
Misbehaviour bool `toml:"misbehaviour"`
}
type Connections struct {
Enabled bool `toml:"enabled"`
}
type Channels struct {
Enabled bool `toml:"enabled"`
}
type Packets struct {
Enabled bool `toml:"enabled"`
ClearInterval int `toml:"clear_interval"`
ClearOnStart bool `toml:"clear_on_start"`
TxConfirmation bool `toml:"tx_confirmation"`
}
type Mode struct {
Clients Clients `toml:"clients"`
Connections Connections `toml:"connections"`
Channels Channels `toml:"channels"`
Packets Packets `toml:"packets"`
}
type Rest struct {
Enabled bool `toml:"enabled"`
Host string `toml:"host"`
Port int `toml:"port"`
}
type Telemetry struct {
Enabled bool `toml:"enabled"`
Host string `toml:"host"`
Port int `toml:"port"`
}
type AddressType struct {
Derivation string `toml:"derivation"`
}
type GasPrice struct {
Price float64 `toml:"price"`
Denom string `toml:"denom"`
}
type TrustThreshold struct {
Numerator string `toml:"numerator"`
Denominator string `toml:"denominator"`
}
type Chain struct {
ID string `toml:"id"`
RPCAddr string `toml:"rpc_addr"`
GrpcAddr string `toml:"grpc_addr"`
WebsocketAddr string `toml:"websocket_addr"`
RPCTimeout string `toml:"rpc_timeout"`
AccountPrefix string `toml:"account_prefix"`
KeyName string `toml:"key_name"`
AddressType AddressType `toml:"address_type"`
StorePrefix string `toml:"store_prefix"`
DefaultGas int `toml:"default_gas"`
MaxGas int `toml:"max_gas"`
GasPrice GasPrice `toml:"gas_price"`
GasMultiplier float64 `toml:"gas_multiplier"`
MaxMsgNum int `toml:"max_msg_num"`
MaxTxSize int `toml:"max_tx_size"`
ClockDrift string `toml:"clock_drift"`
MaxBlockTime string `toml:"max_block_time"`
TrustingPeriod string `toml:"trusting_period"`
TrustThreshold TrustThreshold `toml:"trust_threshold"`
MemoPrefix string `toml:"memo_prefix,omitempty"`
}