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

chore: autocli #80

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simapp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,6 @@ testnet-basic: setup-testnet
spawn local-ic start testnet

sh-testnet:
CHAIN_ID="local-1" HOME_DIR="~/.simapp" BLOCK_TIME="1000ms" CLEAN=true sh scripts/test_node.sh
CHAIN_ID="local-1" BLOCK_TIME="1000ms" CLEAN=true sh scripts/test_node.sh

.PHONY: testnet testnet-basic sh-testnet
31 changes: 17 additions & 14 deletions simapp/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
signingtype "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -439,20 +442,20 @@ func NewChainApp(
logger,
)

// optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper)
// enabledSignModes := append(tx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
// txConfigOpts := tx.ConfigOptions{
// EnabledSignModes: enabledSignModes,
// TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
// }
// txConfig, err := tx.NewTxConfigWithOptions(
// appCodec,
// txConfigOpts,
// )
// if err != nil {
// panic(err)
// }
// app.txConfig = txConfig
// enable sign mode textual by overwriting the default tx config (after setting the bank keeper)
enabledSignModes := append(tx.DefaultSignModes, signingtype.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}
txConfig, err = tx.NewTxConfigWithOptions(
appCodec,
txConfigOpts,
)
if err != nil {
panic(err)
}
app.txConfig = txConfig

app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
Expand Down
11 changes: 9 additions & 2 deletions simapp/scripts/test_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ alias BINARY="$BINARY --home=$HOME_DIR"
command -v $BINARY > /dev/null 2>&1 || { echo >&2 "$BINARY command not found. Ensure this is setup / properly installed in your GOPATH (make install)."; exit 1; }
command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; }

$BINARY config set client chain-id $CHAIN_ID
$BINARY config set client keyring-backend $KEYRING
set_config() {
$BINARY config set client chain-id $CHAIN_ID
$BINARY config set client keyring-backend $KEYRING
}
set_config


from_scratch () {
# Fresh install on current branch
Expand All @@ -51,6 +55,9 @@ from_scratch () {
fi
rm -rf $HOME_DIR && echo "Removed $HOME_DIR"

# reset values if not set already after whipe
set_config

add_key() {
key=$1
mnemonic=$2
Expand Down
31 changes: 31 additions & 0 deletions simapp/x/example/autocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package module

import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
modulev1 "github.com/strangelove-ventures/simapp/api/example/v1"
)

// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: modulev1.Query_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Params",
Use: "params",
Short: "Query the current consensus parameters",
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: modulev1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "UpdateParams",
Skip: false, // set to true if authority gated
},
},
},
}
}
2 changes: 2 additions & 0 deletions simapp/x/example/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/strangelove-ventures/simapp/x/example/types"
)

// !NOTE: Must enable in module.go (disabled in favor of autocli.go)

func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: types.ModuleName,
Expand Down
2 changes: 2 additions & 0 deletions simapp/x/example/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/strangelove-ventures/simapp/x/example/types"
)

// !NOTE: Must enable in module.go (disabled in favor of autocli.go)

// NewTxCmd returns a root CLI command handler for certain modules
// transaction commands.
func NewTxCmd() *cobra.Command {
Expand Down
26 changes: 4 additions & 22 deletions simapp/x/example/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

abci "github.com/cometbft/cometbft/abci/types"

Expand All @@ -19,14 +18,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/strangelove-ventures/simapp/x/example/client/cli"
"github.com/strangelove-ventures/simapp/x/example/keeper"
"github.com/strangelove-ventures/simapp/x/example/types"

// this line is used by starport scaffolding # 1

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
examplev1 "github.com/strangelove-ventures/simapp/api/example/v1"
)

const (
Expand All @@ -41,9 +35,7 @@ var (
_ module.AppModuleGenesis = AppModule{}
_ module.AppModule = AppModule{}

_ autocli.HasAutoCLIConfig = AppModule{}
_ autocli.HasCustomQueryCommand = AppModule{}
_ autocli.HasCustomTxCommand = AppModule{}
_ autocli.HasAutoCLIConfig = AppModule{}
)

// AppModuleBasic defines the basic application module used by the wasm module.
Expand Down Expand Up @@ -101,26 +93,16 @@ func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux
}
}

// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: examplev1.Query_ServiceDesc.ServiceName,
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: examplev1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{},
},
}
}

// Disable in favor of autocli.go. If you wish to use these, it will override AutoCLI methods.
/*
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

func (a AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
*/

func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
Expand Down
3 changes: 3 additions & 0 deletions spawn/file_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (fc *FileContent) ReplaceTestNodeScript(cfg *NewChainConfig) {
fc.ReplaceAll("export BINARY=${BINARY:-wasmd}", fmt.Sprintf("export BINARY=${BINARY:-%s}", cfg.BinDaemon))
fc.ReplaceAll("export DENOM=${DENOM:-token}", fmt.Sprintf("export DENOM=${DENOM:-%s}", cfg.Denom))

fc.ReplaceAll(`export HOME_DIR=$(eval echo "${HOME_DIR:-"~/.simapp"}")`, fmt.Sprintf(`export HOME_DIR=$(eval echo "${HOME_DIR:-"~/%s"}")`, cfg.HomeDir))
fc.ReplaceAll(`HOME_DIR="~/.simapp"`, fmt.Sprintf(`HOME_DIR="~/%s"`, cfg.HomeDir))

fc.FindAndReplaceAddressBech32("wasm", cfg.Bech32Prefix)
}
}
Expand Down
Loading