From d47b7cf5fa822daca1f0a4afcdbd372a4d8348dc Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Sat, 9 Jun 2018 06:44:08 +0200 Subject: [PATCH] Add --gas flag to specify gas limit for a transaction --- CHANGELOG.md | 1 + client/context/helpers.go | 2 +- client/context/types.go | 7 +++++++ client/context/viper.go | 1 + client/flags.go | 2 ++ client/lcd/lcd_test.go | 3 ++- 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79432a9713..71a8faa626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ IMPROVEMENTS FIXES * [lcd] Switch to bech32 for addresses on all human readable inputs and outputs +* [cli] Added `--gas` flag to specify transaction gas limit ## 0.18.0 diff --git a/client/context/helpers.go b/client/context/helpers.go index f47cc7ff41..880c4adb37 100644 --- a/client/context/helpers.go +++ b/client/context/helpers.go @@ -114,7 +114,7 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *w ChainID: chainID, Sequences: []int64{sequence}, Msg: msg, - Fee: auth.NewStdFee(10000, sdk.Coin{}), // TODO run simulate to estimate gas? + Fee: auth.NewStdFee(ctx.Gas, sdk.Coin{}), // TODO run simulate to estimate gas? } keybase, err := keys.GetKeyBase() diff --git a/client/context/types.go b/client/context/types.go index da15b32936..e9c97ffbc7 100644 --- a/client/context/types.go +++ b/client/context/types.go @@ -10,6 +10,7 @@ import ( type CoreContext struct { ChainID string Height int64 + Gas int64 TrustNode bool NodeURI string FromAddressName string @@ -31,6 +32,12 @@ func (c CoreContext) WithHeight(height int64) CoreContext { return c } +// WithGas - return a copy of the context with an updated gas +func (c CoreContext) WithGas(gas int64) CoreContext { + c.Gas = gas + return c +} + // WithTrustNode - return a copy of the context with an updated TrustNode flag func (c CoreContext) WithTrustNode(trustNode bool) CoreContext { c.TrustNode = trustNode diff --git a/client/context/viper.go b/client/context/viper.go index 4b3007f12a..081c9f5c28 100644 --- a/client/context/viper.go +++ b/client/context/viper.go @@ -30,6 +30,7 @@ func NewCoreContextFromViper() CoreContext { return CoreContext{ ChainID: chainID, Height: viper.GetInt64(client.FlagHeight), + Gas: viper.GetInt64(client.FlagGas), TrustNode: viper.GetBool(client.FlagTrustNode), FromAddressName: viper.GetString(client.FlagName), NodeURI: nodeURI, diff --git a/client/flags.go b/client/flags.go index ceaf5a3a9d..aacd4ba1d3 100644 --- a/client/flags.go +++ b/client/flags.go @@ -7,6 +7,7 @@ const ( FlagChainID = "chain-id" FlagNode = "node" FlagHeight = "height" + FlagGas = "gas" FlagTrustNode = "trust-node" FlagName = "name" FlagSequence = "sequence" @@ -25,6 +26,7 @@ func GetCommands(cmds ...*cobra.Command) []*cobra.Command { c.Flags().String(FlagChainID, "", "Chain ID of tendermint node") c.Flags().String(FlagNode, "tcp://localhost:46657", ": to tendermint rpc interface for this chain") c.Flags().Int64(FlagHeight, 0, "block height to query, omit to get most recent provable block") + c.Flags().Int64(FlagGas, 200000, "gas limit to set per-transaction") } return cmds } diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 076b422625..59f5b24646 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -22,11 +22,11 @@ import ( tmcfg "github.com/tendermint/tendermint/config" nm "github.com/tendermint/tendermint/node" p2p "github.com/tendermint/tendermint/p2p" + pvm "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" ctypes "github.com/tendermint/tendermint/rpc/core/types" tmrpc "github.com/tendermint/tendermint/rpc/lib/server" tmtypes "github.com/tendermint/tendermint/types" - pvm "github.com/tendermint/tendermint/privval" "github.com/tendermint/tmlibs/cli" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" @@ -392,6 +392,7 @@ func startTMAndLCD() (*nm.Node, net.Listener, error) { return nil, nil, err } viper.Set(cli.HomeFlag, dir) + viper.Set(client.FlagGas, 200000) kb, err := keys.GetKeyBase() // dbm.NewMemDB()) // :( if err != nil { return nil, nil, err