2018-02-23 02:25:25 -08:00
|
|
|
package rpc
|
2018-02-22 06:33:34 -08:00
|
|
|
|
2018-02-23 01:49:30 -08:00
|
|
|
import (
|
2018-02-23 02:25:25 -08:00
|
|
|
"github.com/pkg/errors"
|
2018-02-23 01:49:30 -08:00
|
|
|
"github.com/spf13/cobra"
|
2018-02-22 06:33:34 -08:00
|
|
|
|
2018-02-23 01:49:30 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
)
|
2018-02-22 06:33:34 -08:00
|
|
|
|
2018-02-23 02:25:25 -08:00
|
|
|
// XXX: remove this when not needed
|
|
|
|
func todoNotImplemented(_ *cobra.Command, _ []string) error {
|
|
|
|
return errors.New("TODO: Command not yet implemented")
|
|
|
|
}
|
|
|
|
|
2018-02-23 01:49:30 -08:00
|
|
|
const (
|
2018-02-22 06:33:34 -08:00
|
|
|
// one of the following should be provided to verify the connection
|
|
|
|
flagGenesis = "genesis"
|
|
|
|
flagCommit = "commit"
|
|
|
|
flagValHash = "validator-set"
|
|
|
|
|
|
|
|
flagSelect = "select"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
statusCmd = &cobra.Command{
|
|
|
|
Use: "status",
|
|
|
|
Short: "Query remote node for status",
|
|
|
|
RunE: todoNotImplemented,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-02-23 02:25:25 -08:00
|
|
|
// AddCommands adds a number of rpc-related subcommands
|
|
|
|
func AddCommands(cmd *cobra.Command) {
|
2018-02-22 06:33:34 -08:00
|
|
|
cmd.AddCommand(
|
|
|
|
initClientCommand(),
|
|
|
|
statusCmd,
|
|
|
|
blockCommand(),
|
|
|
|
validatorCommand(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func initClientCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "init",
|
|
|
|
Short: "Initialize light client",
|
|
|
|
RunE: todoNotImplemented,
|
|
|
|
}
|
2018-02-23 01:49:30 -08:00
|
|
|
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")
|
2018-02-22 06:33:34 -08:00
|
|
|
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)")
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func blockCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "block <height>",
|
|
|
|
Short: "Get verified data for a the block at given height",
|
|
|
|
RunE: todoNotImplemented,
|
|
|
|
}
|
|
|
|
cmd.Flags().StringSlice(flagSelect, []string{"header", "tx"}, "Fields to return (header|txs|results)")
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func validatorCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "validatorset <height>",
|
|
|
|
Short: "Get the full validator set at given height",
|
|
|
|
RunE: todoNotImplemented,
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|