Skip to content

Commit c6796b8

Browse files
cwgoesebuchman
authored andcommitted
Add --gas flag to specify gas limit for a transaction
1 parent d84296e commit c6796b8

File tree

6 files changed

+14
-2
lines changed

6 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ IMPROVEMENTS
1111

1212
FIXES
1313
* [lcd] Switch to bech32 for addresses on all human readable inputs and outputs
14+
* [cli] Added `--gas` flag to specify transaction gas limit
1415

1516
## 0.18.0
1617

client/context/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *w
114114
ChainID: chainID,
115115
Sequences: []int64{sequence},
116116
Msg: msg,
117-
Fee: auth.NewStdFee(10000, sdk.Coin{}), // TODO run simulate to estimate gas?
117+
Fee: auth.NewStdFee(ctx.Gas, sdk.Coin{}), // TODO run simulate to estimate gas?
118118
}
119119

120120
keybase, err := keys.GetKeyBase()

client/context/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
type CoreContext struct {
1111
ChainID string
1212
Height int64
13+
Gas int64
1314
TrustNode bool
1415
NodeURI string
1516
FromAddressName string
@@ -31,6 +32,12 @@ func (c CoreContext) WithHeight(height int64) CoreContext {
3132
return c
3233
}
3334

35+
// WithGas - return a copy of the context with an updated gas
36+
func (c CoreContext) WithGas(gas int64) CoreContext {
37+
c.Gas = gas
38+
return c
39+
}
40+
3441
// WithTrustNode - return a copy of the context with an updated TrustNode flag
3542
func (c CoreContext) WithTrustNode(trustNode bool) CoreContext {
3643
c.TrustNode = trustNode

client/context/viper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func NewCoreContextFromViper() CoreContext {
3030
return CoreContext{
3131
ChainID: chainID,
3232
Height: viper.GetInt64(client.FlagHeight),
33+
Gas: viper.GetInt64(client.FlagGas),
3334
TrustNode: viper.GetBool(client.FlagTrustNode),
3435
FromAddressName: viper.GetString(client.FlagName),
3536
NodeURI: nodeURI,

client/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const (
77
FlagChainID = "chain-id"
88
FlagNode = "node"
99
FlagHeight = "height"
10+
FlagGas = "gas"
1011
FlagTrustNode = "trust-node"
1112
FlagName = "name"
1213
FlagSequence = "sequence"
@@ -25,6 +26,7 @@ func GetCommands(cmds ...*cobra.Command) []*cobra.Command {
2526
c.Flags().String(FlagChainID, "", "Chain ID of tendermint node")
2627
c.Flags().String(FlagNode, "tcp://localhost:46657", "<host>:<port> to tendermint rpc interface for this chain")
2728
c.Flags().Int64(FlagHeight, 0, "block height to query, omit to get most recent provable block")
29+
c.Flags().Int64(FlagGas, 200000, "gas limit to set per-transaction")
2830
}
2931
return cmds
3032
}

client/lcd/lcd_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222
tmcfg "github.com/tendermint/tendermint/config"
2323
nm "github.com/tendermint/tendermint/node"
2424
p2p "github.com/tendermint/tendermint/p2p"
25+
pvm "github.com/tendermint/tendermint/privval"
2526
"github.com/tendermint/tendermint/proxy"
2627
ctypes "github.com/tendermint/tendermint/rpc/core/types"
2728
tmrpc "github.com/tendermint/tendermint/rpc/lib/server"
2829
tmtypes "github.com/tendermint/tendermint/types"
29-
pvm "github.com/tendermint/tendermint/privval"
3030
"github.com/tendermint/tmlibs/cli"
3131
dbm "github.com/tendermint/tmlibs/db"
3232
"github.com/tendermint/tmlibs/log"
@@ -385,6 +385,7 @@ func startTMAndLCD() (*nm.Node, net.Listener, error) {
385385
return nil, nil, err
386386
}
387387
viper.Set(cli.HomeFlag, dir)
388+
viper.Set(client.FlagGas, 200000)
388389
kb, err := keys.GetKeyBase() // dbm.NewMemDB()) // :(
389390
if err != nil {
390391
return nil, nil, err

0 commit comments

Comments
 (0)