Skip to content

Commit 2d27589

Browse files
authored
refactor(templates): use wasm from tendermint/spm-extras (#1399)
* refactor(templates): use wasm from tendermint/spm-extras * Update starport/templates/module/import/stargate.go * fix * fix
1 parent 62051fb commit 2d27589

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

starport/pkg/gocmd/gocmd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@ func ParseTarget(t string) (goos, goarch string, err error) {
101101

102102
return parsed[0], parsed[1], nil
103103
}
104+
105+
// PackageLiteral returns the string representation of package part of go get [package].
106+
func PackageLiteral(path, version string) string {
107+
return fmt.Sprintf("%s@%s", path, version)
108+
}

starport/services/scaffolder/module.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ import (
2727
)
2828

2929
const (
30-
wasmImport = "github.com/CosmWasm/wasmd"
31-
appPkg = "app"
32-
moduleDir = "x"
33-
wasmVersion = "v0.16.0"
30+
wasmImport = "github.com/CosmWasm/wasmd"
31+
wasmVersion = "v0.16.0"
32+
extrasImport = "github.com/tendermint/spm-extras"
33+
extrasVersion = "v0.1.0"
34+
appPkg = "app"
35+
moduleDir = "x"
3436
)
3537

3638
// moduleCreationOptions holds options for creating a new module
@@ -290,17 +292,10 @@ func (s *Scaffolder) installWasm() error {
290292
switch s.version {
291293
case cosmosver.StargateZeroFourtyAndAbove:
292294
return cmdrunner.
293-
New(
294-
cmdrunner.DefaultStderr(os.Stderr),
295-
).
295+
New().
296296
Run(context.Background(),
297-
step.New(
298-
step.Exec(
299-
gocmd.Name(),
300-
"get",
301-
wasmImport+"@"+wasmVersion,
302-
),
303-
),
297+
step.New(step.Exec(gocmd.Name(), "get", gocmd.PackageLiteral(wasmImport, wasmVersion))),
298+
step.New(step.Exec(gocmd.Name(), "get", gocmd.PackageLiteral(extrasImport, extrasVersion))),
304299
)
305300
default:
306301
return errors.New("version not supported")

starport/templates/app/stargate/go.mod.plush

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/spf13/cobra v1.1.3
1313
github.com/spf13/pflag v1.0.5
1414
github.com/stretchr/testify v1.7.0
15-
github.com/tendermint/spm v0.1.0
15+
github.com/tendermint/spm v0.1.2
1616
github.com/tendermint/tendermint v0.34.11
1717
github.com/tendermint/tm-db v0.6.4
1818
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced

starport/templates/module/import/stargate.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func appModifyStargate(replacer placeholder.Replacer) genny.RunFn {
3232
}
3333

3434
templateImport := `%[1]v
35+
"github.com/tendermint/spm-extras/wasmcmd"
3536
"github.com/CosmWasm/wasmd/x/wasm"
3637
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"`
3738
replacementImport := fmt.Sprintf(templateImport, module.PlaceholderSgAppModuleImport)
@@ -114,7 +115,7 @@ func appModifyStargate(replacer placeholder.Replacer) genny.RunFn {
114115
)
115116
116117
// The gov proposal types can be individually enabled
117-
enabledProposals := cosmoscmd.GetEnabledProposals(ProposalsEnabled, EnableSpecificProposals)
118+
enabledProposals := wasmcmd.GetEnabledProposals(ProposalsEnabled, EnableSpecificProposals)
118119
if len(enabledProposals) != 0 {
119120
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals))
120121
}`
@@ -150,11 +151,16 @@ func cmdModifyStargate(replacer placeholder.Replacer, opts *ImportOptions) genny
150151
return err
151152
}
152153

153-
templateArgs := `cosmoscmd.WithWasm(),
154+
templateArgs := `cosmoscmd.AddSubCmd(wasmcmd.GenesisWasmMsgCmd(app.DefaultNodeHome)),
155+
cosmoscmd.CustomizeStartCmd(wasmcmd.AddModuleInitFlags),
154156
%[1]v`
155157
replacementArgs := fmt.Sprintf(templateArgs, module.PlaceholderSgRootArgument)
156158
content := replacer.Replace(f.String(), module.PlaceholderSgRootArgument, replacementArgs)
157159

160+
// import spm-extras.
161+
content = replacer.Replace(content, "package main", `package main
162+
import "github.com/tendermint/spm-extras/wasmcmd"`)
163+
158164
newFile := genny.NewFileS(path, content)
159165
return r.File(newFile)
160166
}

0 commit comments

Comments
 (0)