Skip to content

Commit

Permalink
refactor: remove simapp dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoM committed Aug 28, 2023
1 parent 507db5d commit c75730c
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 123 deletions.
58 changes: 56 additions & 2 deletions cmd/parse/types/sdk.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
package types

import (
"cosmossdk.io/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/capability"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/mint"
nftmodule "github.com/cosmos/cosmos-sdk/x/nft/module"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"

"github.com/forbole/juno/v5/types/config"
appparams "github.com/forbole/juno/v5/types/params"
)

// SdkConfigSetup represents a method that allows to customize the given sdk.Config.
Expand Down Expand Up @@ -32,4 +56,34 @@ func DefaultConfigSetup(cfg config.Config, sdkConfig *sdk.Config) {
// -----------------------------------------------------------------

// EncodingConfigBuilder represents a function that is used to return the proper encoding config.
type EncodingConfigBuilder func() params.EncodingConfig
type EncodingConfigBuilder func() appparams.EncodingConfig

var (
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
},
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
authzmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
nftmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
)
)
8 changes: 4 additions & 4 deletions cmd/parse/types/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func GetParserContext(cfg config.Config, parseConfig *Config) (*parser.Context,
}

// Get the db
databaseCtx := database.NewContext(cfg.Database, &encodingConfig, parseConfig.GetLogger())
databaseCtx := database.NewContext(cfg.Database, encodingConfig, parseConfig.GetLogger())
db, err := parseConfig.GetDBBuilder()(databaseCtx)
if err != nil {
return nil, err
}

// Init the client
cp, err := nodebuilder.BuildNode(cfg.Node, &encodingConfig)
cp, err := nodebuilder.BuildNode(cfg.Node, encodingConfig)
if err != nil {
return nil, fmt.Errorf("failed to start client: %s", err)
}
Expand All @@ -53,11 +53,11 @@ func GetParserContext(cfg config.Config, parseConfig *Config) (*parser.Context,
}

// Get the modules
context := modsregistrar.NewContext(cfg, sdkConfig, &encodingConfig, db, cp, parseConfig.GetLogger())
context := modsregistrar.NewContext(cfg, sdkConfig, encodingConfig, db, cp, parseConfig.GetLogger())
mods := parseConfig.GetRegistrar().BuildModules(context)
registeredModules := modsregistrar.GetModules(mods, cfg.Chain.Modules, parseConfig.GetLogger())

return parser.NewContext(&encodingConfig, cp, db, parseConfig.GetLogger(), registeredModules), nil
return parser.NewContext(encodingConfig, cp, db, parseConfig.GetLogger(), registeredModules), nil
}

// getConfig returns the SDK Config instance as well as if it's sealed or not
Expand Down
11 changes: 5 additions & 6 deletions cmd/parse/types/types.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package types

