-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrar.go
130 lines (112 loc) · 4.09 KB
/
registrar.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
package modules
import (
"github.com/rarimo/bdjuno/modules/actions"
"github.com/rarimo/bdjuno/modules/bridge"
"github.com/rarimo/bdjuno/modules/multisig"
"github.com/rarimo/bdjuno/modules/oraclemanager"
"github.com/rarimo/bdjuno/modules/rarimocore"
"github.com/rarimo/bdjuno/modules/tokenmanager"
"github.com/rarimo/bdjuno/modules/types"
"github.com/forbole/juno/v4/modules/pruning"
"github.com/forbole/juno/v4/modules/telemetry"
"github.com/rarimo/bdjuno/modules/slashing"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
jmodules "github.com/forbole/juno/v4/modules"
"github.com/forbole/juno/v4/modules/messages"
"github.com/forbole/juno/v4/modules/registrar"
"github.com/rarimo/bdjuno/utils"
"github.com/rarimo/bdjuno/database"
"github.com/rarimo/bdjuno/modules/auth"
"github.com/rarimo/bdjuno/modules/bank"
"github.com/rarimo/bdjuno/modules/consensus"
"github.com/rarimo/bdjuno/modules/distribution"
"github.com/rarimo/bdjuno/modules/feegrant"
"github.com/rarimo/bdjuno/modules/gov"
"github.com/rarimo/bdjuno/modules/mint"
"github.com/rarimo/bdjuno/modules/modules"
"github.com/rarimo/bdjuno/modules/pricefeed"
"github.com/rarimo/bdjuno/modules/staking"
)
// UniqueAddressesParser returns a wrapper around the given parser that removes all duplicated addresses
func UniqueAddressesParser(parser messages.MessageAddressesParser) messages.MessageAddressesParser {
return func(cdc codec.Codec, msg sdk.Msg) ([]string, error) {
addresses, err := parser(cdc, msg)
if err != nil {
return nil, err
}
return utils.RemoveDuplicateValues(addresses), nil
}
}
// --------------------------------------------------------------------------------------------------------------------
var (
_ registrar.Registrar = &Registrar{}
)
// Registrar represents the modules.Registrar that allows to register all modules that are supported by BigDipper
type Registrar struct {
parser messages.MessageAddressesParser
}
// NewRegistrar allows to build a new Registrar instance
func NewRegistrar(parser messages.MessageAddressesParser) *Registrar {
return &Registrar{
parser: UniqueAddressesParser(parser),
}
}
// BuildModules implements modules.Registrar
func (r *Registrar) BuildModules(ctx registrar.Context) jmodules.Modules {
cdc := ctx.EncodingConfig.Codec
db := database.Cast(ctx.Database)
sources, err := types.BuildSources(ctx.JunoConfig.Node, ctx.EncodingConfig)
if err != nil {
panic(err)
}
actionsModule := actions.NewModule(ctx.JunoConfig, ctx.EncodingConfig)
authModule := auth.NewModule(r.parser, cdc, db)
bankModule := bank.NewModule(r.parser, sources.BankSource, cdc, db)
consensusModule := consensus.NewModule(db)
distrModule := distribution.NewModule(sources.DistrSource, cdc, db)
feegrantModule := feegrant.NewModule(cdc, db)
mintModule := mint.NewModule(sources.MintSource, cdc, db)
slashingModule := slashing.NewModule(sources.SlashingSource, cdc, db)
stakingModule := staking.NewModule(sources.StakingSource, cdc, db)
rarimocoreModule := rarimocore.NewModule(sources.RarimoCoreSource, sources.TokenManagerSource, cdc, db)
tokenmanagerModule := tokenmanager.NewModule(sources.TokenManagerSource, cdc, db)
oraclemanagerModule := oraclemanager.NewModule(sources.OracleManagerSource, rarimocoreModule, cdc, db)
bridgeModule := bridge.NewModule(sources.BridgeSource, cdc, db)
govModule := gov.NewModule(
sources.GovSource,
authModule,
distrModule,
mintModule,
slashingModule,
stakingModule,
rarimocoreModule,
tokenmanagerModule,
oraclemanagerModule,
bridgeModule,
cdc,
db,
)
return []jmodules.Module{
messages.NewModule(r.parser, cdc, ctx.Database),
telemetry.NewModule(ctx.JunoConfig),
pruning.NewModule(ctx.JunoConfig, db, ctx.Logger),
actionsModule,
authModule,
bankModule,
consensusModule,
distrModule,
feegrantModule,
govModule,
mintModule,
modules.NewModule(ctx.JunoConfig.Chain, db),
pricefeed.NewModule(ctx.JunoConfig, cdc, db),
slashingModule,
stakingModule,
rarimocoreModule,
tokenmanagerModule,
oraclemanagerModule,
bridgeModule,
multisig.NewModule(sources.MultisigSource, cdc, db, authModule),
}
}