Skip to content

Commit

Permalink
Remove TxBuilder references to viper. (cosmos#6653)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Bezobchuk <[email protected]>
Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: Alessio Treglia <[email protected]>
  • Loading branch information
4 people authored Jul 10, 2020
1 parent 255ed06 commit 6ceedc9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 38 deletions.
6 changes: 0 additions & 6 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
11 changes: 8 additions & 3 deletions x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions x/auth/client/cli/validate_sigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 0 additions & 25 deletions x/auth/types/txbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6ceedc9

Please sign in to comment.