Skip to content

Commit

Permalink
chore: stop using deprecated tendermint spm
Browse files Browse the repository at this point in the history
chore: format and fix linter
  • Loading branch information
Lockwarr committed Dec 22, 2023
1 parent ae55c96 commit 14d9e9f
Show file tree
Hide file tree
Showing 21 changed files with 836 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ linters:
- bidichk
- bodyclose
- contextcheck
- depguard
# - depguard TODO - start using depguard again after fix
- godot
- gofmt
- gofumpt
Expand Down
27 changes: 14 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand All @@ -29,8 +30,6 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/tendermint/spm/cosmoscmd"
"github.com/tendermint/spm/openapiconsole"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
Expand All @@ -39,6 +38,7 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/Nolus-Protocol/nolus-core/app/keepers"
"github.com/Nolus-Protocol/nolus-core/app/openapiconsole"
appparams "github.com/Nolus-Protocol/nolus-core/app/params"
"github.com/Nolus-Protocol/nolus-core/app/upgrades"
v042 "github.com/Nolus-Protocol/nolus-core/app/upgrades/v042"
Expand All @@ -60,8 +60,8 @@ var (
)

var (
_ cosmoscmd.CosmosApp = (*App)(nil)
_ servertypes.Application = (*App)(nil)
_ simapp.App = (*App)(nil)
)

func init() {
Expand All @@ -83,7 +83,7 @@ type App struct {
cdc *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
encodingConfig appparams.EncodingConfig
encodingConfig EncodingConfig
invCheckPeriod uint

// the module manager
Expand All @@ -93,7 +93,7 @@ type App struct {
configurator module.Configurator
}

// New returns a reference to an initialized Gaia.
// New returns a reference to an initialized blockchain app.
func New(
logger log.Logger,
db dbm.DB,
Expand All @@ -102,10 +102,10 @@ func New(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig cosmoscmd.EncodingConfig,
encodingConfig EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) cosmoscmd.App {
) *App {
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand All @@ -117,18 +117,19 @@ func New(

app := &App{
BaseApp: bApp,
AppKeepers: keepers.AppKeepers{},
cdc: cdc,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
encodingConfig: appparams.EncodingConfig(encodingConfig),
encodingConfig: EncodingConfig(encodingConfig),
}

// Setup keepers
app.AppKeepers = keepers.NewAppKeeper(
app.NewAppKeepers(
appCodec,
bApp,
encodingConfig,
encodingConfig.Amino,
encodingConfig.InterfaceRegistry,
maccPerms,
app.BlockedAddrs(),
skipUpgradeHeights,
Expand Down Expand Up @@ -192,8 +193,8 @@ func New(
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
TaxKeeper: app.TaxKeeper,
TxCounterStoreKey: app.AppKeepers.GetKVStoreKey()[wasm.StoreKey],
WasmConfig: &app.AppKeepers.WasmConfig,
TxCounterStoreKey: app.GetKVStoreKey()[wasm.StoreKey],
WasmConfig: &app.WasmConfig,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
IBCKeeper: app.IBCKeeper,
Expand Down
44 changes: 44 additions & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package app

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// makeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func makeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}
}

// MakeEncodingConfig creates an EncodingConfig for testing.
func MakeEncodingConfig(moduleBasics module.BasicManager) EncodingConfig {
encodingConfig := makeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
moduleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
moduleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
18 changes: 7 additions & 11 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down Expand Up @@ -48,8 +49,6 @@ import (
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

"github.com/tendermint/spm/cosmoscmd"

"github.com/Nolus-Protocol/nolus-core/wasmbinding"
mintkeeper "github.com/Nolus-Protocol/nolus-core/x/mint/keeper"
minttypes "github.com/Nolus-Protocol/nolus-core/x/mint/types"
Expand Down Expand Up @@ -182,25 +181,24 @@ type AppKeepers struct {
AuthzModule authzmodule.AppModule
}

func NewAppKeeper(
func (appKeepers *AppKeepers) NewAppKeepers(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
encodingConfig cosmoscmd.EncodingConfig,
cdc *codec.LegacyAmino,
interfaceRegistry codectypes.InterfaceRegistry,
maccPerms map[string][]string,
blockedAddress map[string]bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
appOpts servertypes.AppOptions,
) AppKeepers {
appKeepers := AppKeepers{}

) {
// Set keys KVStoreKey, TransientStoreKey, MemoryStoreKey
appKeepers.GenerateKeys()

appKeepers.ParamsKeeper = initParamsKeeper(
appCodec,
encodingConfig.Amino,
cdc,
appKeepers.keys[paramstypes.StoreKey],
appKeepers.tkeys[paramstypes.TStoreKey],
)
Expand Down Expand Up @@ -480,9 +478,7 @@ func NewAppKeeper(
appCodec,
bApp.MsgServiceRouter(),
)
appKeepers.AuthzModule = authzmodule.NewAppModule(appCodec, appKeepers.AuthzKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper, encodingConfig.InterfaceRegistry)

return appKeepers
appKeepers.AuthzModule = authzmodule.NewAppModule(appCodec, appKeepers.AuthzKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper, interfaceRegistry)
}

// GetSubspace returns a param subspace for a given module name.
Expand Down
4 changes: 2 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var ModuleBasics = module.NewBasicManager(

func appModules(
app *App,
encodingConfig cosmoscmd.EncodingConfig,
encodingConfig EncodingConfig,
skipGenesisInvariants bool,
) []module.AppModule {
appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -179,7 +179,7 @@ func appModules(
// define the order of the modules for deterministic simulations.
func simulationModules(
app *App,
encodingConfig cosmoscmd.EncodingConfig,
encodingConfig EncodingConfig,
_ bool,
) []module.AppModuleSimulation {
appCodec := encodingConfig.Marshaler
Expand Down
25 changes: 25 additions & 0 deletions app/openapiconsole/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package openapiconsole

import (
"embed"
"html/template"
"net/http"
)

//go:embed index.tpl
var index embed.FS

// Handler returns an http handler that servers OpenAPI console for an OpenAPI spec at specURL.
func Handler(title, specURL string) http.HandlerFunc {
t, _ := template.ParseFS(index, "index.tpl")

return func(w http.ResponseWriter, req *http.Request) {
t.Execute(w, struct { //nolint:errcheck
Title string
URL string
}{
title,
specURL,
})
}
}
25 changes: 25 additions & 0 deletions app/openapiconsole/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{{ .Title }}</title>
<link rel="stylesheet" type="text/css" href="//unpkg.com/swagger-ui-dist@3.40.0/swagger-ui.css" />
<link rel="icon" type="image/png" href="//unpkg.com/swagger-ui-dist@3.40.0/favicon-16x16.png" />
</head>
<body>
<div id="swagger-ui"></div>

<script src="//unpkg.com/swagger-ui-dist@3.40.0/swagger-ui-bundle.js"></script>
<script>
// init Swagger for faucet's openapi.yml.
window.onload = function() {
window.ui = SwaggerUIBundle({
url: {{ .URL }},
dom_id: "#swagger-ui",
deepLinking: true,
layout: "BaseLayout",
});
}
</script>
</body>
</html>
16 changes: 0 additions & 16 deletions app/params/encoding.go

This file was deleted.

22 changes: 0 additions & 22 deletions app/params/proto.go

This file was deleted.

Loading

0 comments on commit 14d9e9f

Please sign in to comment.