Skip to content

Commit

Permalink
feat(cli): add --wasm-dir flag to start command (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs47 authored Feb 28, 2024
1 parent 4a0d1d7 commit a30eae9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
8 changes: 7 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func NewAxelarApp(
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
wasmDir string,
invCheckPeriod uint,
encodingConfig axelarParams.EncodingConfig,
appOpts servertypes.AppOptions,
Expand Down Expand Up @@ -255,7 +256,12 @@ func NewAxelarApp(
SetKeeper(keepers, initAxelarIBCKeeper(keepers))

if IsWasmEnabled() {
SetKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, appOpts, wasmOpts, homePath))
if wasmDir == "" {
dbDir := cast.ToString(appOpts.Get("db_dir"))
wasmDir = filepath.Join(homePath, dbDir, "wasm")
}

SetKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, appOpts, wasmOpts, wasmDir))
SetKeeper(keepers, initWasmContractKeeper(keepers))

// set the contract keeper for the Ics20WasmHooks
Expand Down
1 change: 1 addition & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestNewAxelarApp(t *testing.T) {
true,
nil,
"",
"",
0,
app.MakeEncodingConfig(),
simapp.EmptyAppOptions{},
Expand Down
4 changes: 1 addition & 3 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"fmt"
"path/filepath"
"reflect"
"strings"

Expand Down Expand Up @@ -162,8 +161,7 @@ func InitStakingKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, ke
return &stakingK
}

func initWasmKeeper(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *KeeperCache, bApp *bam.BaseApp, appOpts types.AppOptions, wasmOpts []wasm.Option, homePath string) *wasm.Keeper {
wasmDir := filepath.Join(homePath, "wasm")
func initWasmKeeper(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *KeeperCache, bApp *bam.BaseApp, appOpts types.AppOptions, wasmOpts []wasm.Option, wasmDir string) *wasm.Keeper {
wasmConfig := mustReadWasmConfig(appOpts)

// The last arguments can contain custom message handlers, and custom query handlers,
Expand Down
16 changes: 13 additions & 3 deletions cmd/axelard/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ import (
axelarnet "github.com/axelarnetwork/axelar-core/x/axelarnet/exported"
)

var minGasPrice = "0.007" + axelarnet.NativeAsset
var (
minGasPrice = "0.007" + axelarnet.NativeAsset
wasmDirFlag = "wasm-dir"
)

// NewRootCmd creates a new root command for axelard. It is called once in the
// main function.
Expand Down Expand Up @@ -201,7 +204,12 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
SetGenesisAuthCmd(app.DefaultNodeHome),
)

server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, export(encodingConfig), crisis.AddModuleInitFlags)
starterFlags := func(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
startCmd.Flags().String(wasmDirFlag, "", "path to the wasm directory, by default set to 'wasm' directory inside the '--db_dir' directory")
}

server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, export(encodingConfig), starterFlags)

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
Expand Down Expand Up @@ -264,6 +272,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
return app.NewAxelarApp(
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToString(appOpts.Get(wasmDirFlag)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
app.MakeEncodingConfig(),
appOpts,
Expand Down Expand Up @@ -291,7 +300,8 @@ func export(encCfg params.EncodingConfig) servertypes.AppExporter {
return servertypes.ExportedApp{}, errors.New("application home not set")
}

aApp := app.NewAxelarApp(logger, db, traceStore, height == -1, map[int64]bool{}, homePath,
wasmdir := cast.ToString(appOpts.Get(wasmDirFlag))
aApp := app.NewAxelarApp(logger, db, traceStore, height == -1, map[int64]bool{}, homePath, wasmdir,
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encCfg, appOpts, []wasm.Option{})
if height != -1 {
if err := aApp.LoadHeight(height); err != nil {
Expand Down
1 change: 1 addition & 0 deletions docs/cli/axelard_start.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a30eae9

Please sign in to comment.