Various sign command improvements
- Exit with error if the user is attempting to sign with a key whose address is not among those who are expected to sign the transaction. - Add --print-signature-only to output only the generated signature.
This commit is contained in:
parent
89047d8ebd
commit
bc583ab1d0
|
@ -123,7 +123,8 @@ func SignStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string,
|
|||
|
||||
// Check whether the address is a signer
|
||||
if !isTxSigner(sdk.AccAddress(addr), stdTx.GetSigners()) {
|
||||
fmt.Fprintf(os.Stderr, "WARNING: The generated transaction's intended signer does not match the given signer: '%v'\n", name)
|
||||
return signedStdTx, fmt.Errorf(
|
||||
"The generated transaction's intended signer does not match the given signer: %q", name)
|
||||
}
|
||||
|
||||
if !offline && txBldr.AccountNumber == 0 {
|
||||
|
|
|
@ -20,6 +20,7 @@ const (
|
|||
flagAppend = "append"
|
||||
flagPrintSigs = "print-sigs"
|
||||
flagOffline = "offline"
|
||||
flagSigOnly = "print-signature-only"
|
||||
)
|
||||
|
||||
// GetSignCommand returns the sign command
|
||||
|
@ -38,6 +39,7 @@ recommended to set such parameters manually.`,
|
|||
}
|
||||
cmd.Flags().String(client.FlagName, "", "Name of private key with which to sign")
|
||||
cmd.Flags().Bool(flagAppend, true, "Append the signature to the existing ones. If disabled, old signatures would be overwritten")
|
||||
cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit.")
|
||||
cmd.Flags().Bool(flagPrintSigs, false, "Print the addresses that must sign the transaction and those who have already signed it, then exit")
|
||||
cmd.Flags().Bool(flagOffline, false, "Offline mode. Do not query local cache.")
|
||||
return cmd
|
||||
|
@ -59,14 +61,24 @@ func makeSignCmd(cdc *amino.Codec, decoder auth.AccountDecoder) func(cmd *cobra.
|
|||
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(decoder)
|
||||
txBldr := authtxb.NewTxBuilderFromCLI()
|
||||
|
||||
newTx, err := utils.SignStdTx(txBldr, cliCtx, name, stdTx, viper.GetBool(flagAppend), viper.GetBool(flagOffline))
|
||||
// if --print-signature-only is on, then override --append
|
||||
generateSignatureOnly := viper.GetBool(flagSigOnly)
|
||||
append := viper.GetBool(flagAppend) && !generateSignatureOnly
|
||||
newTx, err := utils.SignStdTx(txBldr, cliCtx, name, stdTx, append, viper.GetBool(flagOffline))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var json []byte
|
||||
if cliCtx.Indent {
|
||||
|
||||
switch {
|
||||
case generateSignatureOnly && cliCtx.Indent:
|
||||
json, err = cdc.MarshalJSONIndent(newTx.Signatures[0], "", " ")
|
||||
case generateSignatureOnly && !cliCtx.Indent:
|
||||
json, err = cdc.MarshalJSON(newTx.Signatures[0])
|
||||
case !generateSignatureOnly && cliCtx.Indent:
|
||||
json, err = cdc.MarshalJSONIndent(newTx, "", " ")
|
||||
} else {
|
||||
case !generateSignatureOnly && !cliCtx.Indent:
|
||||
json, err = cdc.MarshalJSON(newTx)
|
||||
}
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue