Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve transactions and messages storing #2

Merged
merged 11 commits into from
Apr 4, 2024
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
if: "env.GIT_DIFF != ''"
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"

- name: Run lint ✅
if: "env.GIT_DIFF != ''"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"

- name: Compute diff 📜
uses: technote-space/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# To exit the bash, just execute
# > exit
FROM golang:alpine AS build-env
FROM golang:1.21-alpine AS build-env

# Set up dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev py-pip
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ clean:

stop-docker-test:
@echo "Stopping Docker container..."
@docker stop bdjuno-test-db || true && docker rm bdjuno-test-db || true
@docker stop juno-test-db || true && docker rm juno-test-db || true
.PHONY: stop-docker-test

start-docker-test: stop-docker-test
@echo "Starting Docker container..."
@docker run --name bdjuno-test-db -e POSTGRES_USER=bdjuno -e POSTGRES_PASSWORD=password -e POSTGRES_DB=bdjuno -d -p 6433:5432 postgres
@docker run --name juno-test-db -e POSTGRES_USER=juno -e POSTGRES_PASSWORD=password -e POSTGRES_DB=juno -d -p 6433:5432 postgres
.PHONY: start-docker-test

coverage:
Expand Down
9 changes: 2 additions & 7 deletions cmd/juno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ package main
import (
"os"

"github.com/forbole/juno/v5/cmd"
"github.com/forbole/juno/v5/cmd/parse/types"

"github.com/forbole/juno/v5/modules/messages"
"github.com/forbole/juno/v5/modules/registrar"

"github.com/forbole/juno/v5/cmd"
)

func main() {
// JunoConfig the runner
config := cmd.NewConfig("juno").
WithParseConfig(types.NewConfig().
WithRegistrar(registrar.NewDefaultRegistrar(
messages.CosmosMessageAddressesParser,
)),
WithRegistrar(registrar.NewDefaultRegistrar()),
)

// Run the commands and panic on any error
Expand Down
6 changes: 1 addition & 5 deletions cmd/migrate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import (
parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types"

"github.com/spf13/cobra"

v4 "github.com/forbole/juno/v5/cmd/migrate/v4"
)

type Migrator func(parseCfg *parsecmdtypes.Config) error

var (
migrations = map[string]Migrator{
"v4": v4.RunMigration,
}
migrations = map[string]Migrator{}
)

func getVersions() []string {
Expand Down
39 changes: 0 additions & 39 deletions cmd/migrate/v3/types.go

This file was deleted.

30 changes: 0 additions & 30 deletions cmd/migrate/v3/utils.go

This file was deleted.

83 changes: 0 additions & 83 deletions cmd/migrate/v4/migrate.go

This file was deleted.

27 changes: 0 additions & 27 deletions cmd/migrate/v4/types.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/parse/blocks/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types"
"github.com/forbole/juno/v5/types/utils"
"github.com/forbole/juno/v5/utils"

"github.com/rs/zerolog/log"

Expand Down
2 changes: 1 addition & 1 deletion cmd/parse/genesis/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"github.com/spf13/cobra"

parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types"
"github.com/forbole/juno/v5/utils"

"github.com/forbole/juno/v5/modules"
nodeconfig "github.com/forbole/juno/v5/node/config"
"github.com/forbole/juno/v5/types/utils"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/parse/types/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"

appparams "github.com/forbole/juno/v5/types"
"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
35 changes: 28 additions & 7 deletions cmd/parse/types/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (

// GetParserContext setups all the things that can be used to later parse the chain state
func GetParserContext(cfg config.Config, parseConfig *Config) (*parser.Context, error) {
accountAddressParser := parseConfig.GetAccountAddressParser()
transactionFilter := parseConfig.GetTransactionFilter()
messageFilter := parseConfig.GetMessageFilterBuilder()(cfg)
logger := parseConfig.GetLogger()

// Build the codec
encodingConfig := parseConfig.GetEncodingConfigBuilder()()

Expand All @@ -29,35 +34,51 @@ 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,
logger,
accountAddressParser,
transactionFilter,
messageFilter,
)
db, err := parseConfig.GetDBBuilder()(databaseCtx)
if err != nil {
return nil, err
}

// Init the client
cp, err := nodebuilder.BuildNode(cfg.Node, encodingConfig)
nodeCtx := nodebuilder.NewContext(encodingConfig, accountAddressParser)
node, err := nodebuilder.BuildNode(cfg.Node, nodeCtx)
if err != nil {
return nil, fmt.Errorf("failed to start client: %s", err)
}

// Setup the logging
err = parseConfig.GetLogger().SetLogFormat(cfg.Logging.LogFormat)
err = logger.SetLogFormat(cfg.Logging.LogFormat)
if err != nil {
return nil, fmt.Errorf("error while setting logging format: %s", err)
}

err = parseConfig.GetLogger().SetLogLevel(cfg.Logging.LogLevel)
err = logger.SetLogLevel(cfg.Logging.LogLevel)
if err != nil {
return nil, fmt.Errorf("error while setting logging level: %s", err)
}

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

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

// getConfig returns the SDK Config instance as well as if it's sealed or not
Expand Down
Loading
Loading