-
Notifications
You must be signed in to change notification settings - Fork 16
/
config.go
54 lines (45 loc) · 1.09 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
package ethproviders
import "strings"
type Config map[string]NetworkConfig
type NetworkConfig struct {
ID uint64 `toml:"id" json:"id"`
URL string `toml:"url" json:"url"`
WSEnabled bool `toml:"ws_enabled" json:"wsEnabled"`
WSURL string `toml:"ws_url" json:"wsUrl"`
AuthChain bool `toml:"auth_chain" json:"authChain"`
Testnet bool `toml:"testnet" json:"testnet"`
Disabled bool `toml:"disabled" json:"disabled"`
}
func (n Config) GetByID(id uint64) (NetworkConfig, bool) {
for _, v := range n {
if v.ID == id {
return v, true
}
}
return NetworkConfig{}, false
}
func (n Config) GetByName(name string) (NetworkConfig, bool) {
name = strings.ToLower(name)
for k, v := range n {
if k == name {
return v, true
}
}
return NetworkConfig{}, false
}
func (n Config) AuthChain() (NetworkConfig, bool) {
for _, v := range n {
if v.AuthChain && !v.Testnet {
return v, true
}
}
return NetworkConfig{}, false
}
func (n Config) TestAuthChain() (NetworkConfig, bool) {
for _, v := range n {
if v.AuthChain && v.Testnet {
return v, true
}
}
return NetworkConfig{}, false
}