-
Notifications
You must be signed in to change notification settings - Fork 80
/
config.go
93 lines (76 loc) · 2.2 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
92
93
package config
import (
"strings"
"gopkg.in/yaml.v3"
databaseconfig "github.com/forbole/juno/v6/database/config"
loggingconfig "github.com/forbole/juno/v6/logging/config"
nodeconfig "github.com/forbole/juno/v6/node/config"
parserconfig "github.com/forbole/juno/v6/parser/config"
)
var (
// Cfg represents the configuration to be used during the execution
Cfg Config
)
// Config defines all necessary juno configuration parameters.
type Config struct {
bytes []byte
Chain ChainConfig `yaml:"chain"`
Node nodeconfig.Config `yaml:"node"`
Parser parserconfig.Config `yaml:"parsing"`
Database databaseconfig.Config `yaml:"database"`
Logging loggingconfig.Config `yaml:"logging"`
}
// NewConfig builds a new Config instance
func NewConfig(
nodeCfg nodeconfig.Config,
chainCfg ChainConfig, dbConfig databaseconfig.Config,
parserConfig parserconfig.Config, loggingConfig loggingconfig.Config,
) Config {
return Config{
Node: nodeCfg,
Chain: chainCfg,
Database: dbConfig,
Parser: parserConfig,
Logging: loggingConfig,
}
}
func DefaultConfig() Config {
cfg := NewConfig(
nodeconfig.DefaultConfig(),
DefaultChainConfig(), databaseconfig.DefaultDatabaseConfig(),
parserconfig.DefaultParsingConfig(), loggingconfig.DefaultLoggingConfig(),
)
bz, err := yaml.Marshal(cfg)
if err != nil {
panic(err)
}
cfg.bytes = bz
return cfg
}
func (c Config) GetBytes() ([]byte, error) {
return c.bytes, nil
}
// ---------------------------------------------------------------------------------------------------------------------
type ChainConfig struct {
Bech32Prefix string `yaml:"bech32_prefix"`
Modules []string `yaml:"modules"`
}
// NewChainConfig returns a new ChainConfig instance
func NewChainConfig(bech32Prefix string, modules []string) ChainConfig {
return ChainConfig{
Bech32Prefix: bech32Prefix,
Modules: modules,
}
}
// DefaultChainConfig returns the default instance of ChainConfig
func DefaultChainConfig() ChainConfig {
return NewChainConfig("cosmos", nil)
}
func (cfg ChainConfig) IsModuleEnabled(moduleName string) bool {
for _, module := range cfg.Modules {
if strings.EqualFold(module, moduleName) {
return true
}
}
return false
}