Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Oct 19, 2023
1 parent 7441f20 commit 50fa2fe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
50 changes: 43 additions & 7 deletions ignite/templates/ibc/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package ibc

import (
"embed"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/emicklei/proto"
Expand Down Expand Up @@ -349,21 +351,55 @@ func protoTxModify(opts *PacketOptions) genny.RunFn {
// 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 {
// TODO
// create tx.go if not exist
// add send command
// edit module.go to a tx command on app module basic
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(`package cli
import (
"fmt"
"time"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"%s/x/%s/types"
)
var DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
// 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),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
// this line is used by starport scaffolding # 1
return cmd
}`, opts.ModulePath, opts.ModuleName) // TODO to improve, probably with a template that does not get copied over directly.

if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
return err
}

path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "client/cli/tx.go")
f, err := r.Disk.Find(path)
if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {

Check failure on line 389 in ignite/templates/ibc/packet.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gofumpt`-ed (gofumpt)
return err
}
}

f, err := r.Disk.Find(filePath)
if err != nil {
return err
}
template := `cmd.AddCommand(CmdSend%[2]v())
%[1]v`
replacement := fmt.Sprintf(template, Placeholder, opts.PacketName.UpperCamel)
content := replacer.Replace(f.String(), Placeholder, replacement)
newFile := genny.NewFileS(path, content)
newFile := genny.NewFileS(filePath, content)
return r.File(newFile)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ignite/templates/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func clientCliTxModify(replacer placeholder.Replacer, opts *Options) genny.RunFn
template := `{
RpcMethod: "%[2]v",
Use: "%[3]v",
Short: "%[4]v",
Short: "Send a %[4]v tx",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{%[5]s},
},
Expand Down

0 comments on commit 50fa2fe

Please sign in to comment.