diff --git a/client/context.go b/client/context.go index 525c851ae8a7..638ba1b9973b 100644 --- a/client/context.go +++ b/client/context.go @@ -83,12 +83,6 @@ func NewContextWithFrom(from string) Context { // command line using Viper. func NewContext() Context { return NewContextWithFrom(viper.GetString(flags.FlagFrom)) } -// NewContextWithInput returns a new initialized Context with a io.Reader and parameters -// from the command line using Viper. -func NewContextWithInput(input io.Reader) Context { - return NewContextWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) -} - // InitWithInputAndFrom returns a new Context re-initialized from an existing // Context with a new io.Reader and from parameter func (ctx Context) InitWithInputAndFrom(input io.Reader, from string) Context { diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index a5bce72881f1..7c74df825dec 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -207,7 +207,11 @@ func InitTestnet( ) tx := authtypes.NewStdTx([]sdk.Msg{msg}, authtypes.StdFee{}, []authtypes.StdSignature{}, memo) //nolint:staticcheck // SA1019: authtypes.StdFee is deprecated - txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithChainID(chainID).WithMemo(memo).WithKeybase(kb) + txBldr, err := authtypes.NewTxBuilderFromFlags(inBuf, cmd.Flags(), clientDir) + if err != nil { + return fmt.Errorf("error creating tx: %w", err) + } + txBldr.WithChainID(chainID).WithMemo(memo).WithKeybase(kb) signedTx, err := txBldr.SignStdTx(nodeDirName, tx, false) if err != nil { diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index db4eacc23ab4..f01d8592d9ff 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/version" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -83,7 +84,10 @@ func makeMultiSignCmd(clientCtx client.Context) func(cmd *cobra.Command, args [] multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) - txBldr := types.NewTxBuilderFromCLI(inBuf) + txBldr, err := types.NewTxBuilderFromFlags(inBuf, cmd.Flags(), homeDir) + if err != nil { + return errors.Wrap(err, "error creating tx builder from flags") + } if !clientCtx.Offline { accnum, seq, err := types.NewAccountRetriever(authclient.Codec).GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress()) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index c515c9c56d42..8fa08062ac4b 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -63,12 +63,16 @@ account key. It implies --signature-only. func makeSignBatchCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) - clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc) - txBldr := types.NewTxBuilderFromCLI(inBuf) + clientCtx := client.GetClientContextFromCmd(cmd) + + txBldr, err := types.NewTxBuilderFromFlags(inBuf, cmd.Flags(), clientCtx.HomeDir) + if err != nil { + return err + } + generateSignatureOnly, _ := cmd.Flags().GetBool(flagSigOnly) var ( - err error multisigAddr sdk.AccAddress infile = os.Stdin ) @@ -184,6 +188,7 @@ be generated via the 'multisign' command. ) cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") cmd.Flags().String(flags.FlagOutputDocument, "", "The document will be written to the given file instead of STDOUT") + cmd.Flags().String(flags.FlagHome, "", "The application home directory") cmd = flags.PostCommands(cmd)[0] cmd.MarkFlagRequired(flags.FlagFrom) diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index e6d90509fc03..84f90b6470d4 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -142,8 +142,12 @@ func readStdTxAndInitContexts(clientCtx client.Context, cmd *cobra.Command, file } inBuf := bufio.NewReader(cmd.InOrStdin()) - clientCtx = clientCtx.InitWithInput(inBuf) - txBldr := types.NewTxBuilderFromCLI(inBuf) + clientCtx = clientCtx.WithInput(inBuf) + + txBldr, err := types.NewTxBuilderFromFlags(inBuf, cmd.Flags(), clientCtx.HomeDir) + if err != nil { + return client.Context{}, types.TxBuilder{}, types.StdTx{}, err + } return clientCtx, txBldr, stdTx, nil } diff --git a/x/auth/types/txbuilder.go b/x/auth/types/txbuilder.go index e13aa135e4a8..1eb7f465cfbf 100644 --- a/x/auth/types/txbuilder.go +++ b/x/auth/types/txbuilder.go @@ -52,31 +52,6 @@ func NewTxBuilder( } } -// NewTxBuilderFromCLI returns a new initialized TxBuilder with parameters from -// the command line using Viper. -// Deprecated in favor of NewTxBuilderFromFlagSet -func NewTxBuilderFromCLI(input io.Reader) TxBuilder { - kb, err := keyring.New(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input) - if err != nil { - panic(err) - } - txbldr := TxBuilder{ - keybase: kb, - 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), - } - - txbldr = txbldr.WithFees(viper.GetString(flags.FlagFees)) - txbldr = txbldr.WithGasPrices(viper.GetString(flags.FlagGasPrices)) - - return txbldr -} - // NewTxBuilderFromCLI returns a new initialized TxBuilder with parameters extracted from // FlagSet (It should deprecate NewTxBuilderFromCLI). func NewTxBuilderFromFlags(input io.Reader, fs *pflag.FlagSet, keyringPath string) (TxBuilder, error) {