From d47b7cf5fa822daca1f0a4afcdbd372a4d8348dc Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Sat, 9 Jun 2018 06:44:08 +0200 Subject: [PATCH 1/2] 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 79432a971..71a8faa62 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 f47cc7ff4..880c4adb3 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 da15b3293..e9c97ffbc 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 4b3007f12..081c9f5c2 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 ceaf5a3a9..aacd4ba1d 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 076b42262..59f5b2464 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 From c08a3fec04b1b931153c4db2b3da3481ace8b4c6 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Sat, 9 Jun 2018 01:04:40 -0700 Subject: [PATCH 2/2] lawl viper --- client/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/flags.go b/client/flags.go index aacd4ba1d..2d68d3146 100644 --- a/client/flags.go +++ b/client/flags.go @@ -26,7 +26,6 @@ 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 } @@ -39,6 +38,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command { c.Flags().String(FlagFee, "", "Fee to pay along with transaction") 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(FlagGas, 200000, "gas limit to set per-transaction") } return cmds }