reduce module interdependancy, /client refactor (#4415)
* abstract staking BuildCreateValidatorMsg, genutil defines its own flags * client/ refactor * staking move keys from keeper to types
This commit is contained in:
committed by
Alessio Treglia
parent
91e75cb74a
commit
73e5ef7c13
+160
@@ -0,0 +1,160 @@
|
||||
// nolint
|
||||
// autogenerated code using github.com/rigelrozanski/multitool
|
||||
// aliases generated for the following subdirectories:
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/context
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/flags
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/keys
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/lcd
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/rest
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/rpc
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/tx
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/utils
|
||||
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/input
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/client/lcd"
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultGasAdjustment = flags.DefaultGasAdjustment
|
||||
DefaultGasLimit = flags.DefaultGasLimit
|
||||
GasFlagAuto = flags.GasFlagAuto
|
||||
BroadcastBlock = flags.BroadcastBlock
|
||||
BroadcastSync = flags.BroadcastSync
|
||||
BroadcastAsync = flags.BroadcastAsync
|
||||
FlagHome = flags.FlagHome
|
||||
FlagUseLedger = flags.FlagUseLedger
|
||||
FlagChainID = flags.FlagChainID
|
||||
FlagNode = flags.FlagNode
|
||||
FlagHeight = flags.FlagHeight
|
||||
FlagGasAdjustment = flags.FlagGasAdjustment
|
||||
FlagTrustNode = flags.FlagTrustNode
|
||||
FlagFrom = flags.FlagFrom
|
||||
FlagName = flags.FlagName
|
||||
FlagAccountNumber = flags.FlagAccountNumber
|
||||
FlagSequence = flags.FlagSequence
|
||||
FlagMemo = flags.FlagMemo
|
||||
FlagFees = flags.FlagFees
|
||||
FlagGasPrices = flags.FlagGasPrices
|
||||
FlagBroadcastMode = flags.FlagBroadcastMode
|
||||
FlagPrintResponse = flags.FlagPrintResponse
|
||||
FlagDryRun = flags.FlagDryRun
|
||||
FlagGenerateOnly = flags.FlagGenerateOnly
|
||||
FlagIndentResponse = flags.FlagIndentResponse
|
||||
FlagListenAddr = flags.FlagListenAddr
|
||||
FlagCORS = flags.FlagCORS
|
||||
FlagMaxOpenConnections = flags.FlagMaxOpenConnections
|
||||
FlagRPCReadTimeout = flags.FlagRPCReadTimeout
|
||||
FlagRPCWriteTimeout = flags.FlagRPCWriteTimeout
|
||||
FlagOutputDocument = flags.FlagOutputDocument
|
||||
FlagSkipConfirmation = flags.FlagSkipConfirmation
|
||||
DefaultKeyPass = keys.DefaultKeyPass
|
||||
FlagAddress = keys.FlagAddress
|
||||
FlagPublicKey = keys.FlagPublicKey
|
||||
FlagBechPrefix = keys.FlagBechPrefix
|
||||
FlagDevice = keys.FlagDevice
|
||||
OutputFormatText = keys.OutputFormatText
|
||||
OutputFormatJSON = keys.OutputFormatJSON
|
||||
MinPassLength = input.MinPassLength
|
||||
)
|
||||
|
||||
var (
|
||||
// functions aliases
|
||||
NewCLIContextWithFrom = context.NewCLIContextWithFrom
|
||||
NewCLIContext = context.NewCLIContext
|
||||
GetAccountDecoder = context.GetAccountDecoder
|
||||
GetFromFields = context.GetFromFields
|
||||
ErrInvalidAccount = context.ErrInvalidAccount
|
||||
ErrVerifyCommit = context.ErrVerifyCommit
|
||||
GetCommands = flags.GetCommands
|
||||
PostCommands = flags.PostCommands
|
||||
RegisterRestServerFlags = flags.RegisterRestServerFlags
|
||||
ParseGas = flags.ParseGas
|
||||
NewCompletionCmd = flags.NewCompletionCmd
|
||||
MarshalJSON = keys.MarshalJSON
|
||||
UnmarshalJSON = keys.UnmarshalJSON
|
||||
Commands = keys.Commands
|
||||
NewAddNewKey = keys.NewAddNewKey
|
||||
NewRecoverKey = keys.NewRecoverKey
|
||||
NewUpdateKeyReq = keys.NewUpdateKeyReq
|
||||
NewDeleteKeyReq = keys.NewDeleteKeyReq
|
||||
GetKeyInfo = keys.GetKeyInfo
|
||||
GetPassphrase = keys.GetPassphrase
|
||||
ReadPassphraseFromStdin = keys.ReadPassphraseFromStdin
|
||||
NewKeyBaseFromHomeFlag = keys.NewKeyBaseFromHomeFlag
|
||||
NewKeyBaseFromDir = keys.NewKeyBaseFromDir
|
||||
NewInMemoryKeyBase = keys.NewInMemoryKeyBase
|
||||
NewRestServer = lcd.NewRestServer
|
||||
ServeCommand = lcd.ServeCommand
|
||||
WriteGenerateStdTxResponse = rest.WriteGenerateStdTxResponse
|
||||
BlockCommand = rpc.BlockCommand
|
||||
GetChainHeight = rpc.GetChainHeight
|
||||
BlockRequestHandlerFn = rpc.BlockRequestHandlerFn
|
||||
LatestBlockRequestHandlerFn = rpc.LatestBlockRequestHandlerFn
|
||||
RegisterRPCRoutes = rpc.RegisterRPCRoutes
|
||||
CLIVersionRequestHandler = rpc.CLIVersionRequestHandler
|
||||
NodeVersionRequestHandler = rpc.NodeVersionRequestHandler
|
||||
StatusCommand = rpc.StatusCommand
|
||||
NodeInfoRequestHandlerFn = rpc.NodeInfoRequestHandlerFn
|
||||
NodeSyncingRequestHandlerFn = rpc.NodeSyncingRequestHandlerFn
|
||||
ValidatorCommand = rpc.ValidatorCommand
|
||||
GetValidators = rpc.GetValidators
|
||||
ValidatorSetRequestHandlerFn = rpc.ValidatorSetRequestHandlerFn
|
||||
LatestValidatorSetRequestHandlerFn = rpc.LatestValidatorSetRequestHandlerFn
|
||||
BroadcastTxRequest = tx.BroadcastTxRequest
|
||||
GetBroadcastCommand = tx.GetBroadcastCommand
|
||||
EncodeTxRequestHandlerFn = tx.EncodeTxRequestHandlerFn
|
||||
GetEncodeCommand = tx.GetEncodeCommand
|
||||
SearchTxCmd = tx.SearchTxCmd
|
||||
QueryTxCmd = tx.QueryTxCmd
|
||||
QueryTxsByTagsRequestHandlerFn = tx.QueryTxsByTagsRequestHandlerFn
|
||||
QueryTxRequestHandlerFn = tx.QueryTxRequestHandlerFn
|
||||
RegisterTxRoutes = tx.RegisterTxRoutes
|
||||
SearchTxs = tx.SearchTxs
|
||||
ValidateTxResult = tx.ValidateTxResult
|
||||
GenerateOrBroadcastMsgs = utils.GenerateOrBroadcastMsgs
|
||||
CompleteAndBroadcastTxCLI = utils.CompleteAndBroadcastTxCLI
|
||||
EnrichWithGas = utils.EnrichWithGas
|
||||
CalculateGas = utils.CalculateGas
|
||||
PrintUnsignedStdTx = utils.PrintUnsignedStdTx
|
||||
SignStdTx = utils.SignStdTx
|
||||
SignStdTxWithSignerAddress = utils.SignStdTxWithSignerAddress
|
||||
ReadStdTxFromFile = utils.ReadStdTxFromFile
|
||||
GetTxEncoder = utils.GetTxEncoder
|
||||
PrepareTxBuilder = utils.PrepareTxBuilder
|
||||
BufferStdin = input.BufferStdin
|
||||
OverrideStdin = input.OverrideStdin
|
||||
GetPassword = input.GetPassword
|
||||
GetCheckPassword = input.GetCheckPassword
|
||||
GetConfirmation = input.GetConfirmation
|
||||
GetString = input.GetString
|
||||
PrintPrefixed = input.PrintPrefixed
|
||||
|
||||
// variable aliases
|
||||
LineBreak = flags.LineBreak
|
||||
GasFlagVar = flags.GasFlagVar
|
||||
)
|
||||
|
||||
type (
|
||||
CLIContext = context.CLIContext
|
||||
GasSetting = flags.GasSetting
|
||||
AddNewKey = keys.AddNewKey
|
||||
RecoverKey = keys.RecoverKey
|
||||
UpdateKeyReq = keys.UpdateKeyReq
|
||||
DeleteKeyReq = keys.DeleteKeyReq
|
||||
RestServer = lcd.RestServer
|
||||
ValidatorOutput = rpc.ValidatorOutput
|
||||
ResultValidatorsOutput = rpc.ResultValidatorsOutput
|
||||
BroadcastReq = tx.BroadcastReq
|
||||
EncodeResp = tx.EncodeResp
|
||||
GasEstimateResponse = utils.GasEstimateResponse
|
||||
)
|
||||
+4
-7
@@ -7,18 +7,15 @@ import (
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
toml "github.com/pelletier/go-toml"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
)
|
||||
|
||||
const (
|
||||
flagGet = "get"
|
||||
|
||||
// DefaultKeyPass contains the default key password for genesis transactions
|
||||
DefaultKeyPass = "12345678"
|
||||
)
|
||||
|
||||
var configDefaults = map[string]string{
|
||||
@@ -38,7 +35,7 @@ func ConfigCmd(defaultCLIHome string) *cobra.Command {
|
||||
Args: cobra.RangeArgs(0, 2),
|
||||
}
|
||||
|
||||
cmd.Flags().String(cli.HomeFlag, defaultCLIHome,
|
||||
cmd.Flags().String(flags.FlagHome, defaultCLIHome,
|
||||
"set client's home directory for configuration")
|
||||
cmd.Flags().Bool(flagGet, false,
|
||||
"print configuration value or its default if unset")
|
||||
@@ -46,7 +43,7 @@ func ConfigCmd(defaultCLIHome string) *cobra.Command {
|
||||
}
|
||||
|
||||
func runConfigCmd(cmd *cobra.Command, args []string) error {
|
||||
cfgFile, err := ensureConfFile(viper.GetString(cli.HomeFlag))
|
||||
cfgFile, err := ensureConfFile(viper.GetString(flags.FlagHome))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
)
|
||||
|
||||
// For https://github.com/cosmos/cosmos-sdk/issues/3899
|
||||
@@ -19,7 +20,7 @@ func Test_runConfigCmdTwiceWithShorterNodeValue(t *testing.T) {
|
||||
configHome, cleanup := tmpDir(t)
|
||||
defer cleanup()
|
||||
_ = os.RemoveAll(filepath.Join(configHome, "config"))
|
||||
viper.Set(cli.HomeFlag, configHome)
|
||||
viper.Set(flags.FlagHome, configHome)
|
||||
|
||||
// Init command config
|
||||
cmd := ConfigCmd(configHome)
|
||||
|
||||
@@ -3,7 +3,7 @@ package context
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@@ -13,13 +13,13 @@ import (
|
||||
// defined.
|
||||
func (ctx CLIContext) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error) {
|
||||
switch ctx.BroadcastMode {
|
||||
case client.BroadcastSync:
|
||||
case flags.BroadcastSync:
|
||||
res, err = ctx.BroadcastTxSync(txBytes)
|
||||
|
||||
case client.BroadcastAsync:
|
||||
case flags.BroadcastAsync:
|
||||
res, err = ctx.BroadcastTxAsync(txBytes)
|
||||
|
||||
case client.BroadcastBlock:
|
||||
case flags.BroadcastBlock:
|
||||
res, err = ctx.BroadcastTxCommit(txBytes)
|
||||
|
||||
default:
|
||||
|
||||
+20
-20
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
@@ -65,7 +65,7 @@ func NewCLIContextWithFrom(from string) CLIContext {
|
||||
var nodeURI string
|
||||
var rpc rpcclient.Client
|
||||
|
||||
genOnly := viper.GetBool(client.FlagGenerateOnly)
|
||||
genOnly := viper.GetBool(flags.FlagGenerateOnly)
|
||||
fromAddress, fromName, err := GetFromFields(from, genOnly)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to get from fields: %v", err)
|
||||
@@ -73,16 +73,16 @@ func NewCLIContextWithFrom(from string) CLIContext {
|
||||
}
|
||||
|
||||
if !genOnly {
|
||||
nodeURI = viper.GetString(client.FlagNode)
|
||||
nodeURI = viper.GetString(flags.FlagNode)
|
||||
if nodeURI != "" {
|
||||
rpc = rpcclient.NewHTTP(nodeURI, "/websocket")
|
||||
}
|
||||
}
|
||||
|
||||
// We need to use a single verifier for all contexts
|
||||
if verifier == nil || verifierHome != viper.GetString(cli.HomeFlag) {
|
||||
if verifier == nil || verifierHome != viper.GetString(flags.FlagHome) {
|
||||
verifier = createVerifier()
|
||||
verifierHome = viper.GetString(cli.HomeFlag)
|
||||
verifierHome = viper.GetString(flags.FlagHome)
|
||||
}
|
||||
|
||||
return CLIContext{
|
||||
@@ -90,41 +90,41 @@ func NewCLIContextWithFrom(from string) CLIContext {
|
||||
Output: os.Stdout,
|
||||
NodeURI: nodeURI,
|
||||
AccountStore: auth.StoreKey,
|
||||
From: viper.GetString(client.FlagFrom),
|
||||
From: viper.GetString(flags.FlagFrom),
|
||||
OutputFormat: viper.GetString(cli.OutputFlag),
|
||||
Height: viper.GetInt64(client.FlagHeight),
|
||||
TrustNode: viper.GetBool(client.FlagTrustNode),
|
||||
UseLedger: viper.GetBool(client.FlagUseLedger),
|
||||
BroadcastMode: viper.GetString(client.FlagBroadcastMode),
|
||||
PrintResponse: viper.GetBool(client.FlagPrintResponse),
|
||||
Height: viper.GetInt64(flags.FlagHeight),
|
||||
TrustNode: viper.GetBool(flags.FlagTrustNode),
|
||||
UseLedger: viper.GetBool(flags.FlagUseLedger),
|
||||
BroadcastMode: viper.GetString(flags.FlagBroadcastMode),
|
||||
PrintResponse: viper.GetBool(flags.FlagPrintResponse),
|
||||
Verifier: verifier,
|
||||
Simulate: viper.GetBool(client.FlagDryRun),
|
||||
Simulate: viper.GetBool(flags.FlagDryRun),
|
||||
GenerateOnly: genOnly,
|
||||
FromAddress: fromAddress,
|
||||
FromName: fromName,
|
||||
Indent: viper.GetBool(client.FlagIndentResponse),
|
||||
SkipConfirm: viper.GetBool(client.FlagSkipConfirmation),
|
||||
Indent: viper.GetBool(flags.FlagIndentResponse),
|
||||
SkipConfirm: viper.GetBool(flags.FlagSkipConfirmation),
|
||||
}
|
||||
}
|
||||
|
||||
// NewCLIContext returns a new initialized CLIContext with parameters from the
|
||||
// command line using Viper.
|
||||
func NewCLIContext() CLIContext { return NewCLIContextWithFrom(viper.GetString(client.FlagFrom)) }
|
||||
func NewCLIContext() CLIContext { return NewCLIContextWithFrom(viper.GetString(flags.FlagFrom)) }
|
||||
|
||||
func createVerifier() tmlite.Verifier {
|
||||
trustNodeDefined := viper.IsSet(client.FlagTrustNode)
|
||||
trustNodeDefined := viper.IsSet(flags.FlagTrustNode)
|
||||
if !trustNodeDefined {
|
||||
return nil
|
||||
}
|
||||
|
||||
trustNode := viper.GetBool(client.FlagTrustNode)
|
||||
trustNode := viper.GetBool(flags.FlagTrustNode)
|
||||
if trustNode {
|
||||
return nil
|
||||
}
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
home := viper.GetString(cli.HomeFlag)
|
||||
nodeURI := viper.GetString(client.FlagNode)
|
||||
chainID := viper.GetString(flags.FlagChainID)
|
||||
home := viper.GetString(flags.FlagHome)
|
||||
nodeURI := viper.GetString(flags.FlagNode)
|
||||
|
||||
var errMsg bytes.Buffer
|
||||
if chainID == "" {
|
||||
|
||||
@@ -2,14 +2,10 @@ package context
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"strings"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
@@ -19,6 +15,8 @@ import (
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
// GetNode returns an RPC client. If the context's client is not defined, an
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package client
|
||||
|
||||
import "errors"
|
||||
|
||||
// common errors for CLI and REST clients
|
||||
var (
|
||||
ErrInvalidGasAdjustment = errors.New("invalid gas adjustment")
|
||||
ErrInvalidSigner = errors.New("tx intended signer does not match the given signer")
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
package client
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
)
|
||||
|
||||
// nolint
|
||||
@@ -28,6 +30,7 @@ const (
|
||||
// immediately.
|
||||
BroadcastAsync = "async"
|
||||
|
||||
FlagHome = tmcli.HomeFlag
|
||||
FlagUseLedger = "ledger"
|
||||
FlagChainID = "chain-id"
|
||||
FlagNode = "node"
|
||||
@@ -1,13 +1,12 @@
|
||||
package client
|
||||
package input
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/bgentry/speakeasy"
|
||||
isatty "github.com/mattn/go-isatty"
|
||||
)
|
||||
+17
-13
@@ -6,7 +6,8 @@ import (
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
@@ -31,6 +32,9 @@ const (
|
||||
flagIndex = "index"
|
||||
flagMultisig = "multisig"
|
||||
flagNoSort = "nosort"
|
||||
|
||||
// DefaultKeyPass contains the default key password for genesis transactions
|
||||
DefaultKeyPass = "12345678"
|
||||
)
|
||||
|
||||
func addKeyCommand() *cobra.Command {
|
||||
@@ -62,13 +66,13 @@ the flag --nosort is set.
|
||||
cmd.Flags().Bool(flagNoSort, false, "Keys passed to --multisig are taken in the order they're supplied")
|
||||
cmd.Flags().String(FlagPublicKey, "", "Parse a public key in bech32 format and save it to disk")
|
||||
cmd.Flags().BoolP(flagInteractive, "i", false, "Interactively prompt user for BIP39 passphrase and mnemonic")
|
||||
cmd.Flags().Bool(client.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device")
|
||||
cmd.Flags().Bool(flags.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device")
|
||||
cmd.Flags().Bool(flagRecover, false, "Provide seed phrase to recover existing key instead of creating")
|
||||
cmd.Flags().Bool(flagNoBackup, false, "Don't print out seed phrase (if others are watching the terminal)")
|
||||
cmd.Flags().Bool(flagDryRun, false, "Perform action, but don't add key to local keystore")
|
||||
cmd.Flags().Uint32(flagAccount, 0, "Account number for HD derivation")
|
||||
cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation")
|
||||
cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -86,7 +90,7 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
var err error
|
||||
var encryptPassword string
|
||||
|
||||
buf := client.BufferStdin()
|
||||
buf := input.BufferStdin()
|
||||
name := args[0]
|
||||
|
||||
interactive := viper.GetBool(flagInteractive)
|
||||
@@ -96,7 +100,7 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
// we throw this away, so don't enforce args,
|
||||
// we want to get a new random seed phrase quickly
|
||||
kb = keys.NewInMemory()
|
||||
encryptPassword = client.DefaultKeyPass
|
||||
encryptPassword = DefaultKeyPass
|
||||
} else {
|
||||
kb, err = NewKeyBaseFromHomeFlag()
|
||||
if err != nil {
|
||||
@@ -106,7 +110,7 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
_, err = kb.Get(name)
|
||||
if err == nil {
|
||||
// account exists, ask for user confirmation
|
||||
if response, err2 := client.GetConfirmation(
|
||||
if response, err2 := input.GetConfirmation(
|
||||
fmt.Sprintf("override the existing name %s", name), buf); err2 != nil || !response {
|
||||
return err2
|
||||
}
|
||||
@@ -146,8 +150,8 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// ask for a password when generating a local key
|
||||
if viper.GetString(FlagPublicKey) == "" && !viper.GetBool(client.FlagUseLedger) {
|
||||
encryptPassword, err = client.GetCheckPassword(
|
||||
if viper.GetString(FlagPublicKey) == "" && !viper.GetBool(flags.FlagUseLedger) {
|
||||
encryptPassword, err = input.GetCheckPassword(
|
||||
"Enter a passphrase to encrypt your key to disk:",
|
||||
"Repeat the passphrase:", buf)
|
||||
if err != nil {
|
||||
@@ -172,7 +176,7 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
index := uint32(viper.GetInt(flagIndex))
|
||||
|
||||
// If we're using ledger, only thing we need is the path and the bech32 prefix.
|
||||
if viper.GetBool(client.FlagUseLedger) {
|
||||
if viper.GetBool(flags.FlagUseLedger) {
|
||||
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
|
||||
info, err := kb.CreateLedger(name, keys.Secp256k1, bech32PrefixAccAddr, account, index)
|
||||
if err != nil {
|
||||
@@ -192,7 +196,7 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
bip39Message = "Enter your bip39 mnemonic, or hit enter to generate one."
|
||||
}
|
||||
|
||||
mnemonic, err = client.GetString(bip39Message, buf)
|
||||
mnemonic, err = input.GetString(bip39Message, buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -217,7 +221,7 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
|
||||
// override bip39 passphrase
|
||||
if interactive {
|
||||
bip39Passphrase, err = client.GetString(
|
||||
bip39Passphrase, err = input.GetString(
|
||||
"Enter your bip39 passphrase. This is combined with the mnemonic to derive the seed. "+
|
||||
"Most users should just hit enter to use the default, \"\"", buf)
|
||||
if err != nil {
|
||||
@@ -226,7 +230,7 @@ func runAddCmd(_ *cobra.Command, args []string) error {
|
||||
|
||||
// if they use one, make them re-enter it
|
||||
if len(bip39Passphrase) != 0 {
|
||||
p2, err := client.GetString("Repeat the passphrase:", buf)
|
||||
p2, err := input.GetString("Repeat the passphrase:", buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -278,7 +282,7 @@ func printCreate(info keys.Info, showMnemonic bool, mnemonic string) error {
|
||||
}
|
||||
|
||||
var jsonString []byte
|
||||
if viper.GetBool(client.FlagIndentResponse) {
|
||||
if viper.GetBool(flags.FlagIndentResponse) {
|
||||
jsonString, err = cdc.MarshalJSONIndent(out, "", " ")
|
||||
} else {
|
||||
jsonString, err = cdc.MarshalJSON(out)
|
||||
|
||||
@@ -7,17 +7,16 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func Test_runAddCmdLedger(t *testing.T) {
|
||||
@@ -28,13 +27,13 @@ func Test_runAddCmdLedger(t *testing.T) {
|
||||
kbHome, kbCleanUp := tests.NewTestCaseDir(t)
|
||||
assert.NotNil(t, kbHome)
|
||||
defer kbCleanUp()
|
||||
viper.Set(cli.HomeFlag, kbHome)
|
||||
viper.Set(client.FlagUseLedger, true)
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
viper.Set(flags.FlagUseLedger, true)
|
||||
|
||||
/// Test Text
|
||||
viper.Set(cli.OutputFlag, OutputFormatText)
|
||||
// Now enter password
|
||||
cleanUp1 := client.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
cleanUp1 := input.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
defer cleanUp1()
|
||||
err := runAddCmd(cmd, []string{"keyname1"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_runAddCmdBasic(t *testing.T) {
|
||||
@@ -23,12 +23,12 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
kbHome, kbCleanUp := tests.NewTestCaseDir(t)
|
||||
assert.NotNil(t, kbHome)
|
||||
defer kbCleanUp()
|
||||
viper.Set(cli.HomeFlag, kbHome)
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
/// Test Text
|
||||
viper.Set(cli.OutputFlag, OutputFormatText)
|
||||
// Now enter password
|
||||
cleanUp1 := client.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
cleanUp1 := input.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
defer cleanUp1()
|
||||
err := runAddCmd(cmd, []string{"keyname1"})
|
||||
assert.NoError(t, err)
|
||||
@@ -36,7 +36,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
/// Test Text - Replace? >> FAIL
|
||||
viper.Set(cli.OutputFlag, OutputFormatText)
|
||||
// Now enter password
|
||||
cleanUp2 := client.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
cleanUp2 := input.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
defer cleanUp2()
|
||||
err = runAddCmd(cmd, []string{"keyname1"})
|
||||
assert.Error(t, err)
|
||||
@@ -44,7 +44,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
/// Test Text - Replace? Answer >> PASS
|
||||
viper.Set(cli.OutputFlag, OutputFormatText)
|
||||
// Now enter password
|
||||
cleanUp3 := client.OverrideStdin(bufio.NewReader(strings.NewReader("y\ntest1234\ntest1234\n")))
|
||||
cleanUp3 := input.OverrideStdin(bufio.NewReader(strings.NewReader("y\ntest1234\ntest1234\n")))
|
||||
defer cleanUp3()
|
||||
err = runAddCmd(cmd, []string{"keyname1"})
|
||||
assert.NoError(t, err)
|
||||
@@ -52,7 +52,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
// Check JSON
|
||||
viper.Set(cli.OutputFlag, OutputFormatJSON)
|
||||
// Now enter password
|
||||
cleanUp4 := client.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
cleanUp4 := input.OverrideStdin(bufio.NewReader(strings.NewReader("test1234\ntest1234\n")))
|
||||
defer cleanUp4()
|
||||
err = runAddCmd(cmd, []string{"keyname2"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -53,7 +53,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
buf := client.BufferStdin()
|
||||
buf := input.BufferStdin()
|
||||
if info.GetType() == keys.TypeLedger || info.GetType() == keys.TypeOffline {
|
||||
if !viper.GetBool(flagYes) {
|
||||
if err := confirmDeletion(buf); err != nil {
|
||||
@@ -71,7 +71,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
|
||||
skipPass := viper.GetBool(flagForce)
|
||||
var oldpass string
|
||||
if !skipPass {
|
||||
if oldpass, err = client.GetPassword(
|
||||
if oldpass, err = input.GetPassword(
|
||||
"DANGER - enter password to permanently delete key:", buf); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func confirmDeletion(buf *bufio.Reader) error {
|
||||
answer, err := client.GetConfirmation("Key reference will be deleted. Continue?", buf)
|
||||
answer, err := input.GetConfirmation("Key reference will be deleted. Continue?", buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
)
|
||||
|
||||
@@ -29,7 +28,7 @@ func Test_runDeleteCmd(t *testing.T) {
|
||||
// Now add a temporary keybase
|
||||
kbHome, cleanUp := tests.NewTestCaseDir(t)
|
||||
defer cleanUp()
|
||||
viper.Set(cli.HomeFlag, kbHome)
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
// Now
|
||||
kb, err := NewKeyBaseFromHomeFlag()
|
||||
@@ -53,7 +52,7 @@ func Test_runDeleteCmd(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now there is a confirmation
|
||||
cleanUp := client.OverrideStdin(bufio.NewReader(strings.NewReader("y\n")))
|
||||
cleanUp := input.OverrideStdin(bufio.NewReader(strings.NewReader("y\n")))
|
||||
defer cleanUp()
|
||||
err = runDeleteCmd(deleteKeyCommand, []string{fakeKeyName1})
|
||||
require.NoError(t, err)
|
||||
|
||||
+2
-3
@@ -1,9 +1,8 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
)
|
||||
|
||||
func listKeysCmd() *cobra.Command {
|
||||
@@ -14,7 +13,7 @@ func listKeysCmd() *cobra.Command {
|
||||
along with their associated name and address.`,
|
||||
RunE: runListCmd,
|
||||
}
|
||||
cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,12 @@ package keys
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func Test_runListCmd(t *testing.T) {
|
||||
@@ -28,7 +26,7 @@ func Test_runListCmd(t *testing.T) {
|
||||
|
||||
kbHome2, cleanUp2 := tests.NewTestCaseDir(t)
|
||||
defer cleanUp2()
|
||||
viper.Set(cli.HomeFlag, kbHome2)
|
||||
viper.Set(flags.FlagHome, kbHome2)
|
||||
|
||||
kb, err := NewKeyBaseFromHomeFlag()
|
||||
assert.NoError(t, err)
|
||||
@@ -47,7 +45,7 @@ func Test_runListCmd(t *testing.T) {
|
||||
}
|
||||
for _, tt := range testData {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
viper.Set(cli.HomeFlag, tt.kbDir)
|
||||
viper.Set(flags.FlagHome, tt.kbDir)
|
||||
if err := runListCmd(tt.args.cmd, tt.args.args); (err != nil) != tt.wantErr {
|
||||
t.Errorf("runListCmd() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
bip39 "github.com/bartekn/go-bip39"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -36,15 +36,15 @@ func runMnemonicCmd(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if userEntropy {
|
||||
// prompt the user to enter some entropy
|
||||
buf := client.BufferStdin()
|
||||
inputEntropy, err := client.GetString("> WARNING: Generate at least 256-bits of entropy and enter the results here:", buf)
|
||||
buf := input.BufferStdin()
|
||||
inputEntropy, err := input.GetString("> WARNING: Generate at least 256-bits of entropy and enter the results here:", buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(inputEntropy) < 43 {
|
||||
return fmt.Errorf("256-bits is 43 characters in Base-64, and 100 in Base-6. You entered %v, and probably want more", len(inputEntropy))
|
||||
}
|
||||
conf, err := client.GetConfirmation(fmt.Sprintf("> Input length: %d", len(inputEntropy)), buf)
|
||||
conf, err := input.GetConfirmation(fmt.Sprintf("> Input length: %d", len(inputEntropy)), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,10 +5,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -28,7 +26,7 @@ func Test_RunMnemonicCmdUser(t *testing.T) {
|
||||
require.Equal(t, "EOF", err.Error())
|
||||
|
||||
// Try again
|
||||
cleanUp := client.OverrideStdin(bufio.NewReader(strings.NewReader("Hi!\n")))
|
||||
cleanUp := input.OverrideStdin(bufio.NewReader(strings.NewReader("Hi!\n")))
|
||||
defer cleanUp()
|
||||
err = runMnemonicCmd(cmdUser, []string{})
|
||||
require.Error(t, err)
|
||||
@@ -38,21 +36,21 @@ func Test_RunMnemonicCmdUser(t *testing.T) {
|
||||
|
||||
// Now provide "good" entropy :)
|
||||
fakeEntropy := strings.Repeat(":)", 40) + "\ny\n" // entropy + accept count
|
||||
cleanUp2 := client.OverrideStdin(bufio.NewReader(strings.NewReader(fakeEntropy)))
|
||||
cleanUp2 := input.OverrideStdin(bufio.NewReader(strings.NewReader(fakeEntropy)))
|
||||
defer cleanUp2()
|
||||
err = runMnemonicCmd(cmdUser, []string{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now provide "good" entropy but no answer
|
||||
fakeEntropy = strings.Repeat(":)", 40) + "\n" // entropy + accept count
|
||||
cleanUp3 := client.OverrideStdin(bufio.NewReader(strings.NewReader(fakeEntropy)))
|
||||
cleanUp3 := input.OverrideStdin(bufio.NewReader(strings.NewReader(fakeEntropy)))
|
||||
defer cleanUp3()
|
||||
err = runMnemonicCmd(cmdUser, []string{})
|
||||
require.Error(t, err)
|
||||
|
||||
// Now provide "good" entropy but say no
|
||||
fakeEntropy = strings.Repeat(":)", 40) + "\nn\n" // entropy + accept count
|
||||
cleanUp4 := client.OverrideStdin(bufio.NewReader(strings.NewReader(fakeEntropy)))
|
||||
cleanUp4 := input.OverrideStdin(bufio.NewReader(strings.NewReader(fakeEntropy)))
|
||||
defer cleanUp4()
|
||||
err = runMnemonicCmd(cmdUser, []string{})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bech32"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@@ -74,7 +75,7 @@ hexadecimal into bech32 cosmos prefixed format and vice versa.
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: parseKey,
|
||||
}
|
||||
cmd.Flags().Bool(client.FlagIndentResponse, false, "Indent JSON output")
|
||||
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Indent JSON output")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -119,7 +120,7 @@ func displayParseKeyInfo(stringer fmt.Stringer) {
|
||||
var out []byte
|
||||
var err error
|
||||
|
||||
if viper.GetBool(client.FlagIndentResponse) {
|
||||
if viper.GetBool(flags.FlagIndentResponse) {
|
||||
out, err = cdc.MarshalJSONIndent(stringer, "", " ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package keys
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
)
|
||||
|
||||
// Commands registers a sub-tree of commands to interact with
|
||||
@@ -23,7 +23,7 @@ func Commands() *cobra.Command {
|
||||
addKeyCommand(),
|
||||
listKeysCmd(),
|
||||
showKeysCmd(),
|
||||
client.LineBreak,
|
||||
flags.LineBreak,
|
||||
deleteKeyCommand(),
|
||||
updateKeyCommand(),
|
||||
parseKeyStringCommand(),
|
||||
|
||||
+6
-7
@@ -4,18 +4,17 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/multisig"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -51,7 +50,7 @@ consisting of all the keys provided by name and multisig threshold.`,
|
||||
cmd.Flags().BoolP(FlagDevice, "d", false, "Output the address in a ledger device")
|
||||
cmd.Flags().Uint(flagMultiSigThreshold, 1, "K out of N required signatures")
|
||||
cmd.Flags().BoolP(flagShowMultiSig, "m", false, "Output multisig pubkey constituents, threshold, and weights")
|
||||
cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -3,17 +3,17 @@ package keys
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/multisig"
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func Test_multiSigKey_Properties(t *testing.T) {
|
||||
@@ -47,7 +47,7 @@ func Test_runShowCmd(t *testing.T) {
|
||||
// Now add a temporary keybase
|
||||
kbHome, cleanUp := tests.NewTestCaseDir(t)
|
||||
defer cleanUp()
|
||||
viper.Set(cli.HomeFlag, kbHome)
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
fakeKeyName1 := "runShowCmd_Key1"
|
||||
fakeKeyName2 := "runShowCmd_Key2"
|
||||
|
||||
@@ -3,8 +3,7 @@ package keys
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -21,19 +20,19 @@ func updateKeyCommand() *cobra.Command {
|
||||
func runUpdateCmd(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
buf := client.BufferStdin()
|
||||
buf := input.BufferStdin()
|
||||
kb, err := NewKeyBaseFromHomeFlag()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
oldpass, err := client.GetPassword(
|
||||
oldpass, err := input.GetPassword(
|
||||
"Enter the current passphrase:", buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
getNewpass := func() (string, error) {
|
||||
return client.GetCheckPassword(
|
||||
return input.GetCheckPassword(
|
||||
"Enter the new passphrase:",
|
||||
"Repeat the new passphrase:", buf)
|
||||
}
|
||||
|
||||
@@ -5,14 +5,12 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
)
|
||||
|
||||
func Test_updateKeyCommand(t *testing.T) {
|
||||
@@ -31,7 +29,7 @@ func Test_runUpdateCmd(t *testing.T) {
|
||||
err := runUpdateCmd(cmd, []string{fakeKeyName1})
|
||||
assert.EqualError(t, err, "EOF")
|
||||
|
||||
cleanUp := client.OverrideStdin(bufio.NewReader(strings.NewReader("pass1234\n")))
|
||||
cleanUp := input.OverrideStdin(bufio.NewReader(strings.NewReader("pass1234\n")))
|
||||
defer cleanUp()
|
||||
|
||||
// try again
|
||||
@@ -42,7 +40,7 @@ func Test_runUpdateCmd(t *testing.T) {
|
||||
// Now add a temporary keybase
|
||||
kbHome, cleanUp1 := tests.NewTestCaseDir(t)
|
||||
defer cleanUp1()
|
||||
viper.Set(cli.HomeFlag, kbHome)
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
kb, err := NewKeyBaseFromHomeFlag()
|
||||
assert.NoError(t, err)
|
||||
@@ -52,7 +50,7 @@ func Test_runUpdateCmd(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Try again now that we have keys
|
||||
cleanUp2 := client.OverrideStdin(bufio.NewReader(strings.NewReader("pass1234\nNew1234\nNew1234")))
|
||||
cleanUp2 := input.OverrideStdin(bufio.NewReader(strings.NewReader("pass1234\nNew1234\nNew1234")))
|
||||
defer cleanUp2()
|
||||
|
||||
// Incorrect key type
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
)
|
||||
|
||||
@@ -62,10 +63,10 @@ func GetPassphrase(name string) (string, error) {
|
||||
// ReadPassphraseFromStdin attempts to read a passphrase from STDIN return an
|
||||
// error upon failure.
|
||||
func ReadPassphraseFromStdin(name string) (string, error) {
|
||||
buf := client.BufferStdin()
|
||||
buf := input.BufferStdin()
|
||||
prompt := fmt.Sprintf("Password to sign with '%s':", name)
|
||||
|
||||
passphrase, err := client.GetPassword(prompt, buf)
|
||||
passphrase, err := input.GetPassword(prompt, buf)
|
||||
if err != nil {
|
||||
return passphrase, fmt.Errorf("Error reading passphrase: %v", err)
|
||||
}
|
||||
@@ -75,7 +76,7 @@ func ReadPassphraseFromStdin(name string) (string, error) {
|
||||
|
||||
// NewKeyBaseFromHomeFlag initializes a Keybase based on the configuration.
|
||||
func NewKeyBaseFromHomeFlag() (keys.Keybase, error) {
|
||||
rootDir := viper.GetString(cli.HomeFlag)
|
||||
rootDir := viper.GetString(flags.FlagHome)
|
||||
return NewKeyBaseFromDir(rootDir)
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ func printKeyInfo(keyInfo keys.Info, bechKeyOut bechKeyOutFn) {
|
||||
case OutputFormatJSON:
|
||||
var out []byte
|
||||
var err error
|
||||
if viper.GetBool(client.FlagIndentResponse) {
|
||||
if viper.GetBool(flags.FlagIndentResponse) {
|
||||
out, err = cdc.MarshalJSONIndent(ko, "", " ")
|
||||
} else {
|
||||
out, err = cdc.MarshalJSON(ko)
|
||||
@@ -147,7 +148,7 @@ func printInfos(infos []keys.Info) {
|
||||
var out []byte
|
||||
var err error
|
||||
|
||||
if viper.GetBool(client.FlagIndentResponse) {
|
||||
if viper.GetBool(flags.FlagIndentResponse) {
|
||||
out, err = cdc.MarshalJSONIndent(kos, "", " ")
|
||||
} else {
|
||||
out, err = cdc.MarshalJSON(kos)
|
||||
|
||||
+7
-7
@@ -12,8 +12,8 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
keybase "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
@@ -65,7 +65,7 @@ func (rs *RestServer) Start(listenAddr string, maxOpen int, readTimeout, writeTi
|
||||
rs.log.Info(
|
||||
fmt.Sprintf(
|
||||
"Starting application REST service (chain-id: %q)...",
|
||||
viper.GetString(client.FlagChainID),
|
||||
viper.GetString(flags.FlagChainID),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -86,15 +86,15 @@ func ServeCommand(cdc *codec.Codec, registerRoutesFn func(*RestServer)) *cobra.C
|
||||
|
||||
// Start the rest server and return error if one exists
|
||||
err = rs.Start(
|
||||
viper.GetString(client.FlagListenAddr),
|
||||
viper.GetInt(client.FlagMaxOpenConnections),
|
||||
uint(viper.GetInt(client.FlagRPCReadTimeout)),
|
||||
uint(viper.GetInt(client.FlagRPCWriteTimeout)),
|
||||
viper.GetString(flags.FlagListenAddr),
|
||||
viper.GetInt(flags.FlagMaxOpenConnections),
|
||||
uint(viper.GetInt(flags.FlagRPCReadTimeout)),
|
||||
uint(viper.GetInt(flags.FlagRPCWriteTimeout)),
|
||||
)
|
||||
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
return client.RegisterRestServerFlags(cmd)
|
||||
return flags.RegisterRestServerFlags(cmd)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package rest
|
||||
|
||||
import "errors"
|
||||
|
||||
var errInvalidGasAdjustment = errors.New("invalid gas adjustment")
|
||||
+4
-4
@@ -4,8 +4,8 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -21,12 +21,12 @@ import (
|
||||
func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
|
||||
cliCtx context.CLIContext, br rest.BaseReq, msgs []sdk.Msg) {
|
||||
|
||||
gasAdj, ok := rest.ParseFloat64OrReturnBadRequest(w, br.GasAdjustment, client.DefaultGasAdjustment)
|
||||
gasAdj, ok := rest.ParseFloat64OrReturnBadRequest(w, br.GasAdjustment, flags.DefaultGasAdjustment)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
simAndExec, gas, err := client.ParseGas(br.Gas)
|
||||
simAndExec, gas, err := flags.ParseGas(br.Gas)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
@@ -39,7 +39,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
|
||||
|
||||
if br.Simulate || simAndExec {
|
||||
if gasAdj < 0 {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, client.ErrInvalidGasAdjustment.Error())
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, errInvalidGasAdjustment.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -9,8 +9,9 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
|
||||
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"
|
||||
@@ -24,10 +25,10 @@ func BlockCommand() *cobra.Command {
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: printBlock,
|
||||
}
|
||||
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(client.FlagNode, cmd.Flags().Lookup(client.FlagNode))
|
||||
cmd.Flags().Bool(client.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(client.FlagTrustNode, cmd.Flags().Lookup(client.FlagTrustNode))
|
||||
cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
|
||||
cmd.Flags().Bool(flags.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -64,9 +65,9 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) {
|
||||
}
|
||||
|
||||
if cliCtx.Indent {
|
||||
return cdc.MarshalJSONIndent(res, "", " ")
|
||||
return codec.Cdc.MarshalJSONIndent(res, "", " ")
|
||||
}
|
||||
return cdc.MarshalJSON(res)
|
||||
return codec.Cdc.MarshalJSON(res)
|
||||
}
|
||||
|
||||
// get the current blockchain height
|
||||
@@ -130,7 +131,7 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
|
||||
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +144,6 @@ func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
|
||||
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
amino "github.com/tendermint/go-amino"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
)
|
||||
|
||||
var cdc = amino.NewCodec()
|
||||
|
||||
func init() {
|
||||
ctypes.RegisterAmino(cdc)
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// Register REST endpoints
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
||||
func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
||||
r.HandleFunc("/version", CLIVersionRequestHandler).Methods("GET")
|
||||
r.HandleFunc("/node_version", NodeVersionRequestHandler(cliCtx)).Methods("GET")
|
||||
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(cliCtx)).Methods("GET")
|
||||
|
||||
@@ -11,8 +11,9 @@ import (
|
||||
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
)
|
||||
|
||||
@@ -24,9 +25,9 @@ func StatusCommand() *cobra.Command {
|
||||
RunE: printNodeStatus,
|
||||
}
|
||||
|
||||
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(client.FlagNode, cmd.Flags().Lookup(client.FlagNode))
|
||||
cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
|
||||
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
|
||||
|
||||
func printNodeStatus(cmd *cobra.Command, args []string) error {
|
||||
// No need to verify proof in getting node status
|
||||
viper.Set(client.FlagTrustNode, true)
|
||||
viper.Set(flags.FlagTrustNode, true)
|
||||
cliCtx := context.NewCLIContext()
|
||||
status, err := getNodeStatus(cliCtx)
|
||||
if err != nil {
|
||||
@@ -53,9 +54,9 @@ func printNodeStatus(cmd *cobra.Command, args []string) error {
|
||||
|
||||
var output []byte
|
||||
if cliCtx.Indent {
|
||||
output, err = cdc.MarshalJSONIndent(status, "", " ")
|
||||
output, err = codec.Cdc.MarshalJSONIndent(status, "", " ")
|
||||
} else {
|
||||
output, err = cdc.MarshalJSON(status)
|
||||
output, err = codec.Cdc.MarshalJSON(status)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -77,7 +78,7 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
nodeInfo := status.NodeInfo
|
||||
rest.PostProcessResponse(w, cdc, nodeInfo, cliCtx.Indent)
|
||||
rest.PostProcessResponse(w, codec.Cdc, nodeInfo, cliCtx.Indent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
@@ -54,12 +54,12 @@ func ValidatorCommand(cdc *codec.Codec) *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(client.FlagNode, cmd.Flags().Lookup(client.FlagNode))
|
||||
cmd.Flags().Bool(client.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(client.FlagTrustNode, cmd.Flags().Lookup(client.FlagTrustNode))
|
||||
cmd.Flags().Bool(client.FlagIndentResponse, false, "indent JSON response")
|
||||
viper.BindPFlag(client.FlagIndentResponse, cmd.Flags().Lookup(client.FlagIndentResponse))
|
||||
cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
|
||||
cmd.Flags().Bool(flags.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
|
||||
cmd.Flags().Bool(flags.FlagIndentResponse, false, "indent JSON response")
|
||||
viper.BindPFlag(flags.FlagIndentResponse, cmd.Flags().Lookup(flags.FlagIndentResponse))
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -113,6 +113,7 @@ func bech32ValidatorOutput(validator *tmtypes.Validator) (ValidatorOutput, error
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetValidators from client
|
||||
func GetValidators(cliCtx context.CLIContext, height *int64) (ResultValidatorsOutput, error) {
|
||||
// get the node
|
||||
node, err := cliCtx.GetNode()
|
||||
@@ -175,7 +176,7 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
|
||||
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +189,6 @@ func LatestValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerF
|
||||
return
|
||||
}
|
||||
|
||||
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
|
||||
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
@@ -92,5 +92,5 @@ $ <appcli> tx broadcast ./mytxn.json
|
||||
},
|
||||
}
|
||||
|
||||
return client.PostCommands(cmd)[0]
|
||||
return flags.PostCommands(cmd)[0]
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
@@ -101,5 +101,5 @@ If you supply a dash (-) argument in place of an input filename, the command rea
|
||||
},
|
||||
}
|
||||
|
||||
return client.PostCommands(cmd)[0]
|
||||
return flags.PostCommands(cmd)[0]
|
||||
}
|
||||
|
||||
+9
-9
@@ -11,8 +11,8 @@ import (
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
@@ -92,10 +92,10 @@ $ <appcli> query txs --tags '<tag1>:<value1>&<tag2>:<value2>' --page 1 --limit 3
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(client.FlagNode, cmd.Flags().Lookup(client.FlagNode))
|
||||
cmd.Flags().Bool(client.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(client.FlagTrustNode, cmd.Flags().Lookup(client.FlagTrustNode))
|
||||
cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
|
||||
cmd.Flags().Bool(flags.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
|
||||
|
||||
cmd.Flags().String(flagTags, "", "tag:value list of tags that must match")
|
||||
cmd.Flags().Uint32(flagPage, rest.DefaultPage, "Query a specific page of paginated results")
|
||||
@@ -127,10 +127,10 @@ func QueryTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(client.FlagNode, cmd.Flags().Lookup(client.FlagNode))
|
||||
cmd.Flags().Bool(client.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(client.FlagTrustNode, cmd.Flags().Lookup(client.FlagTrustNode))
|
||||
cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
|
||||
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
|
||||
cmd.Flags().Bool(flags.FlagTrustNode, false, "Trust connected full node (don't verify proofs for responses)")
|
||||
viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// register REST routes
|
||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||
func RegisterTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
|
||||
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET")
|
||||
r.HandleFunc("/txs", QueryTxsByTagsRequestHandlerFn(cliCtx, cdc)).Methods("GET")
|
||||
r.HandleFunc("/txs", BroadcastTxRequest(cliCtx, cdc)).Methods("POST")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package utils
|
||||
|
||||
import "errors"
|
||||
|
||||
var errInvalidSigner = errors.New("tx intended signer does not match the given signer")
|
||||
+11
-12
@@ -9,14 +9,13 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
"github.com/tendermint/tendermint/libs/common"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
@@ -77,7 +76,7 @@ func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIConte
|
||||
}
|
||||
|
||||
var json []byte
|
||||
if viper.GetBool(client.FlagIndentResponse) {
|
||||
if viper.GetBool(flags.FlagIndentResponse) {
|
||||
json, err = cliCtx.Codec.MarshalJSONIndent(stdSignMsg, "", " ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -88,8 +87,8 @@ func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIConte
|
||||
|
||||
fmt.Fprintf(os.Stderr, "%s\n\n", json)
|
||||
|
||||
buf := client.BufferStdin()
|
||||
ok, err := client.GetConfirmation("confirm transaction before signing and broadcasting", buf)
|
||||
buf := input.BufferStdin()
|
||||
ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf)
|
||||
if err != nil || !ok {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", "cancelled transaction")
|
||||
return err
|
||||
@@ -129,7 +128,7 @@ func EnrichWithGas(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []s
|
||||
// CalculateGas simulates the execution of a transaction and returns
|
||||
// both the estimate obtained by the query and the adjusted amount.
|
||||
func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error),
|
||||
cdc *amino.Codec, txBytes []byte, adjustment float64) (estimate, adjusted uint64, err error) {
|
||||
cdc *codec.Codec, txBytes []byte, adjustment float64) (estimate, adjusted uint64, err error) {
|
||||
|
||||
// run a simulation (via /app/simulate query) to
|
||||
// estimate gas and update TxBuilder accordingly
|
||||
@@ -180,7 +179,7 @@ func SignStdTx(
|
||||
|
||||
// check whether the address is a signer
|
||||
if !isTxSigner(sdk.AccAddress(addr), stdTx.GetSigners()) {
|
||||
return signedStdTx, fmt.Errorf("%s: %s", client.ErrInvalidSigner, name)
|
||||
return signedStdTx, fmt.Errorf("%s: %s", errInvalidSigner, name)
|
||||
}
|
||||
|
||||
if !offline {
|
||||
@@ -207,7 +206,7 @@ func SignStdTxWithSignerAddress(txBldr authtxb.TxBuilder, cliCtx context.CLICont
|
||||
|
||||
// check whether the address is a signer
|
||||
if !isTxSigner(addr, stdTx.GetSigners()) {
|
||||
return signedStdTx, fmt.Errorf("%s: %s", client.ErrInvalidSigner, name)
|
||||
return signedStdTx, fmt.Errorf("%s: %s", errInvalidSigner, name)
|
||||
}
|
||||
|
||||
if !offline {
|
||||
@@ -226,7 +225,7 @@ func SignStdTxWithSignerAddress(txBldr authtxb.TxBuilder, cliCtx context.CLICont
|
||||
}
|
||||
|
||||
// Read and decode a StdTx from the given filename. Can pass "-" to read from stdin.
|
||||
func ReadStdTxFromFile(cdc *amino.Codec, filename string) (stdTx auth.StdTx, err error) {
|
||||
func ReadStdTxFromFile(cdc *codec.Codec, filename string) (stdTx auth.StdTx, err error) {
|
||||
var bytes []byte
|
||||
if filename == "-" {
|
||||
bytes, err = ioutil.ReadAll(os.Stdin)
|
||||
@@ -284,7 +283,7 @@ func adjustGasEstimate(estimate uint64, adjustment float64) uint64 {
|
||||
return uint64(adjustment * float64(estimate))
|
||||
}
|
||||
|
||||
func parseQueryResponse(cdc *amino.Codec, rawRes []byte) (uint64, error) {
|
||||
func parseQueryResponse(cdc *codec.Codec, rawRes []byte) (uint64, error) {
|
||||
var simulationResult sdk.Result
|
||||
if err := cdc.UnmarshalBinaryLengthPrefixed(rawRes, &simulationResult); err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -15,13 +15,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -77,7 +70,7 @@ func TestCalculateGas(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDefaultTxEncoder(t *testing.T) {
|
||||
cdc := makeTestCodec()
|
||||
cdc := makeCodec()
|
||||
|
||||
defaultEncoder := auth.DefaultTxEncoder(cdc)
|
||||
encoder := GetTxEncoder(cdc)
|
||||
@@ -86,7 +79,7 @@ func TestDefaultTxEncoder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfiguredTxEncoder(t *testing.T) {
|
||||
cdc := makeTestCodec()
|
||||
cdc := makeCodec()
|
||||
|
||||
customEncoder := func(tx sdk.Tx) ([]byte, error) {
|
||||
return json.Marshal(tx)
|
||||
@@ -144,21 +137,9 @@ func writeToNewTempFile(t *testing.T, data string) *os.File {
|
||||
|
||||
func makeCodec() *codec.Codec {
|
||||
var cdc = codec.New()
|
||||
bank.RegisterCodec(cdc)
|
||||
staking.RegisterCodec(cdc)
|
||||
distribution.RegisterCodec(cdc)
|
||||
slashing.RegisterCodec(cdc)
|
||||
params.RegisterCodec(cdc)
|
||||
gov.RegisterCodec(cdc)
|
||||
auth.RegisterCodec(cdc)
|
||||
crisis.RegisterCodec(cdc)
|
||||
sdk.RegisterCodec(cdc)
|
||||
codec.RegisterCrypto(cdc)
|
||||
return cdc
|
||||
}
|
||||
|
||||
func makeTestCodec() *codec.Codec {
|
||||
cdc := makeCodec()
|
||||
auth.RegisterCodec(cdc)
|
||||
cdc.RegisterConcrete(sdk.TestMsg{}, "cosmos-sdk/Test", nil)
|
||||
return cdc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user