cosmos-sdk/client/rpc/root.go

57 lines
1.8 KiB
Go
Raw Normal View History

package rpc
2018-02-22 06:33:34 -08:00
import (
2018-03-09 01:15:56 -08:00
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/cobra"
2018-02-22 06:33:34 -08:00
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
)
2018-02-22 06:33:34 -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"
)
// XXX: remove this when not needed
func todoNotImplemented(_ *cobra.Command, _ []string) error {
return errors.New("TODO: Command not yet implemented")
}
2018-02-22 06:33:34 -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(),
statusCommand(),
2018-02-22 06:33:34 -08:00
blockCommand(),
validatorCommand(),
)
}
func initClientCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize light client",
RunE: todoNotImplemented,
}
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
}
2018-03-09 01:15:56 -08:00
2018-04-18 21:49:24 -07:00
// Register REST endpoints
func RegisterRoutes(ctx context.CoreContext, r *mux.Router) {
2018-04-25 13:32:22 -07:00
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(ctx)).Methods("GET")
r.HandleFunc("/syncing", NodeSyncingRequestHandlerFn(ctx)).Methods("GET")
r.HandleFunc("/blocks/latest", LatestBlockRequestHandlerFn(ctx)).Methods("GET")
r.HandleFunc("/blocks/{height}", BlockRequestHandlerFn(ctx)).Methods("GET")
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandlerFn(ctx)).Methods("GET")
r.HandleFunc("/validatorsets/{height}", ValidatorSetRequestHandlerFn(ctx)).Methods("GET")
2018-03-09 01:15:56 -08:00
}