Skip to content

Commit

Permalink
fix: add missing tx.go file by default and enable cli if autocli do…
Browse files Browse the repository at this point in the history
…es not exist (#3849)

* add missing tx.go file by default and enable cli if autocli not exist

* add changelog

* add missing imports

* only scaffold `cli/tx.go` if is a ibc module

* move tx.go.plush to right place

* scaffold the function `GetTxCmd` only in a ibc module

* add cobra import to the ibc if

* Update ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani authored Dec 20, 2023
1 parent bbf6931 commit 816a327
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [#3825](https://github.com/ignite/cli/pull/3825) Fix a minor Keplr type-checking bug in TS client
- [#3836](https://github.com/ignite/cli/pull/3836) Add missing IBC commands for scaffolded chain
- [#3833](https://github.com/ignite/cli/pull/3833) Improve Cosmos SDK detection to support SDK forks
- [#3849](https://github.com/ignite/cli/pull/3849) Add missing `tx.go` file by default and enable cli if autocli does not exist
- [#3851](https://github.com/ignite/cli/pull/3851) Add missing ibc interfaces to chain client

## [`v28.0.0`](https://github.com/ignite/cli/releases/tag/v28.0.0)
Expand Down
15 changes: 0 additions & 15 deletions ignite/templates/ibc/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ibc
import (
"embed"
"fmt"
"os"
"path/filepath"

"github.com/emicklei/proto"
Expand Down Expand Up @@ -352,24 +351,10 @@ func protoTxModify(opts *PacketOptions) genny.RunFn {
}
}

//go:embed templates/packet/tx.tpl
var txTemplate string

// clientCliTxModify does not use AutoCLI here, because it as a better UX as it is.
func clientCliTxModify(replacer placeholder.Replacer, opts *PacketOptions) genny.RunFn {
return func(r *genny.Runner) error {
filePath := filepath.Join(opts.AppPath, "x", opts.ModuleName, "client/cli/tx.go")
if _, err := os.Stat(filePath); errors.Is(err, os.ErrNotExist) {
content := fmt.Sprintf(txTemplate, opts.ModulePath, opts.ModuleName)
if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
return err
}

if err := os.WriteFile(filePath, []byte(content), 0o644); err != nil {
return err
}
}

f, err := r.Disk.Find(filePath)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/runtime"
<%= if (isIBC) { %>porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"<% } %>
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
"github.com/spf13/cobra"<% } %>

// this line is used by starport scaffolding # 1

modulev1 "<%= modulePath %>/api/<%= appName %>/<%= moduleName %>/module"
"<%= modulePath %>/x/<%= moduleName %>/keeper"
"<%= modulePath %>/x/<%= moduleName %>/types"
<%= if (isIBC) { %>"<%= modulePath %>/x/<%= moduleName %>/client/cli"<% } %>
)

var (
Expand Down Expand Up @@ -91,12 +93,13 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
}
}

<%= if (isIBC) { %>
// GetTxCmd returns the root Tx command for the module.
// These commands enrich the AutoCLI tx commands.
// When creating non AutoCLI commands, add the following:
// func (a AppModuleBasic) GetTxCmd() *cobra.Command {
// return cli.GetTxCmd()
// }
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
<% } %>

// ----------------------------------------------------------------------------
// AppModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"%s/x/%s/types"
// "github.com/cosmos/cosmos-sdk/client/flags"
"<%= modulePath %>/x/<%= moduleName %>/types"
)

var DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())

const listSeparator = ","

// GetTxCmd returns the transaction commands for this module
// GetTxCmd returns the transaction commands for this module.
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%%s transactions subcommands", types.ModuleName),
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

// this line is used by starport scaffolding # 1

return cmd
}
return cmd
}

0 comments on commit 816a327

Please sign in to comment.