You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.6 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package handlers
  2. import (
  3. rpc "github.com/tendermint/go-rpc/server"
  4. "github.com/tendermint/netmon/types"
  5. )
  6. func Routes(network *TendermintNetwork) map[string]*rpc.RPCFunc {
  7. return map[string]*rpc.RPCFunc{
  8. // subscribe/unsubscribe are reserved for websocket events.
  9. // "subscribe": rpc.NewWSRPCFunc(Subscribe, []string{"event"}),
  10. // "unsubscribe": rpc.NewWSRPCFunc(Unsubscribe, []string{"event"}),
  11. "status": rpc.NewRPCFunc(StatusResult(network), ""),
  12. "get_chain": rpc.NewRPCFunc(GetChainResult(network), "chainID"),
  13. "register_chain": rpc.NewRPCFunc(RegisterChainResult(network), "chainConfig"),
  14. "validator_set": rpc.NewRPCFunc(GetValidatorSetResult(network), "valsetID"),
  15. "register_validator_set": rpc.NewRPCFunc(RegisterValidatorSetResult(network), "valSetID"),
  16. "validator": rpc.NewRPCFunc(GetValidatorResult(network), "valSetID,valID"),
  17. "update_validator": rpc.NewRPCFunc(UpdateValidatorResult(network), "chainID,valID,rpcAddr"),
  18. "start_meter": rpc.NewRPCFunc(network.StartMeter, "chainID,valID,event"),
  19. "stop_meter": rpc.NewRPCFunc(network.StopMeter, "chainID,valID,event"),
  20. "meter": rpc.NewRPCFunc(GetMeterResult(network), "chainID,valID,event"),
  21. }
  22. }
  23. func StatusResult(network *TendermintNetwork) interface{} {
  24. return func() (NetMonResult, error) {
  25. return network.Status()
  26. }
  27. }
  28. func GetChainResult(network *TendermintNetwork) interface{} {
  29. return func(chain string) (NetMonResult, error) {
  30. return network.GetChain(chain)
  31. }
  32. }
  33. func RegisterChainResult(network *TendermintNetwork) interface{} {
  34. return func(chainConfig *types.BlockchainConfig) (NetMonResult, error) {
  35. return network.RegisterChain(chainConfig)
  36. }
  37. }
  38. func GetValidatorSetResult(network *TendermintNetwork) interface{} {
  39. return func(valSetID string) (NetMonResult, error) {
  40. return network.GetValidatorSet(valSetID)
  41. }
  42. }
  43. func RegisterValidatorSetResult(network *TendermintNetwork) interface{} {
  44. return func(valSet *types.ValidatorSet) (NetMonResult, error) {
  45. return network.RegisterValidatorSet(valSet)
  46. }
  47. }
  48. func GetValidatorResult(network *TendermintNetwork) interface{} {
  49. return func(valSetID, valID string) (NetMonResult, error) {
  50. return network.GetValidator(valSetID, valID)
  51. }
  52. }
  53. func UpdateValidatorResult(network *TendermintNetwork) interface{} {
  54. return func(chainID, valID, rpcAddr string) (NetMonResult, error) {
  55. return network.UpdateValidator(chainID, valID, rpcAddr)
  56. }
  57. }
  58. func GetMeterResult(network *TendermintNetwork) interface{} {
  59. return func(chainID, valID, eventID string) (NetMonResult, error) {
  60. return network.GetMeter(chainID, valID, eventID)
  61. }
  62. }