2019-05-28 01:44:04 -07:00
package flags
2018-02-23 01:49:30 -08:00
2018-09-11 17:31:30 -07:00
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
2019-05-28 01:44:04 -07:00
tmcli "github.com/tendermint/tendermint/libs/cli"
2020-01-22 09:54:56 -08:00
2020-03-25 08:20:36 -07:00
"github.com/cosmos/cosmos-sdk/crypto/keyring"
2018-09-11 17:31:30 -07:00
)
2018-02-23 01:49:30 -08:00
const (
2019-02-04 15:35:12 -08:00
// DefaultGasAdjustment is applied to gas estimates to avoid tx execution
// failures due to state changes that might occur between the tx simulation
// and the actual run.
2018-08-31 10:04:11 -07:00
DefaultGasAdjustment = 1.0
2018-08-31 10:04:42 -07:00
DefaultGasLimit = 200000
2018-12-20 11:21:07 -08:00
GasFlagAuto = "auto"
2018-08-22 04:38:55 -07:00
2019-12-11 01:45:26 -08:00
// DefaultKeyringBackend
2020-03-25 08:20:36 -07:00
DefaultKeyringBackend = keyring . BackendOS
2019-12-11 01:45:26 -08:00
2019-03-25 17:54:23 -07:00
// BroadcastBlock defines a tx broadcasting mode where the client waits for
// the tx to be committed in a block.
BroadcastBlock = "block"
// BroadcastSync defines a tx broadcasting mode where the client waits for
// a CheckTx execution response only.
BroadcastSync = "sync"
// BroadcastAsync defines a tx broadcasting mode where the client returns
// immediately.
BroadcastAsync = "async"
2020-12-11 05:54:50 -08:00
// SignModeDirect is the value of the --sign-mode flag for SIGN_MODE_DIRECT
SignModeDirect = "direct"
// SignModeLegacyAminoJSON is the value of the --sign-mode flag for SIGN_MODE_LEGACY_AMINO_JSON
SignModeLegacyAminoJSON = "amino-json"
2020-01-30 07:13:42 -08:00
)
2019-03-25 17:54:23 -07:00
2020-01-30 07:13:42 -08:00
// List of CLI flags
const (
2020-06-15 10:39:09 -07:00
FlagHome = tmcli . HomeFlag
2020-10-08 10:41:35 -07:00
FlagKeyringDir = "keyring-dir"
2020-06-15 10:39:09 -07:00
FlagUseLedger = "ledger"
FlagChainID = "chain-id"
FlagNode = "node"
FlagHeight = "height"
FlagGasAdjustment = "gas-adjustment"
FlagFrom = "from"
FlagName = "name"
FlagAccountNumber = "account-number"
FlagSequence = "sequence"
2021-05-04 02:00:54 -07:00
FlagNote = "note"
2020-06-15 10:39:09 -07:00
FlagFees = "fees"
2020-07-11 01:13:46 -07:00
FlagGas = "gas"
2020-06-15 10:39:09 -07:00
FlagGasPrices = "gas-prices"
FlagBroadcastMode = "broadcast-mode"
FlagDryRun = "dry-run"
FlagGenerateOnly = "generate-only"
FlagOffline = "offline"
FlagOutputDocument = "output-document" // inspired by wget -O
FlagSkipConfirmation = "yes"
FlagProve = "prove"
FlagKeyringBackend = "keyring-backend"
FlagPage = "page"
FlagLimit = "limit"
2020-06-16 12:57:37 -07:00
FlagSignMode = "sign-mode"
2020-07-17 08:23:42 -07:00
FlagPageKey = "page-key"
FlagOffset = "offset"
FlagCountTotal = "count-total"
2020-08-07 16:32:22 -07:00
FlagTimeoutHeight = "timeout-height"
2020-08-12 01:34:10 -07:00
FlagKeyAlgorithm = "algo"
Add fee grant module (#8061)
* Add docs
* Add BasicFeeAllowance implementation
* Add expiration structs and complete basic fee
* Add delegation messages, add validation logic
* Add keeper and helper structs
* Add alias and handler to top level
* Add delegation module
* Add basic querier
* Add types tests
* Add types tests
* More internal test coverage
* Solid internal test coverage
* Expose Querier to top level module
* Add FeeAccount to auth/types, like StdTx, SignDoc
* Fix all tests in x/auth
* All tests pass
* Appease the Golang Linter
* Add fee-account command line flag
* Start on DelegatedDeductFeeDecorator
* Cleanup the Decorator
* Wire up delegation module in simapp
* add basic test for decorator (no delegation)
* Table tests for deduct fees
* Table tests over all conditions of delegated fee decorator
* Build full ante handler stack and test it
* Start genesis
* Implement Genesis
* Rename package delegation to subkeys
* Clarify antes test cases, handle empty account w/o fees
* Allow paying delegated fees with no account
* Pull mempool into delegated ante, for control on StdFee
* Use custom DelegatedTx, DelegatedFee for subkeys
* Revert all changes to x/auth.StdTx
* Appease scopelint
* Register DelegatedTx with codec
* Address PR comments
* Remove unnecessary DelegatedMempoolFeeDecorator
* Cleaned up errors in querier
* Clean up message sign bytes
* Minor PR comments
* Replace GetAllFees... with Iterator variants
* PrepareForExport adjusts grant expiration height
* Panic on de/serialization error in keeper
* Move custom ante handler chain to tests, update docs
* More cleanup
* More doc cleanup
* Renamed subkeys module to fee_grant
* Rename subkeys/delegation to fee grant in all strings
* Modify Msg and Keeper methods to use Grant not Delegate
* Add PeriodicFeeAllowance
* Update aliases
* Cover all accept cases for PeriodicFeeAllowance
* Et tu scopelint?
* Update docs as requested
* Remove error return from GetFeeGrant
* Code cleanup as requested by PR
* Updated all errors to use new sdk/errors package
* Use test suite for keeper tests
* Clean up alias.go file
* Define expected interfaces in exported, rather than importing from account
* Remove dependency on auth/ante
* Improve godoc, Logger
* Cleaned up ExpiresAt
* Improve error reporting with UseGrantedFee
* Enforce period limit subset of basic limit
* Add events
* Rename fee_grant to feegrant
* Ensure KeeperTestSuite actually runs
* Move types/tx to types
* Update alias file, include ante
* I do need nolint in alias.go
* Properly emit events in the handler. Use cosmos-sdk in amino types
* Update godoc
* Linting...
* Update errors
* Update pkg doc and fix ante-handler order
* Merge PR #5782: Migrate x/feegrant to proto
* fix errors
* proto changes
* proto changes
* fix errors
* fix errors
* genesis state changed to proto
* fix keeper tests
* fix test
* fixed tests
* fix tests
* updated expected keepers
* updated ante tests
* lint
* deleted alias.go
* tx updated to proto tx
* remove explicit signmode
* tests
* Added `cli/query.go`
* Added tx.go in cli
* updated `module.go`
* resolve errors in tx.go
* Add fee payer gentx func
* updated tx
* fixed error
* WIP: cli tests
* fix query error
* fix tests
* Unused types and funcs
* fix tests
* rename helper func to create tx
* remove unused
* update tx cfg
* fix cli tests
* added simulations
* Add `decoder.go`
* fix build fail
* added init genesis code
* update tx.go
* fixed LGTM alert
* modified cli
* remove gogoproto extensions
* change acc address type to string
* lint
* fix simulations
* Add gen simulations
* remove legacy querier
* remove legacy code
* add grpc queries tests
* fix simulations
* update module.go
* lint
* register feegrant NewSimulationManager
* fix sims
* fix sims
* add genesis test
* add periodic grant
* updated cmd
* changed times
* updated flags
* removed days as period clock
* added condition for period and exp
* add periodic fee cli tests
* udpated tests
* fix lint
* fix tests
* fix sims
* renaming to `fee_grant`
* review changes
* fix test
* add condition for duplicate grants
* fix tests
* add `genTxWithFeeGranter` in tests
* fix simulation
* one of changes & test fixes
* fix test
* fix lint
* changed package name `feegrant` to `fee_grant`
* review comments
* review changes
* review change
* review changes
* added fee-account in flags
* address review changes
* read fee granter from cli
* updated create account with mnemonic
* Address review comments
* move `simapp/ante` file to `feegrant/ante`
* update keeper logic to create account
* update docs
* fix tests
* update `serviceMsgClientConn` from `msgservice`
* review changes
* add test case for using more fees than allowed
* eliminate panic checks from keeper
* fix lint
* change store keys string to bytes
* fix tests
* review changes
* review changes
* udpate docs
* make spend limit optional
* fix tests
* fix tests
* review changes
* add norace tag
* proto-docs
* add docs
Co-authored-by: Ethan Frey <ethanfrey@users.noreply.github.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: SaReN <sahithnarahari@gmail.com>
Co-authored-by: aleem1413 <aleem@vitwit.com>
Co-authored-by: MD Aleem <72057206+aleem1314@users.noreply.github.com>
Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-01-29 11:54:51 -08:00
FlagFeeAccount = "fee-account"
2021-03-23 02:28:20 -07:00
FlagReverse = "reverse"
2020-12-03 15:17:21 -08:00
// Tendermint logging flags
FlagLogLevel = "log_level"
FlagLogFormat = "log_format"
2018-02-23 01:49:30 -08:00
)
2018-02-23 02:25:25 -08:00
// LineBreak can be included in a command list to provide a blank line
// to help with readability
2020-07-11 01:13:46 -07:00
var LineBreak = & cobra . Command { Run : func ( * cobra . Command , [ ] string ) { } }
2018-02-23 02:25:25 -08:00
2020-07-10 12:59:26 -07:00
// AddQueryFlagsToCmd adds common flags to a module query command.
func AddQueryFlagsToCmd ( cmd * cobra . Command ) {
cmd . Flags ( ) . String ( FlagNode , "tcp://localhost:26657" , "<host>:<port> to Tendermint RPC interface for this chain" )
cmd . Flags ( ) . Int64 ( FlagHeight , 0 , "Use a specific height to query state at (this can error if the node is pruning state)" )
cmd . Flags ( ) . StringP ( tmcli . OutputFlag , "o" , "text" , "Output format (text|json)" )
cmd . MarkFlagRequired ( FlagChainID )
}
// AddTxFlagsToCmd adds common flags to a module tx command.
func AddTxFlagsToCmd ( cmd * cobra . Command ) {
2021-07-26 07:13:41 -07:00
cmd . Flags ( ) . StringP ( tmcli . OutputFlag , "o" , "json" , "Output format (text|json)" )
2020-10-08 10:41:35 -07:00
cmd . Flags ( ) . String ( FlagKeyringDir , "" , "The client Keyring directory; if omitted, the default 'home' directory will be used" )
2020-07-10 12:59:26 -07:00
cmd . Flags ( ) . String ( FlagFrom , "" , "Name or address of private key with which to sign" )
cmd . Flags ( ) . Uint64P ( FlagAccountNumber , "a" , 0 , "The account number of the signing account (offline mode only)" )
cmd . Flags ( ) . Uint64P ( FlagSequence , "s" , 0 , "The sequence number of the signing account (offline mode only)" )
2021-06-02 06:50:59 -07:00
cmd . Flags ( ) . String ( FlagNote , "" , "Note to add a description to the transaction (previously --memo)" )
2020-07-10 12:59:26 -07:00
cmd . Flags ( ) . String ( FlagFees , "" , "Fees to pay along with transaction; eg: 10uatom" )
2020-07-13 05:36:34 -07:00
cmd . Flags ( ) . String ( FlagGasPrices , "" , "Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)" )
2020-07-10 12:59:26 -07:00
cmd . Flags ( ) . String ( FlagNode , "tcp://localhost:26657" , "<host>:<port> to tendermint rpc interface for this chain" )
cmd . Flags ( ) . Bool ( FlagUseLedger , false , "Use a connected Ledger device" )
cmd . Flags ( ) . Float64 ( FlagGasAdjustment , DefaultGasAdjustment , "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored " )
cmd . Flags ( ) . StringP ( FlagBroadcastMode , "b" , BroadcastSync , "Transaction broadcasting mode (sync|async|block)" )
cmd . Flags ( ) . Bool ( FlagDryRun , false , "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it" )
cmd . Flags ( ) . Bool ( FlagGenerateOnly , false , "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase is not accessible)" )
2021-07-13 03:22:37 -07:00
cmd . Flags ( ) . Bool ( FlagOffline , false , "Offline mode (does not allow any online functionality)" )
2020-07-10 12:59:26 -07:00
cmd . Flags ( ) . BoolP ( FlagSkipConfirmation , "y" , false , "Skip tx broadcasting prompt confirmation" )
2021-03-11 07:17:43 -08:00
cmd . Flags ( ) . String ( FlagKeyringBackend , DefaultKeyringBackend , "Select keyring's backend (os|file|kwallet|pass|test|memory)" )
2020-07-10 12:59:26 -07:00
cmd . Flags ( ) . String ( FlagSignMode , "" , "Choose sign mode (direct|amino-json), this is an advanced feature" )
2020-08-07 16:32:22 -07:00
cmd . Flags ( ) . Uint64 ( FlagTimeoutHeight , 0 , "Set a block timeout height to prevent the tx from being committed past a certain height" )
Add fee grant module (#8061)
* Add docs
* Add BasicFeeAllowance implementation
* Add expiration structs and complete basic fee
* Add delegation messages, add validation logic
* Add keeper and helper structs
* Add alias and handler to top level
* Add delegation module
* Add basic querier
* Add types tests
* Add types tests
* More internal test coverage
* Solid internal test coverage
* Expose Querier to top level module
* Add FeeAccount to auth/types, like StdTx, SignDoc
* Fix all tests in x/auth
* All tests pass
* Appease the Golang Linter
* Add fee-account command line flag
* Start on DelegatedDeductFeeDecorator
* Cleanup the Decorator
* Wire up delegation module in simapp
* add basic test for decorator (no delegation)
* Table tests for deduct fees
* Table tests over all conditions of delegated fee decorator
* Build full ante handler stack and test it
* Start genesis
* Implement Genesis
* Rename package delegation to subkeys
* Clarify antes test cases, handle empty account w/o fees
* Allow paying delegated fees with no account
* Pull mempool into delegated ante, for control on StdFee
* Use custom DelegatedTx, DelegatedFee for subkeys
* Revert all changes to x/auth.StdTx
* Appease scopelint
* Register DelegatedTx with codec
* Address PR comments
* Remove unnecessary DelegatedMempoolFeeDecorator
* Cleaned up errors in querier
* Clean up message sign bytes
* Minor PR comments
* Replace GetAllFees... with Iterator variants
* PrepareForExport adjusts grant expiration height
* Panic on de/serialization error in keeper
* Move custom ante handler chain to tests, update docs
* More cleanup
* More doc cleanup
* Renamed subkeys module to fee_grant
* Rename subkeys/delegation to fee grant in all strings
* Modify Msg and Keeper methods to use Grant not Delegate
* Add PeriodicFeeAllowance
* Update aliases
* Cover all accept cases for PeriodicFeeAllowance
* Et tu scopelint?
* Update docs as requested
* Remove error return from GetFeeGrant
* Code cleanup as requested by PR
* Updated all errors to use new sdk/errors package
* Use test suite for keeper tests
* Clean up alias.go file
* Define expected interfaces in exported, rather than importing from account
* Remove dependency on auth/ante
* Improve godoc, Logger
* Cleaned up ExpiresAt
* Improve error reporting with UseGrantedFee
* Enforce period limit subset of basic limit
* Add events
* Rename fee_grant to feegrant
* Ensure KeeperTestSuite actually runs
* Move types/tx to types
* Update alias file, include ante
* I do need nolint in alias.go
* Properly emit events in the handler. Use cosmos-sdk in amino types
* Update godoc
* Linting...
* Update errors
* Update pkg doc and fix ante-handler order
* Merge PR #5782: Migrate x/feegrant to proto
* fix errors
* proto changes
* proto changes
* fix errors
* fix errors
* genesis state changed to proto
* fix keeper tests
* fix test
* fixed tests
* fix tests
* updated expected keepers
* updated ante tests
* lint
* deleted alias.go
* tx updated to proto tx
* remove explicit signmode
* tests
* Added `cli/query.go`
* Added tx.go in cli
* updated `module.go`
* resolve errors in tx.go
* Add fee payer gentx func
* updated tx
* fixed error
* WIP: cli tests
* fix query error
* fix tests
* Unused types and funcs
* fix tests
* rename helper func to create tx
* remove unused
* update tx cfg
* fix cli tests
* added simulations
* Add `decoder.go`
* fix build fail
* added init genesis code
* update tx.go
* fixed LGTM alert
* modified cli
* remove gogoproto extensions
* change acc address type to string
* lint
* fix simulations
* Add gen simulations
* remove legacy querier
* remove legacy code
* add grpc queries tests
* fix simulations
* update module.go
* lint
* register feegrant NewSimulationManager
* fix sims
* fix sims
* add genesis test
* add periodic grant
* updated cmd
* changed times
* updated flags
* removed days as period clock
* added condition for period and exp
* add periodic fee cli tests
* udpated tests
* fix lint
* fix tests
* fix sims
* renaming to `fee_grant`
* review changes
* fix test
* add condition for duplicate grants
* fix tests
* add `genTxWithFeeGranter` in tests
* fix simulation
* one of changes & test fixes
* fix test
* fix lint
* changed package name `feegrant` to `fee_grant`
* review comments
* review changes
* review change
* review changes
* added fee-account in flags
* address review changes
* read fee granter from cli
* updated create account with mnemonic
* Address review comments
* move `simapp/ante` file to `feegrant/ante`
* update keeper logic to create account
* update docs
* fix tests
* update `serviceMsgClientConn` from `msgservice`
* review changes
* add test case for using more fees than allowed
* eliminate panic checks from keeper
* fix lint
* change store keys string to bytes
* fix tests
* review changes
* review changes
* udpate docs
* make spend limit optional
* fix tests
* fix tests
* review changes
* add norace tag
* proto-docs
* add docs
Co-authored-by: Ethan Frey <ethanfrey@users.noreply.github.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: SaReN <sahithnarahari@gmail.com>
Co-authored-by: aleem1413 <aleem@vitwit.com>
Co-authored-by: MD Aleem <72057206+aleem1314@users.noreply.github.com>
Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-01-29 11:54:51 -08:00
cmd . Flags ( ) . String ( FlagFeeAccount , "" , "Fee account pays fees for the transaction instead of deducting from the signer" )
2020-07-10 12:59:26 -07:00
2020-07-11 01:13:46 -07:00
// --gas can accept integers and "auto"
cmd . Flags ( ) . String ( FlagGas , "" , fmt . Sprintf ( "gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)" , GasFlagAuto , DefaultGasLimit ) )
2020-07-10 12:59:26 -07:00
}
2020-07-19 03:16:57 -07:00
// AddPaginationFlagsToCmd adds common pagination flags to cmd
2020-07-17 08:23:42 -07:00
func AddPaginationFlagsToCmd ( cmd * cobra . Command , query string ) {
2020-07-24 01:17:11 -07:00
cmd . Flags ( ) . Uint64 ( FlagPage , 1 , fmt . Sprintf ( "pagination page of %s to query for. This sets offset to a multiple of limit" , query ) )
2020-07-17 08:23:42 -07:00
cmd . Flags ( ) . String ( FlagPageKey , "" , fmt . Sprintf ( "pagination page-key of %s to query for" , query ) )
cmd . Flags ( ) . Uint64 ( FlagOffset , 0 , fmt . Sprintf ( "pagination offset of %s to query for" , query ) )
cmd . Flags ( ) . Uint64 ( FlagLimit , 100 , fmt . Sprintf ( "pagination limit of %s to query for" , query ) )
cmd . Flags ( ) . Bool ( FlagCountTotal , false , fmt . Sprintf ( "count total number of records in %s to query for" , query ) )
2021-03-23 02:28:20 -07:00
cmd . Flags ( ) . Bool ( FlagReverse , false , "results are sorted in descending order" )
2020-07-17 08:23:42 -07:00
}
2018-09-11 17:31:30 -07:00
// GasSetting encapsulates the possible values passed through the --gas flag.
type GasSetting struct {
Simulate bool
2018-11-19 09:13:45 -08:00
Gas uint64
2018-09-11 17:31:30 -07:00
}
func ( v * GasSetting ) String ( ) string {
if v . Simulate {
2018-12-20 11:21:07 -08:00
return GasFlagAuto
2018-09-11 17:31:30 -07:00
}
2020-07-11 01:13:46 -07:00
2018-11-19 09:13:45 -08:00
return strconv . FormatUint ( v . Gas , 10 )
2018-09-11 17:31:30 -07:00
}
2020-07-11 01:13:46 -07:00
// ParseGasSetting parses a string gas value. The value may either be 'auto',
// which indicates a transaction should be executed in simulate mode to
// automatically find a sufficient gas value, or a string integer. It returns an
// error if a string integer is provided which cannot be parsed.
func ParseGasSetting ( gasStr string ) ( GasSetting , error ) {
2018-12-19 16:26:33 -08:00
switch gasStr {
2018-09-11 17:31:30 -07:00
case "" :
2020-07-11 01:13:46 -07:00
return GasSetting { false , DefaultGasLimit } , nil
2018-12-20 11:21:07 -08:00
case GasFlagAuto :
2020-07-11 01:13:46 -07:00
return GasSetting { true , 0 } , nil
2018-09-11 17:31:30 -07:00
default :
2020-07-11 01:13:46 -07:00
gas , err := strconv . ParseUint ( gasStr , 10 , 64 )
2018-09-11 17:31:30 -07:00
if err != nil {
2020-07-11 01:13:46 -07:00
return GasSetting { } , fmt . Errorf ( "gas must be either integer or %s" , GasFlagAuto )
2018-09-11 17:31:30 -07:00
}
2020-07-11 01:13:46 -07:00
return GasSetting { false , gas } , nil
2018-09-11 17:31:30 -07:00
}
}