Move sendtx and query account commands into x/bank
This commit is contained in:
parent
00304dd094
commit
356baf61c1
|
@ -0,0 +1,33 @@
|
|||
package client
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
const (
|
||||
FlagChainID = "chain-id"
|
||||
FlagNode = "node"
|
||||
FlagHeight = "height"
|
||||
FlagTrustNode = "trust-node"
|
||||
FlagName = "name"
|
||||
)
|
||||
|
||||
// GetCommands adds common flags to query commands
|
||||
func GetCommands(cmds ...*cobra.Command) []*cobra.Command {
|
||||
for _, c := range cmds {
|
||||
// TODO: make this default false when we support proofs
|
||||
c.Flags().Bool(FlagTrustNode, true, "Don't verify proofs for responses")
|
||||
c.Flags().String(FlagChainID, "", "Chain ID of tendermint node")
|
||||
c.Flags().String(FlagNode, "", "<host>:<port> to tendermint rpc interface for this chain")
|
||||
c.Flags().Int64(FlagHeight, 0, "block height to query, omit to get most recent provable block")
|
||||
}
|
||||
return cmds
|
||||
}
|
||||
|
||||
// PostCommands adds common flags for commands to post tx
|
||||
func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
|
||||
for _, c := range cmds {
|
||||
c.Flags().String(FlagName, "", "Name of private key with which to sign")
|
||||
c.Flags().String(FlagChainID, "", "Chain ID of tendermint node")
|
||||
c.Flags().String(FlagNode, "", "<host>:<port> to tendermint rpc interface for this chain")
|
||||
}
|
||||
return cmds
|
||||
}
|
|
@ -1,28 +1,23 @@
|
|||
package main
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
)
|
||||
|
||||
const (
|
||||
// these are needed for every init
|
||||
flagChainID = "chain-id"
|
||||
flagNode = "node"
|
||||
|
||||
// one of the following should be provided to verify the connection
|
||||
flagGenesis = "genesis"
|
||||
flagCommit = "commit"
|
||||
flagValHash = "validator-set"
|
||||
|
||||
flagHeight = "height"
|
||||
flagSelect = "select"
|
||||
flagTags = "tag"
|
||||
flagAny = "any"
|
||||
|
||||
flagBind = "bind"
|
||||
flagCORS = "cors"
|
||||
flagTrustNode = "trust-node"
|
||||
|
||||
// this is for signing
|
||||
flagName = "name"
|
||||
flagBind = "bind"
|
||||
flagCORS = "cors"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -49,36 +44,14 @@ func AddClientCommands(cmd *cobra.Command) {
|
|||
)
|
||||
}
|
||||
|
||||
// GetCommands adds common flags to query commands
|
||||
func GetCommands(cmds ...*cobra.Command) []*cobra.Command {
|
||||
for _, c := range cmds {
|
||||
// TODO: make this default false when we support proofs
|
||||
c.Flags().Bool(flagTrustNode, true, "Don't verify proofs for responses")
|
||||
c.Flags().String(flagChainID, "", "Chain ID of tendermint node")
|
||||
c.Flags().String(flagNode, "", "<host>:<port> to tendermint rpc interface for this chain")
|
||||
c.Flags().Int64(flagHeight, 0, "block height to query, omit to get most recent provable block")
|
||||
}
|
||||
return cmds
|
||||
}
|
||||
|
||||
// PostCommands adds common flags for commands to post tx
|
||||
func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
|
||||
for _, c := range cmds {
|
||||
c.Flags().String(flagName, "", "Name of private key with which to sign")
|
||||
c.Flags().String(flagChainID, "", "Chain ID of tendermint node")
|
||||
c.Flags().String(flagNode, "", "<host>:<port> to tendermint rpc interface for this chain")
|
||||
}
|
||||
return cmds
|
||||
}
|
||||
|
||||
func initClientCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize light client",
|
||||
RunE: todoNotImplemented,
|
||||
}
|
||||
cmd.Flags().StringP(flagChainID, "c", "", "ID of chain we connect to")
|
||||
cmd.Flags().StringP(flagNode, "n", "tcp://localhost:46657", "Node to connect to")
|
||||
cmd.Flags().StringP(client.FlagChainID, "c", "", "ID of chain we connect to")
|
||||
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:46657", "Node to connect to")
|
||||
cmd.Flags().String(flagGenesis, "", "Genesis file to verify header validity")
|
||||
cmd.Flags().String(flagCommit, "", "File with trusted and signed header")
|
||||
cmd.Flags().String(flagValHash, "", "Hash of trusted validator set (hex-encoded)")
|
||||
|
|
|
@ -8,8 +8,10 @@ import (
|
|||
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/commands"
|
||||
)
|
||||
|
||||
// gaiacliCmd is the entry point for this binary
|
||||
|
@ -35,9 +37,9 @@ func main() {
|
|||
|
||||
// query/post commands (custom to binary)
|
||||
basecliCmd.AddCommand(
|
||||
GetCommands(getAccountCmd())...)
|
||||
client.GetCommands(bankcmd.GetAccountCmd())...)
|
||||
basecliCmd.AddCommand(
|
||||
PostCommands(postSendCommand())...)
|
||||
client.PostCommands(bankcmd.SendTxCommand())...)
|
||||
|
||||
// add proxy, version and key info
|
||||
basecliCmd.AddCommand(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -17,7 +17,9 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/examples/basecoin/types"
|
||||
)
|
||||
|
||||
func getAccountCmd() *cobra.Command {
|
||||
// GetAccountCmd returns a query account that will display the
|
||||
// state of the account at a given address
|
||||
func GetAccountCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "account <address>",
|
||||
Short: "Query account balance",
|
||||
|
@ -42,16 +44,15 @@ func getAccount(cmd *cobra.Command, args []string) error {
|
|||
// TODO: make the store name a variable in getAccountCmd?
|
||||
path := "/main/key"
|
||||
|
||||
uri := viper.GetString(flagNode)
|
||||
uri := viper.GetString(client.FlagNode)
|
||||
if uri == "" {
|
||||
return errors.New("Must define which node to query with --node")
|
||||
}
|
||||
node := client.GetNode(uri)
|
||||
|
||||
opts := rpcclient.ABCIQueryOptions{
|
||||
Height: viper.GetInt64(flagHeight),
|
||||
// Trusted: viper.GetBool(flagTrustNode),
|
||||
Trusted: true,
|
||||
Height: viper.GetInt64(client.FlagHeight),
|
||||
Trusted: viper.GetBool(client.FlagTrustNode),
|
||||
}
|
||||
result, err := node.ABCIQueryWithOptions(path, key, opts)
|
||||
if err != nil {
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -23,7 +23,8 @@ const (
|
|||
flagSequence = "seq"
|
||||
)
|
||||
|
||||
func postSendCommand() *cobra.Command {
|
||||
// SendTxCommand will create a send tx and sign it with the given key
|
||||
func SendTxCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send",
|
||||
Short: "Create and sign a send tx",
|
||||
|
@ -42,7 +43,7 @@ func sendTx(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
uri := viper.GetString(flagNode)
|
||||
uri := viper.GetString(client.FlagNode)
|
||||
if uri == "" {
|
||||
return errors.New("Must define which node to query with --node")
|
||||
}
|
||||
|
@ -75,7 +76,7 @@ func buildTx() ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
name := viper.GetString(flagName)
|
||||
name := viper.GetString(client.FlagName)
|
||||
info, err := keybase.Get(name)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "No key for name")
|
Loading…
Reference in New Issue