diff --git a/CHANGELOG.md b/CHANGELOG.md index d420a893187b..da992685c617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* [\#10710](https://github.com/cosmos/cosmos-sdk/pull/10710) Chain-id shouldn't be required for creating a transaction with both --generate-only and --offline flags. * [\#10703](https://github.com/cosmos/cosmos-sdk/pull/10703) Create a new grantee account, if the grantee of an authorization does not exist. * [\#10592](https://github.com/cosmos/cosmos-sdk/pull/10592) Add a `DecApproxEq` function that checks to see if `|d1 - d2| < tol` for some Dec `d1, d2, tol`. * [\#10393](https://github.com/cosmos/cosmos-sdk/pull/10393) Add `HasSupply` method to bank keeper to ensure that input denom actually exists on chain. diff --git a/client/tx/factory.go b/client/tx/factory.go index 6d62d6264135..79fe2b45f9f2 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -28,6 +28,8 @@ type Factory struct { timeoutHeight uint64 gasAdjustment float64 chainID string + offline bool + generateOnly bool memo string fees sdk.Coins tip *tx.Tip @@ -64,6 +66,8 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory { accountRetriever: clientCtx.AccountRetriever, keybase: clientCtx.Keyring, chainID: clientCtx.ChainID, + offline: clientCtx.Offline, + generateOnly: clientCtx.GenerateOnly, gas: gasSetting.Gas, simulateAndExecute: gasSetting.Simulate, accountNumber: accNum, @@ -220,7 +224,11 @@ func (f Factory) WithTimeoutHeight(height uint64) Factory { // BuildUnsignedTx builds a transaction to be signed given a set of messages. // Once created, the fee, memo, and messages are set. func (f Factory) BuildUnsignedTx(msgs ...sdk.Msg) (client.TxBuilder, error) { - if f.chainID == "" { + if f.offline && f.generateOnly { + if f.chainID != "" { + return nil, fmt.Errorf("chain ID cannot be used when offline and generate-only flags are set") + } + } else if f.chainID == "" { return nil, fmt.Errorf("chain ID required but not specified") } diff --git a/x/bank/client/testutil/suite.go b/x/bank/client/testutil/suite.go index e486de8e91f2..f37d1f24c4d0 100644 --- a/x/bank/client/testutil/suite.go +++ b/x/bank/client/testutil/suite.go @@ -414,6 +414,23 @@ func (s *IntegrationTestSuite) TestNewSendTxCmd() { }, false, 0, &sdk.TxResponse{}, }, + { + "chain-id shouldn't be used with offline and generate-only flags", + val.Address, + val.Address, + sdk.NewCoins( + sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(10)), + sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)), + ), + []string{ + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=true", flags.FlagOffline), + fmt.Sprintf("--%s=true", flags.FlagGenerateOnly), + }, + true, 0, &sdk.TxResponse{}, + }, { "not enough fees", val.Address,