-
Notifications
You must be signed in to change notification settings - Fork 19
/
config.go
91 lines (76 loc) · 2.73 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
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
package client
import (
"fmt"
)
type Chain struct {
ID string `name:"id" json:"id" yaml:"id"`
Name string `name:"name" json:"name" yaml:"name"`
NumValidators int `name:"num-validators" json:"num_validators" yaml:"numValidators"`
Ports Port `name:"ports" json:"ports" yaml:"ports"`
Upgrade Upgrade `name:"upgrade" json:"upgrade" yaml:"upgrade"`
}
func (c *Chain) GetRPCAddr() string {
return fmt.Sprintf("http://localhost:%d", c.Ports.Rpc)
}
func (c *Chain) GetRESTAddr() string {
return fmt.Sprintf("http://localhost:%d", c.Ports.Rest)
}
type Upgrade struct {
Enabled bool `name:"eanbled" json:"enabled" yaml:"enabled"`
Type string `name:"type" json:"type" yaml:"type"`
Genesis string `name:"genesis" json:"genesis" yaml:"genesis"`
Upgrades []struct {
Name string `name:"name" json:"name" yaml:"name"`
Version string `name:"version" json:"version" yaml:"version"`
} `name:"upgrades" json:"upgrades" yaml:"upgrades"`
}
type Port struct {
Rest int `name:"rest" json:"rest" yaml:"rest"`
Rpc int `name:"rpc" json:"rpc" yaml:"rpc"`
Grpc int `name:"grpc" json:"grpc" yaml:"grpc"`
Exposer int `name:"exposer" json:"exposer" yaml:"exposer"`
}
type Relayer struct {
Name string `name:"name" json:"name" yaml:"name"`
Type string `name:"type" json:"type" yaml:"type"`
Replicas int `name:"replicas" json:"replicas" yaml:"replicas"`
Chains []string `name:"chains" json:"chains" yaml:"chains"`
}
type Feature struct {
Enabled bool `name:"enabled" json:"enabled" yaml:"enabled"`
Image string `name:"image" json:"image" yaml:"image"`
Ports Port `name:"ports" json:"ports" yaml:"ports"`
}
func (f *Feature) GetRPCAddr() string {
return fmt.Sprintf("http://localhost:%d", f.Ports.Rpc)
}
func (f *Feature) GetRESTAddr() string {
return fmt.Sprintf("http://localhost:%d", f.Ports.Rest)
}
// Config is the struct for the config.yaml setup file
// todo: move this to a more common place, outside just tests
// todo: can be moved to proto defination
type Config struct {
Chains []*Chain `name:"chains" json:"chains" yaml:"chains"`
Relayers []*Relayer `name:"relayers" json:"relayers" yaml:"relayers"`
Explorer *Feature `name:"explorer" json:"explorer" yaml:"explorer"`
Registry *Feature `name:"registry" json:"registry" yaml:"registry"`
}
// HasChainId returns true if chain id found in list of chains
func (c *Config) HasChainId(chainId string) bool {
for _, chain := range c.Chains {
if chain.ID == chainId {
return true
}
}
return false
}
// GetChain returns the Chain object pointer for the given chain id
func (c *Config) GetChain(chainId string) *Chain {
for _, chain := range c.Chains {
if chain.ID == chainId {
return chain
}
}
return nil
}