-
Notifications
You must be signed in to change notification settings - Fork 72
/
types.go
119 lines (102 loc) · 3.24 KB
/
types.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
package types
import (
"github.com/cosmos/cosmos-sdk/std"
"github.com/forbole/juno/v5/logging"
"github.com/forbole/juno/v5/types/config"
"github.com/forbole/juno/v5/types/params"
"github.com/forbole/juno/v5/database"
"github.com/forbole/juno/v5/database/builder"
"github.com/forbole/juno/v5/modules/registrar"
)
// Config contains all the configuration for the "parse" command
type Config struct {
registrar registrar.Registrar
configParser config.Parser
encodingConfigBuilder EncodingConfigBuilder
setupCfg SdkConfigSetup
buildDb database.Builder
logger logging.Logger
}
// NewConfig allows to build a new Config instance
func NewConfig() *Config {
return &Config{}
}
// WithRegistrar sets the modules registrar to be used
func (cfg *Config) WithRegistrar(r registrar.Registrar) *Config {
cfg.registrar = r
return cfg
}
// GetRegistrar returns the modules registrar to be used
func (cfg *Config) GetRegistrar() registrar.Registrar {
if cfg.registrar == nil {
return ®istrar.EmptyRegistrar{}
}
return cfg.registrar
}
// WithConfigParser sets the configuration parser to be used
func (cfg *Config) WithConfigParser(p config.Parser) *Config {
cfg.configParser = p
return cfg
}
// GetConfigParser returns the configuration parser to be used
func (cfg *Config) GetConfigParser() config.Parser {
if cfg.configParser == nil {
return config.DefaultConfigParser
}
return cfg.configParser
}
// WithEncodingConfigBuilder sets the configurations builder to be used
func (cfg *Config) WithEncodingConfigBuilder(b EncodingConfigBuilder) *Config {
cfg.encodingConfigBuilder = b
return cfg
}
// GetEncodingConfigBuilder returns the encoding config builder to be used
func (cfg *Config) GetEncodingConfigBuilder() EncodingConfigBuilder {
if cfg.encodingConfigBuilder == nil {
return func() params.EncodingConfig {
encodingConfig := params.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
}
return cfg.encodingConfigBuilder
}
// WithSetupConfig sets the SDK setup configurator to be used
func (cfg *Config) WithSetupConfig(s SdkConfigSetup) *Config {
cfg.setupCfg = s
return cfg
}
// GetSetupConfig returns the SDK configuration builder to use
func (cfg *Config) GetSetupConfig() SdkConfigSetup {
if cfg.setupCfg == nil {
return DefaultConfigSetup
}
return cfg.setupCfg
}
// WithDBBuilder sets the database builder to be used
func (cfg *Config) WithDBBuilder(b database.Builder) *Config {
cfg.buildDb = b
return cfg
}
// GetDBBuilder returns the database builder to be used
func (cfg *Config) GetDBBuilder() database.Builder {
if cfg.buildDb == nil {
return builder.Builder
}
return cfg.buildDb
}
// WithLogger sets the logger to be used while parsing the data
func (cfg *Config) WithLogger(logger logging.Logger) *Config {
cfg.logger = logger
return cfg
}
// GetLogger returns the logger to be used when parsing the data
func (cfg *Config) GetLogger() logging.Logger {
if cfg.logger == nil {
return logging.DefaultLogger()
}
return cfg.logger
}