diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b8c45629..5ce1e54c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (cli) [\#9856](https://github.com/cosmos/cosmos-sdk/pull/9856) Overwrite `--sequence` and `--account-number` flags with default flag values when used with `offline=false` in `sign-batch` command. * (cli) [\#9593](https://github.com/cosmos/cosmos-sdk/pull/9593) Check if chain-id is blank before verifying signatures in multisign and error. * (cli) [\#9717](https://github.com/cosmos/cosmos-sdk/pull/9717) Added CLI flag `--output json/text` to `tx` cli commands. diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 34483f9c9..08abeaa05 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -28,7 +28,7 @@ func GetSignBatchCommand() *cobra.Command { Long: `Sign batch files of transactions generated with --generate-only. The command processes list of transactions from file (one StdTx each line), generate signed transactions or signatures and print their JSON encoding, delimited by '\n'. -As the signatures are generated, the command updates the account sequence number accordingly. +As the signatures are generated, the command updates the account and sequence number accordingly. If the --signature-only flag is set, it will output the signature parts only. @@ -38,6 +38,9 @@ it is required to set such parameters manually. Note, invalid values will cause the transaction to fail. The sequence will be incremented automatically for each transaction that is signed. +If --account-number or --sequence flag is used when offline=false, they are ignored and +overwritten by the default flag values. + The --multisig= flag generates a signature on behalf of a multisig account key. It implies --signature-only. `, @@ -89,6 +92,10 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } scanner := authclient.NewBatchScanner(txCfg, infile) + if !clientCtx.Offline { + txFactory = txFactory.WithAccountNumber(0).WithSequence(0) + } + for sequence := txFactory.Sequence(); scanner.Scan(); sequence++ { unsignedStdTx := scanner.Tx() txFactory = txFactory.WithSequence(sequence) diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index fd4a472f8..e744916b4 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -126,8 +126,21 @@ func (s *IntegrationTestSuite) TestCLISignBatch() { _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") + // sign-batch file - offline and sequence is set but account-number is not set + _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), "--offline") + s.Require().EqualError(err, "required flag(s) \"account-number\" not set") + + // sign-batch file - offline and account-number is set but sequence is not set + _, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1"), "--offline") + s.Require().EqualError(err, "required flag(s) \"sequence\" not set") + + // sign-batch file - sequence and account-number are set when offline is false + res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1")) + s.Require().NoError(err) + s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) + // sign-batch file - res, err := TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID)) + res, err = TxSignBatchExec(val.ClientCtx, val.Address, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, val.ClientCtx.ChainID)) s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n")))