import (
"cosmossdk.io/simapp"
simappparams "cosmossdk.io/simapp/params"
"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"
Expand Down Expand Up @@ -65,12 +64,12 @@ func (cfg *Config) WithEncodingConfigBuilder(b EncodingConfigBuilder) *Config {
// GetEncodingConfigBuilder returns the encoding config builder to be used
func (cfg *Config) GetEncodingConfigBuilder() EncodingConfigBuilder {
if cfg.encodingConfigBuilder == nil {
return func() simappparams.EncodingConfig {
encodingConfig := simappparams.MakeTestEncodingConfig()
return func() params.EncodingConfig {
encodingConfig := params.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
simapp.ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
simapp.ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
}
Expand Down
7 changes: 3 additions & 4 deletions database/database.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package database

import (
"cosmossdk.io/simapp/params"

"github.com/forbole/juno/v5/logging"
"github.com/forbole/juno/v5/types/params"

databaseconfig "github.com/forbole/juno/v5/database/config"

Expand Down Expand Up @@ -71,12 +70,12 @@ type PruningDb interface {
// Context contains the data that might be used to build a Database instance
type Context struct {
Cfg databaseconfig.Config
EncodingConfig *params.EncodingConfig
EncodingConfig params.EncodingConfig
Logger logging.Logger
}

// NewContext allows to build a new Context instance
func NewContext(cfg databaseconfig.Config, encodingConfig *params.EncodingConfig, logger logging.Logger) *Context {
func NewContext(cfg databaseconfig.Config, encodingConfig params.EncodingConfig, logger logging.Logger) *Context {
return &Context{
Cfg: cfg,
EncodingConfig: encodingConfig,
Expand Down
4 changes: 2 additions & 2 deletions database/postgresql/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"strings"
"testing"

"cosmossdk.io/simapp/params"
"github.com/stretchr/testify/suite"

"github.com/forbole/juno/v5/database"
databaseconfig "github.com/forbole/juno/v5/database/config"
postgres "github.com/forbole/juno/v5/database/postgresql"
"github.com/forbole/juno/v5/logging"
"github.com/forbole/juno/v5/types/params"
)

func TestDatabaseTestSuite(t *testing.T) {
Expand All @@ -36,7 +36,7 @@ func (suite *DbTestSuite) SetupTest() {
WithURL("postgres://bdjuno:password@localhost:6433/bdjuno?sslmode=disable&search_path=public")

// Build the database
db, err := postgres.Builder(database.NewContext(dbCfg, &codec, logging.DefaultLogger()))
db, err := postgres.Builder(database.NewContext(dbCfg, codec, logging.DefaultLogger()))
suite.Require().NoError(err)

bigDipperDb, ok := (db).(*postgres.Database)
Expand Down
64 changes: 32 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ module github.com/forbole/juno/v5
go 1.20

require (
cosmossdk.io/simapp v0.0.0-20230224204036-a6adb0821462
github.com/cometbft/cometbft v0.37.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.7.0
github.com/cosmos/cosmos-sdk v0.47.2
github.com/cosmos/gogoproto v1.4.8
github.com/cosmos/cosmos-sdk v0.47.4
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.0.1
github.com/go-co-op/gocron v1.13.0
github.com/golangci/golangci-lint v1.52.2
github.com/gorilla/mux v1.8.0
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.7
github.com/prometheus/client_golang v1.14.0
github.com/rs/zerolog v1.27.0
github.com/rs/zerolog v1.29.1
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
google.golang.org/grpc v1.54.0
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.56.2
gopkg.in/yaml.v3 v3.0.1
)

require (
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
4d63.com/gochecknoglobals v0.2.1 // indirect
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.12.0 // indirect
cloud.google.com/go/storage v1.29.0 // indirect
cloud.google.com/go/iam v1.1.0 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.0 // indirect
cosmossdk.io/errors v1.0.0 // indirect
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect
cosmossdk.io/math v1.0.1 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down Expand Up @@ -137,9 +137,10 @@ require (
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down Expand Up @@ -171,7 +172,6 @@ require (
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/julz/importas v0.1.0 // indirect
github.com/junk1tm/musttag v0.5.0 // indirect
github.com/kisielk/errcheck v1.6.3 // indirect
Expand All @@ -192,7 +192,7 @@ require (
github.com/maratori/testpackage v1.1.1 // indirect
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mbilski/exhaustivestruct v1.2.0 // indirect
Expand All @@ -202,8 +202,6 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/moricho/tparallel v0.3.1 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/nakabonne/nestif v0.3.1 // indirect
Expand All @@ -212,13 +210,13 @@ require (
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nunnatsa/ginkgolinter v0.9.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/petermattis/goid v0.0.0-20221215004737-a150e88a970d // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polyfloyd/go-errorlint v1.4.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.40.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/quasilyte/go-ruleguard v0.3.19 // indirect
github.com/quasilyte/gogrep v0.5.0 // indirect
Expand Down Expand Up @@ -275,22 +273,24 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
golang.org/x/exp/typeparams v0.0.0-20230224173230-c95f2b4c22f2 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230216225411-c8e22ba71e44 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
honnef.co/go/tools v0.4.3 // indirect
Expand Down
Loading

0 comments on commit c75730c

Please sign in to comment.