forked from forbole/juno
/
types.go
139 lines (119 loc) · 3.7 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package parse
import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/pylons-tech/juno/logging"
"github.com/pylons-tech/juno/node"
"github.com/pylons-tech/juno/types/config"
"github.com/pylons-tech/juno/database"
"github.com/pylons-tech/juno/database/builder"
"github.com/pylons-tech/juno/modules"
"github.com/pylons-tech/juno/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 simapp.MakeTestEncodingConfig
}
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
}
// --------------------------------------------------------------------------------------------------------------------
// Context contains the parsing context
type Context struct {
EncodingConfig *params.EncodingConfig
Node node.Node
Database database.Database
Logger logging.Logger
Modules []modules.Module
}
// NewContext builds a new Context instance
func NewContext(
encodingConfig *params.EncodingConfig, proxy node.Node, db database.Database,
logger logging.Logger, modules []modules.Module,
) *Context {
return &Context{
EncodingConfig: encodingConfig,
Node: proxy,
Database: db,
Modules: modules,
Logger: logger,
}
}