Merge pull request #1182 from cosmos/cwgoes/max-gas-flag

Add --gas flag to specify gas limit for a transaction
This commit is contained in:
Rigel 2018-06-09 15:44:50 -07:00 committed by GitHub
commit 3fc7200f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 2 deletions

View File

@ -12,6 +12,7 @@ IMPROVEMENTS
FIXES FIXES
* [lcd] Switch to bech32 for addresses on all human readable inputs and outputs * [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 ## 0.18.0

View File

@ -114,7 +114,7 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *w
ChainID: chainID, ChainID: chainID,
Sequences: []int64{sequence}, Sequences: []int64{sequence},
Msg: msg, 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() keybase, err := keys.GetKeyBase()

View File

@ -10,6 +10,7 @@ import (
type CoreContext struct { type CoreContext struct {
ChainID string ChainID string
Height int64 Height int64
Gas int64
TrustNode bool TrustNode bool
NodeURI string NodeURI string
FromAddressName string FromAddressName string
@ -31,6 +32,12 @@ func (c CoreContext) WithHeight(height int64) CoreContext {
return c 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 // WithTrustNode - return a copy of the context with an updated TrustNode flag
func (c CoreContext) WithTrustNode(trustNode bool) CoreContext { func (c CoreContext) WithTrustNode(trustNode bool) CoreContext {
c.TrustNode = trustNode c.TrustNode = trustNode

View File

@ -30,6 +30,7 @@ func NewCoreContextFromViper() CoreContext {
return CoreContext{ return CoreContext{
ChainID: chainID, ChainID: chainID,
Height: viper.GetInt64(client.FlagHeight), Height: viper.GetInt64(client.FlagHeight),
Gas: viper.GetInt64(client.FlagGas),
TrustNode: viper.GetBool(client.FlagTrustNode), TrustNode: viper.GetBool(client.FlagTrustNode),
FromAddressName: viper.GetString(client.FlagName), FromAddressName: viper.GetString(client.FlagName),
NodeURI: nodeURI, NodeURI: nodeURI,

View File

@ -7,6 +7,7 @@ const (
FlagChainID = "chain-id" FlagChainID = "chain-id"
FlagNode = "node" FlagNode = "node"
FlagHeight = "height" FlagHeight = "height"
FlagGas = "gas"
FlagTrustNode = "trust-node" FlagTrustNode = "trust-node"
FlagName = "name" FlagName = "name"
FlagSequence = "sequence" FlagSequence = "sequence"
@ -37,6 +38,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
c.Flags().String(FlagFee, "", "Fee to pay along with transaction") c.Flags().String(FlagFee, "", "Fee to pay along with transaction")
c.Flags().String(FlagChainID, "", "Chain ID of tendermint node") c.Flags().String(FlagChainID, "", "Chain ID of tendermint node")
c.Flags().String(FlagNode, "tcp://localhost:46657", "<host>:<port> to tendermint rpc interface for this chain") c.Flags().String(FlagNode, "tcp://localhost:46657", "<host>:<port> to tendermint rpc interface for this chain")
c.Flags().Int64(FlagGas, 200000, "gas limit to set per-transaction")
} }
return cmds return cmds
} }

View File

@ -22,11 +22,11 @@ import (
tmcfg "github.com/tendermint/tendermint/config" tmcfg "github.com/tendermint/tendermint/config"
nm "github.com/tendermint/tendermint/node" nm "github.com/tendermint/tendermint/node"
p2p "github.com/tendermint/tendermint/p2p" p2p "github.com/tendermint/tendermint/p2p"
pvm "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
tmrpc "github.com/tendermint/tendermint/rpc/lib/server" tmrpc "github.com/tendermint/tendermint/rpc/lib/server"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
pvm "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tmlibs/cli"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tmlibs/log"
@ -392,6 +392,7 @@ func startTMAndLCD() (*nm.Node, net.Listener, error) {
return nil, nil, err return nil, nil, err
} }
viper.Set(cli.HomeFlag, dir) viper.Set(cli.HomeFlag, dir)
viper.Set(client.FlagGas, 200000)
kb, err := keys.GetKeyBase() // dbm.NewMemDB()) // :( kb, err := keys.GetKeyBase() // dbm.NewMemDB()) // :(
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err