Merge PR #6525: x/bank: Refactor CLI & Tests

This commit is contained in:
Alexander Bezobchuk
2020-06-30 16:59:21 -04:00
committed by GitHub
parent 56af94e6ab
commit d5049413ef
35 changed files with 665 additions and 561 deletions
+95
View File
@@ -6,6 +6,9 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/cosmos/cosmos-sdk/client/flags"
)
// ValidateCmd returns unknown command error or Help display if help flag set
@@ -55,3 +58,95 @@ func ValidateCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
// ReadPersistentCommandFlags returns a Context with fields set for "persistent"
// flags that do not necessarily change with context. These must be checked if
// the caller explicitly changed the values.
func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, error) {
if flagSet.Changed(flags.FlagChainID) {
chainID, _ := flagSet.GetString(flags.FlagChainID)
clientCtx = clientCtx.WithChainID(chainID)
}
if flagSet.Changed(flags.FlagTrustNode) {
trustNode, _ := flagSet.GetBool(flags.FlagTrustNode)
clientCtx = clientCtx.WithTrustNode(trustNode)
}
if flagSet.Changed(flags.FlagKeyringBackend) {
keyringBackend, _ := flagSet.GetString(flags.FlagKeyringBackend)
kr, err := newKeyringFromFlags(clientCtx, keyringBackend)
if err != nil {
return clientCtx, err
}
clientCtx = clientCtx.WithKeyring(kr)
}
if flagSet.Changed(flags.FlagNode) {
rpcURI, _ := flagSet.GetString(flags.FlagNode)
clientCtx = clientCtx.WithNodeURI(rpcURI)
}
return clientCtx, nil
}
// ReadQueryCommandFlags returns an updated Context with fields set based on flags
// defined in GetCommands. An error is returned if any flag query fails.
//
// Certain flags are naturally command and context dependent, so for these flags
// we do not check if they've been explicitly set by the caller. Other flags can
// be considered "persistent" (e.g. KeyBase or Client) and these should be checked
// if the caller explicitly set those.
func ReadQueryCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, error) {
height, _ := flagSet.GetInt64(flags.FlagHeight)
clientCtx = clientCtx.WithHeight(height)
useLedger, _ := flagSet.GetBool(flags.FlagUseLedger)
clientCtx = clientCtx.WithUseLedger(useLedger)
return ReadPersistentCommandFlags(clientCtx, flagSet)
}
// ReadTxCommandFlags returns an updated Context with fields set based on flags
// defined in PostCommands. An error is returned if any flag query fails.
//
// Certain flags are naturally command and context dependent, so for these flags
// we do not check if they've been explicitly set by the caller. Other flags can
// be considered "persistent" (e.g. KeyBase or Client) and these should be checked
// if the caller explicitly set those.
func ReadTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, error) {
clientCtx, err := ReadPersistentCommandFlags(clientCtx, flagSet)
if err != nil {
return clientCtx, err
}
genOnly, _ := flagSet.GetBool(flags.FlagGenerateOnly)
clientCtx = clientCtx.WithGenerateOnly(genOnly)
dryRun, _ := flagSet.GetBool(flags.FlagDryRun)
clientCtx = clientCtx.WithSimulation(dryRun)
offline, _ := flagSet.GetBool(flags.FlagOffline)
clientCtx = clientCtx.WithOffline(offline)
useLedger, _ := flagSet.GetBool(flags.FlagUseLedger)
clientCtx = clientCtx.WithUseLedger(useLedger)
bMode, _ := flagSet.GetString(flags.FlagBroadcastMode)
clientCtx = clientCtx.WithBroadcastMode(bMode)
skipConfirm, _ := flagSet.GetBool(flags.FlagSkipConfirmation)
clientCtx = clientCtx.WithSkipConfirmation(skipConfirm)
from, _ := flagSet.GetString(flags.FlagFrom)
fromAddr, fromName, err := GetFromFields(clientCtx.Keyring, from, clientCtx.GenerateOnly)
if err != nil {
return clientCtx, err
}
clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName)
return clientCtx, nil
}
+27 -28
View File
@@ -43,21 +43,18 @@ type Context struct {
Simulate bool
GenerateOnly bool
Offline bool
Indent bool
SkipConfirm bool
TxGenerator TxGenerator
AccountRetriever AccountRetriever
// TODO: API and CLI interfaces are migrating to a single binary (i.e be part of
// the same process of the application). We need to groom through these fields
// and remove any that no longer make sense.
NodeURI string
Verifier tmlite.Verifier
NodeURI string
Verifier tmlite.Verifier
// TODO: Deprecated (remove).
Codec *codec.Codec
}
// TODO: Remove all New* and Init* methods.
// NewContextWithInputAndFrom returns a new initialized Context with parameters from the
// command line using Viper. It takes a io.Reader and and key name or address and populates
// the FromName and FromAddress field accordingly. It will also create Tendermint verifier
@@ -127,33 +124,29 @@ func (ctx Context) InitWithInputAndFrom(input io.Reader, from string) Context {
ctx.BroadcastMode = viper.GetString(flags.FlagBroadcastMode)
ctx.Simulate = viper.GetBool(flags.FlagDryRun)
ctx.Offline = offline
ctx.Indent = viper.GetBool(flags.FlagIndentResponse)
ctx.SkipConfirm = viper.GetBool(flags.FlagSkipConfirmation)
ctx.HomeDir = viper.GetString(flags.FlagHome)
ctx.GenerateOnly = viper.GetBool(flags.FlagGenerateOnly)
homedir := viper.GetString(flags.FlagHome)
genOnly := viper.GetBool(flags.FlagGenerateOnly)
backend := viper.GetString(flags.FlagKeyringBackend)
if len(backend) == 0 {
backend = keyring.BackendMemory
}
kr, err := newKeyringFromFlags(backend, homedir, input, genOnly)
kr, err := newKeyringFromFlags(ctx, backend)
if err != nil {
panic(fmt.Errorf("couldn't acquire keyring: %v", err))
}
fromAddress, fromName, err := GetFromFields(kr, from, genOnly)
fromAddress, fromName, err := GetFromFields(kr, from, ctx.GenerateOnly)
if err != nil {
fmt.Printf("failed to get from fields: %v\n", err)
os.Exit(1)
}
ctx.HomeDir = homedir
ctx.Keyring = kr
ctx.FromAddress = fromAddress
ctx.FromName = fromName
ctx.GenerateOnly = genOnly
if offline {
return ctx
@@ -290,6 +283,12 @@ func (ctx Context) WithSimulation(simulate bool) Context {
return ctx
}
// WithOffline returns a copy of the context with updated Offline value.
func (ctx Context) WithOffline(offline bool) Context {
ctx.Offline = offline
return ctx
}
// WithFromName returns a copy of the context with an updated from account name.
func (ctx Context) WithFromName(name string) Context {
ctx.FromName = name
@@ -310,6 +309,13 @@ func (ctx Context) WithBroadcastMode(mode string) Context {
return ctx
}
// WithSkipConfirmation returns a copy of the context with an updated SkipConfirm
// value.
func (ctx Context) WithSkipConfirmation(skip bool) Context {
ctx.SkipConfirm = skip
return ctx
}
// WithTxGenerator returns the context with an updated TxGenerator
func (ctx Context) WithTxGenerator(generator TxGenerator) Context {
ctx.TxGenerator = generator
@@ -335,6 +341,7 @@ func (ctx Context) PrintOutput(toPrint interface{}) error {
if ctx.OutputFormat == "text" {
// handle text format by decoding and re-encoding JSON as YAML
var j interface{}
err = json.Unmarshal(out, &j)
if err != nil {
return err
@@ -344,18 +351,9 @@ func (ctx Context) PrintOutput(toPrint interface{}) error {
if err != nil {
return err
}
} else if ctx.Indent {
// To JSON indent, we re-encode the already encoded JSON given there is no
// error. The re-encoded JSON uses the standard library as the initial encoded
// JSON should have the correct output produced by ctx.JSONMarshaler.
out, err = codec.MarshalIndentFromJSON(out)
if err != nil {
return err
}
}
writer := ctx.Output
// default to stdout
if writer == nil {
writer = os.Stdout
}
@@ -409,9 +407,10 @@ func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddres
return info.GetAddress(), info.GetName(), nil
}
func newKeyringFromFlags(backend, homedir string, input io.Reader, genOnly bool) (keyring.Keyring, error) {
if genOnly {
return keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, homedir, input)
func newKeyringFromFlags(ctx Context, backend string) (keyring.Keyring, error) {
if ctx.GenerateOnly {
return keyring.New(sdk.KeyringServiceName(), keyring.BackendMemory, ctx.HomeDir, ctx.Input)
}
return keyring.New(sdk.KeyringServiceName(), backend, homedir, input)
return keyring.New(sdk.KeyringServiceName(), backend, ctx.HomeDir, ctx.Input)
}
-45
View File
@@ -106,36 +106,16 @@ func TestContext_PrintOutput(t *testing.T) {
buf := &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "json"
ctx.Indent = false
err = ctx.PrintOutput(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{"animal":{"@type":"/cosmos_sdk.codec.v1.Dog","size":"big","name":"Spot"},"x":"10"}
`, string(buf.Bytes()))
// json indent
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "json"
ctx.Indent = true
err = ctx.PrintOutput(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{
"animal": {
"@type": "/cosmos_sdk.codec.v1.Dog",
"name": "Spot",
"size": "big"
},
"x": "10"
}
`, string(buf.Bytes()))
// yaml
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "text"
ctx.Indent = false
err = ctx.PrintOutput(hasAnimal)
require.NoError(t, err)
require.Equal(t,
@@ -156,41 +136,16 @@ x: "10"
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "json"
ctx.Indent = false
err = ctx.PrintOutput(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{"type":"testdata/HasAnimal","value":{"animal":{"type":"testdata/Dog","value":{"size":"big","name":"Spot"}},"x":"10"}}
`, string(buf.Bytes()))
// json indent
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "json"
ctx.Indent = true
err = ctx.PrintOutput(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{
"type": "testdata/HasAnimal",
"value": {
"animal": {
"type": "testdata/Dog",
"value": {
"name": "Spot",
"size": "big"
}
},
"x": "10"
}
}
`, string(buf.Bytes()))
// yaml
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "text"
ctx.Indent = false
err = ctx.PrintOutput(hasAnimal)
require.NoError(t, err)
require.Equal(t,
+6 -5
View File
@@ -57,7 +57,6 @@ const (
FlagDryRun = "dry-run"
FlagGenerateOnly = "generate-only"
FlagOffline = "offline"
FlagIndentResponse = "indent"
FlagOutputDocument = "output-document" // inspired by wget -O
FlagSkipConfirmation = "yes"
FlagProve = "prove"
@@ -77,13 +76,13 @@ var (
// GetCommands adds common flags to query commands
func GetCommands(cmds ...*cobra.Command) []*cobra.Command {
for _, c := range cmds {
c.Flags().Bool(FlagIndentResponse, false, "Add indent to JSON response")
c.Flags().Bool(FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
c.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device")
c.Flags().String(FlagNode, "tcp://localhost:26657", "<host>:<port> to Tendermint RPC interface for this chain")
c.Flags().Int64(FlagHeight, 0, "Use a specific height to query state at (this can error if the node is pruning state)")
c.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
// TODO: REMOVE VIPER CALLS!
viper.BindPFlag(FlagTrustNode, c.Flags().Lookup(FlagTrustNode))
viper.BindPFlag(FlagUseLedger, c.Flags().Lookup(FlagUseLedger))
viper.BindPFlag(FlagNode, c.Flags().Lookup(FlagNode))
@@ -100,7 +99,6 @@ func GetCommands(cmds ...*cobra.Command) []*cobra.Command {
// PostCommands adds common flags for commands to post tx
func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
for _, c := range cmds {
c.Flags().Bool(FlagIndentResponse, false, "Add indent to JSON response")
c.Flags().String(FlagFrom, "", "Name or address of private key with which to sign")
c.Flags().Uint64P(FlagAccountNumber, "a", 0, "The account number of the signing account (offline mode only)")
c.Flags().Uint64P(FlagSequence, "s", 0, "The sequence number of the signing account (offline mode only)")
@@ -120,10 +118,15 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
c.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json), this is an advanced feature")
// --gas can accept integers and "simulate"
//
// TODO: Remove usage of var in favor of string as this is technical creating
// a singleton usage pattern and can cause issues in parallel tests.
c.Flags().Var(&GasFlagVar, "gas", fmt.Sprintf(
"gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)",
GasFlagAuto, DefaultGasLimit,
))
// TODO: REMOVE VIPER CALLS!
viper.BindPFlag(FlagTrustNode, c.Flags().Lookup(FlagTrustNode))
viper.BindPFlag(FlagUseLedger, c.Flags().Lookup(FlagUseLedger))
viper.BindPFlag(FlagNode, c.Flags().Lookup(FlagNode))
@@ -137,8 +140,6 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
return cmds
}
// Gas flag parsing functions
// GasSetting encapsulates the possible values passed through the --gas flag.
type GasSetting struct {
Simulate bool
+2 -8
View File
@@ -78,7 +78,6 @@ the flag --nosort is set.
cmd.Flags().Uint32(flagCoinType, sdk.GetConfig().GetCoinType(), "coin type number for HD derivation")
cmd.Flags().Uint32(flagAccount, 0, "Account number for HD derivation")
cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation")
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
cmd.Flags().String(flagKeyAlgo, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")
return cmd
@@ -311,18 +310,13 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
out.Mnemonic = mnemonic
}
var jsonString []byte
if viper.GetBool(flags.FlagIndentResponse) {
jsonString, err = KeysCdc.MarshalJSONIndent(out, "", " ")
} else {
jsonString, err = KeysCdc.MarshalJSON(out)
}
jsonString, err := KeysCdc.MarshalJSON(out)
if err != nil {
return err
}
cmd.PrintErrln(string(jsonString))
default:
return fmt.Errorf("invalid output format %s", output)
}
+1 -1
View File
@@ -20,7 +20,7 @@ func ListKeysCmd() *cobra.Command {
along with their associated name and address.`,
RunE: runListCmd,
}
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
cmd.Flags().BoolP(flagListNames, "n", false, "List names only")
return cmd
}
+1 -7
View File
@@ -16,7 +16,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@@ -85,7 +84,6 @@ hexadecimal into bech32 cosmos prefixed format and vice versa.
Args: cobra.ExactArgs(1),
RunE: parseKey,
}
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Indent JSON output")
return cmd
}
@@ -145,11 +143,7 @@ func displayParseKeyInfo(w io.Writer, stringer fmt.Stringer) {
out, err = yaml.Marshal(&stringer)
case OutputFormatJSON:
if viper.GetBool(flags.FlagIndentResponse) {
out, err = KeysCdc.MarshalJSONIndent(stringer, "", " ")
} else {
out = KeysCdc.MustMarshalJSON(stringer)
}
out, err = KeysCdc.MarshalJSON(stringer)
}
if err != nil {
-1
View File
@@ -49,7 +49,6 @@ consisting of all the keys provided by name and multisig threshold.`,
cmd.Flags().BoolP(FlagPublicKey, "p", false, "Output the public key only (overrides --output)")
cmd.Flags().BoolP(FlagDevice, "d", false, "Output the address in a ledger device")
cmd.Flags().Uint(flagMultiSigThreshold, 1, "K out of N required signatures")
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
return cmd
}
+3 -17
View File
@@ -9,7 +9,6 @@ import (
"github.com/tendermint/tendermint/libs/cli"
"gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/client/flags"
cryptokeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
)
@@ -45,13 +44,7 @@ func printKeyInfo(w io.Writer, keyInfo cryptokeyring.Info, bechKeyOut bechKeyOut
printTextInfos(w, []cryptokeyring.KeyOutput{ko})
case OutputFormatJSON:
var out []byte
var err error
if viper.GetBool(flags.FlagIndentResponse) {
out, err = KeysCdc.MarshalJSONIndent(ko, "", " ")
} else {
out, err = KeysCdc.MarshalJSON(ko)
}
out, err := KeysCdc.MarshalJSON(ko)
if err != nil {
panic(err)
}
@@ -71,18 +64,11 @@ func printInfos(w io.Writer, infos []cryptokeyring.Info) {
printTextInfos(w, kos)
case OutputFormatJSON:
var out []byte
var err error
if viper.GetBool(flags.FlagIndentResponse) {
out, err = KeysCdc.MarshalJSONIndent(kos, "", " ")
} else {
out, err = KeysCdc.MarshalJSON(kos)
}
out, err := KeysCdc.MarshalJSON(kos)
if err != nil {
panic(err)
}
fmt.Fprintf(w, "%s", out)
}
}
-4
View File
@@ -64,10 +64,6 @@ func getBlock(clientCtx client.Context, height *int64) ([]byte, error) {
}
}
if clientCtx.Indent {
return legacy.Cdc.MarshalJSONIndent(res, "", " ")
}
return legacy.Cdc.MarshalJSON(res)
}
+1 -7
View File
@@ -28,7 +28,6 @@ func StatusCommand() *cobra.Command {
cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
return cmd
}
@@ -53,12 +52,7 @@ func printNodeStatus(_ *cobra.Command, _ []string) error {
return err
}
var output []byte
if clientCtx.Indent {
output, err = legacy.Cdc.MarshalJSONIndent(status, "", " ")
} else {
output, err = legacy.Cdc.MarshalJSON(status)
}
output, err := legacy.Cdc.MarshalJSON(status)
if err != nil {
return err
}
+5 -2
View File
@@ -56,15 +56,18 @@ func ValidatorCommand(cdc *codec.Codec) *cobra.Command {
cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
cmd.Flags().Bool(flags.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend))
cmd.Flags().Bool(flags.FlagIndentResponse, false, "indent JSON response")
viper.BindPFlag(flags.FlagIndentResponse, cmd.Flags().Lookup(flags.FlagIndentResponse))
cmd.Flags().Int(flags.FlagPage, 0, "Query a specific page of paginated results")
viper.BindPFlag(flags.FlagPage, cmd.Flags().Lookup(flags.FlagPage))
cmd.Flags().Int(flags.FlagLimit, 100, "Query number of results returned per page")
viper.BindPFlag(flags.FlagLimit, cmd.Flags().Lookup(flags.FlagLimit))
return cmd
}
+43 -2
View File
@@ -3,6 +3,7 @@ package tx
import (
"io"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
@@ -35,7 +36,47 @@ const (
signModeAminoJSON = "amino-json"
)
func NewFactoryFromCLI(input io.Reader) Factory {
func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
signModeStr, _ := flagSet.GetString(flags.FlagSignMode)
signMode := signing.SignMode_SIGN_MODE_UNSPECIFIED
switch signModeStr {
case signModeDirect:
signMode = signing.SignMode_SIGN_MODE_DIRECT
case signModeAminoJSON:
signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON
}
accNum, _ := flagSet.GetUint64(flags.FlagAccountNumber)
accSeq, _ := flagSet.GetUint64(flags.FlagSequence)
gasAdj, _ := flagSet.GetFloat64(flags.FlagGasAdjustment)
memo, _ := flagSet.GetString(flags.FlagMemo)
f := Factory{
txGenerator: clientCtx.TxGenerator,
accountRetriever: clientCtx.AccountRetriever,
keybase: clientCtx.Keyring,
chainID: clientCtx.ChainID,
gas: flags.GasFlagVar.Gas,
simulateAndExecute: flags.GasFlagVar.Simulate,
accountNumber: accNum,
sequence: accSeq,
gasAdjustment: gasAdj,
memo: memo,
signMode: signMode,
}
feesStr, _ := flagSet.GetString(flags.FlagFees)
f = f.WithFees(feesStr)
gasPricesStr, _ := flagSet.GetString(flags.FlagGasPrices)
f = f.WithGasPrices(gasPricesStr)
return f
}
// TODO: Remove in favor of NewFactoryCLI
func NewFactoryFromDeprecated(input io.Reader) Factory {
kb, err := keyring.New(
sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend),
@@ -57,12 +98,12 @@ func NewFactoryFromCLI(input io.Reader) Factory {
f := Factory{
keybase: kb,
chainID: viper.GetString(flags.FlagChainID),
accountNumber: viper.GetUint64(flags.FlagAccountNumber),
sequence: viper.GetUint64(flags.FlagSequence),
gas: flags.GasFlagVar.Gas,
gasAdjustment: viper.GetFloat64(flags.FlagGasAdjustment),
simulateAndExecute: flags.GasFlagVar.Simulate,
chainID: viper.GetString(flags.FlagChainID),
memo: viper.GetString(flags.FlagMemo),
signMode: signMode,
}
+11 -1
View File
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/gogo/protobuf/jsonpb"
"github.com/spf13/pflag"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -20,10 +21,19 @@ import (
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
)
// GenerateOrBroadcastTxCLI will either generate and print and unsigned transaction
// or sign it and broadcast it returning an error upon failure.
func GenerateOrBroadcastTxCLI(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) error {
txf := NewFactoryCLI(clientCtx, flagSet)
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
}
// GenerateOrBroadcastTx will either generate and print and unsigned transaction
// or sign it and broadcast it returning an error upon failure.
//
// TODO: Remove in favor of GenerateOrBroadcastTxCLI
func GenerateOrBroadcastTx(clientCtx client.Context, msgs ...sdk.Msg) error {
txf := NewFactoryFromCLI(clientCtx.Input).WithTxGenerator(clientCtx.TxGenerator).WithAccountRetriever(clientCtx.AccountRetriever)
txf := NewFactoryFromDeprecated(clientCtx.Input).WithTxGenerator(clientCtx.TxGenerator).WithAccountRetriever(clientCtx.AccountRetriever)
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
}