Merge PR #3713: Use from instead of name CLI flag for the tx sign cmd

* Use from instead of name CLI flag for the tx sign cmd
* Use cliCtx.GetFromName() instead of direct from value
This commit is contained in:
Alexander Bezobchuk 2019-02-22 11:15:36 -05:00 committed by Christopher Goes
parent b823203839
commit c96d8f3e81
3 changed files with 18 additions and 11 deletions

View File

@ -44,6 +44,9 @@ decoded automatically.
### Gaia CLI
* [\#3711] Update `tx sign` to use `--from` instead of the deprecated `--name`
CLI flag.
### Gaia
### SDK

View File

@ -290,7 +290,7 @@ func (f *Fixtures) TxSend(from string, to sdk.AccAddress, amount sdk.Coin, flags
// TxSign is gaiacli tx sign
func (f *Fixtures) TxSign(signer, fileName string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("gaiacli tx sign %v --name=%s %v", f.Flags(), signer, fileName)
cmd := fmt.Sprintf("gaiacli tx sign %v --from=%s %v", f.Flags(), signer, fileName)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), app.DefaultKeyPass)
}

View File

@ -1,13 +1,12 @@
package cli
import (
"errors"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/go-amino"
amino "github.com/tendermint/go-amino"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
@ -55,7 +54,7 @@ be generated via the 'multisign' command.
RunE: makeSignCmd(codec),
Args: cobra.ExactArgs(1),
}
cmd.Flags().String(client.FlagName, "", "Name of private key with which to sign")
cmd.Flags().String(flagMultisig, "",
"Address of the multisig account on behalf of which the "+
"transaction shall be signed")
@ -69,7 +68,7 @@ be generated via the 'multisign' command.
cmd.Flags().String(flagOutfile, "",
"The document will be written to the given file instead of STDOUT")
// Add the flags here and return the command
// add the flags here and return the command
return client.PostCommands(cmd)[0]
}
@ -92,9 +91,9 @@ func makeSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) error
return nil
}
name := viper.GetString(client.FlagName)
if name == "" {
return errors.New("required flag \"name\" has not been set")
from := viper.GetString(client.FlagFrom)
if from == "" {
return fmt.Errorf("required flag '%s' has not been set", client.FlagFrom)
}
// if --signature-only is on, then override --append
@ -104,19 +103,21 @@ func makeSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) error
if multisigAddrStr != "" {
var multisigAddr sdk.AccAddress
multisigAddr, err = sdk.AccAddressFromBech32(multisigAddrStr)
if err != nil {
return err
}
newTx, err = utils.SignStdTxWithSignerAddress(
txBldr, cliCtx, multisigAddr, name, stdTx, offline)
txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, offline,
)
generateSignatureOnly = true
} else {
appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly
newTx, err = utils.SignStdTx(
txBldr, cliCtx, name, stdTx, appendSig, offline)
newTx, err = utils.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, offline)
}
if err != nil {
return err
}
@ -128,13 +129,16 @@ func makeSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) error
switch cliCtx.Indent {
case true:
json, err = cdc.MarshalJSONIndent(newTx.Signatures[0], "", " ")
default:
json, err = cdc.MarshalJSON(newTx.Signatures[0])
}
default:
switch cliCtx.Indent {
case true:
json, err = cdc.MarshalJSONIndent(newTx, "", " ")
default:
json, err = cdc.MarshalJSON(newTx)
}