Skip to content

Commit

Permalink
apply some comments suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored and Pantani committed Feb 16, 2024
1 parent 50ea09d commit 6358fe2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 22 deletions.
10 changes: 4 additions & 6 deletions wasm/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ func NewWasmAdd() *cobra.Command {

flagSetPath(c)
flagSetHome(c)
c.Flags().Uint64(flagSimulationGasLimit, 0, "the max gas to be used in a tx simulation call. When not set the consensus max block gas is used instead")
c.Flags().Uint64(flagSmartQueryGasLimit, 3_000_000, "the max gas to be used in a smart query contract call")
c.Flags().Uint32(flagMemoryCacheSize, 100, "memory cache size in MiB not bytes")
flagSetWasmConfigs(c)

return c
}
Expand All @@ -32,9 +30,9 @@ func wasmAddExecuteHandler(cmd *cobra.Command, args []string) error {
defer session.End()

var (
simulationGasLimit, _ = cmd.Flags().GetUint64(flagSimulationGasLimit)
smartQueryGasLimit, _ = cmd.Flags().GetUint64(flagSmartQueryGasLimit)
memoryCacheSize, _ = cmd.Flags().GetUint32(flagMemoryCacheSize)
simulationGasLimit = getSimulationGasLimit(cmd)
smartQueryGasLimit = getSmartQueryGasLimit(cmd)
memoryCacheSize = getMemoryCacheSize(cmd)
)

c, err := newChainWithHomeFlags(cmd, chain.WithOutputer(session), chain.CollectEvents(session.EventBus()))
Expand Down
21 changes: 21 additions & 0 deletions wasm/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func flagSetHome(cmd *cobra.Command) {
cmd.Flags().String(flagHome, "", "directory where the blockchain node is initialized")
}

func flagSetWasmConfigs(cmd *cobra.Command) {
cmd.Flags().Uint64(flagSimulationGasLimit, 0, "the max gas to be used in a tx simulation call. When not set the consensus max block gas is used instead")
cmd.Flags().Uint64(flagSmartQueryGasLimit, 3_000_000, "the max gas to be used in a smart query contract call")
cmd.Flags().Uint64(flagMemoryCacheSize, 100, "memory cache size in MiB not bytes")
}

func getPath(cmd *cobra.Command) string {
path, _ := cmd.Flags().GetString(flagPath)
return path
Expand All @@ -65,6 +71,21 @@ func getHome(cmd *cobra.Command) string {
return home
}

func getSimulationGasLimit(cmd *cobra.Command) uint64 {
simulationGasLimit, _ := cmd.Flags().GetUint64(flagSimulationGasLimit)
return simulationGasLimit
}

func getSmartQueryGasLimit(cmd *cobra.Command) uint64 {
smartQueryGasLimit, _ := cmd.Flags().GetUint64(flagSmartQueryGasLimit)
return smartQueryGasLimit
}

func getMemoryCacheSize(cmd *cobra.Command) uint64 {
memoryCacheSize, _ := cmd.Flags().GetUint64(flagMemoryCacheSize)
return memoryCacheSize
}

// newChainWithHomeFlags create new *chain.Chain with home and path flags.
func newChainWithHomeFlags(cmd *cobra.Command, chainOption ...chain.Option) (*chain.Chain, error) {
// Check if custom home is provided
Expand Down
10 changes: 4 additions & 6 deletions wasm/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func NewWasmConfig() *cobra.Command {

flagSetPath(c)
flagSetHome(c)
c.Flags().Uint64(flagSimulationGasLimit, 0, "the max gas to be used in a tx simulation call. When not set the consensus max block gas is used instead")
c.Flags().Uint64(flagSmartQueryGasLimit, 3_000_000, "the max gas to be used in a smart query contract call")
c.Flags().Uint32(flagMemoryCacheSize, 100, "memory cache size in MiB not bytes")
flagSetWasmConfigs(c)

return c
}
Expand All @@ -44,9 +42,9 @@ func wasmConfigExecuteHandler(cmd *cobra.Command, args []string) error {
defer session.End()

var (
simulationGasLimit, _ = cmd.Flags().GetUint64(flagSimulationGasLimit)
smartQueryGasLimit, _ = cmd.Flags().GetUint64(flagSmartQueryGasLimit)
memoryCacheSize, _ = cmd.Flags().GetUint32(flagMemoryCacheSize)
simulationGasLimit = getSimulationGasLimit(cmd)
smartQueryGasLimit = getSmartQueryGasLimit(cmd)
memoryCacheSize = getMemoryCacheSize(cmd)
)

c, err := newChainWithHomeFlags(cmd, chain.WithOutputer(session), chain.CollectEvents(session.EventBus()))
Expand Down
1 change: 1 addition & 0 deletions wasm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/ignite/cli/v28 v28.2.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.8.0
github.com/spf13/flag v0.0.0-20140426202619-916eaf9e2dc5
github.com/stretchr/testify v1.8.4
)

Expand Down
2 changes: 2 additions & 0 deletions wasm/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,8 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/flag v0.0.0-20140426202619-916eaf9e2dc5 h1:MSrGX3LBRICNbsIQQXymhuetB06NqwUUExAE058qiZY=
github.com/spf13/flag v0.0.0-20140426202619-916eaf9e2dc5/go.mod h1:vQX74tizEmTgaYZBrs2aiI4aQX90WpxfqEM6eFJZ/8k=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
10 changes: 4 additions & 6 deletions wasm/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"fmt"
"os"
"strings"

Expand All @@ -14,7 +13,7 @@ type (
options struct {
simulationGasLimit uint64
smartQueryGasLimit uint64
memoryCacheSize uint32
memoryCacheSize uint64
}
// Option configures the message scaffolding.
Option func(*options)
Expand Down Expand Up @@ -44,7 +43,7 @@ func WithSmartQueryGasLimit(smartQueryGasLimit uint64) Option {
}

// WithMemoryCacheSize provides a memory cache size for the wasm config.
func WithMemoryCacheSize(memoryCacheSize uint32) Option {
func WithMemoryCacheSize(memoryCacheSize uint64) Option {
return func(m *options) {
m.memoryCacheSize = memoryCacheSize
}
Expand Down Expand Up @@ -75,11 +74,10 @@ func AddWasm(configPath string, options ...Option) error {
config.SimulationGasLimit = &opts.simulationGasLimit
}
config.SmartQueryGasLimit = opts.smartQueryGasLimit
config.MemoryCacheSize = opts.memoryCacheSize
config.MemoryCacheSize = uint32(opts.memoryCacheSize)

// Save new configs to the TOML file.
wasmConfig := fmt.Sprintf("%s", wasmtypes.ConfigTemplate(config))
if _, err = f.WriteString(wasmConfig); err != nil {
if _, err = f.WriteString(wasmtypes.ConfigTemplate(config)); err != nil {
return err
}

Expand Down
5 changes: 3 additions & 2 deletions wasm/pkg/goanalysis/goanalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"go/format"
"go/parser"
"go/token"
"strconv"
"strings"

"github.com/ignite/cli/v28/ignite/pkg/errors"
Expand Down Expand Up @@ -64,7 +65,7 @@ func AppendImports(fileContent string, importStatements ...string) (modifiedCont
}

// Check if the import already exists.
if _, ok := existImports[`"`+importRepo+`"`]; ok {
if _, ok := existImports[strconv.Quote(importRepo)]; ok {
continue
}
// Create a new import spec.
Expand All @@ -74,7 +75,7 @@ func AppendImports(fileContent string, importStatements ...string) (modifiedCont
},
Path: &ast.BasicLit{
Kind: token.STRING,
Value: `"` + importRepo + `"`,
Value: strconv.Quote(importRepo),
},
}
importDecl.Specs = append(importDecl.Specs, spec)
Expand Down
4 changes: 2 additions & 2 deletions wasm/services/scaffolder/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type (
wasmOptions struct {
simulationGasLimit uint64
smartQueryGasLimit uint64
memoryCacheSize uint32
memoryCacheSize uint64
}
// WasmOption configures the message scaffolding.
WasmOption func(*wasmOptions)
Expand Down Expand Up @@ -51,7 +51,7 @@ func WithSmartQueryGasLimit(smartQueryGasLimit uint64) WasmOption {
}

// WithMemoryCacheSize provides a memory cache size for the wasm config.
func WithMemoryCacheSize(memoryCacheSize uint32) WasmOption {
func WithMemoryCacheSize(memoryCacheSize uint64) WasmOption {
return func(m *wasmOptions) {
m.memoryCacheSize = memoryCacheSize
}
Expand Down

0 comments on commit 6358fe2

Please sign in to comment.