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.

52 lines
1.7 KiB

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. )
  5. func Routes(network *TendermintNetwork) map[string]*rpc.RPCFunc {
  6. return map[string]*rpc.RPCFunc{
  7. // subscribe/unsubscribe are reserved for websocket events.
  8. // "subscribe": rpc.NewWSRPCFunc(Subscribe, []string{"event"}),
  9. // "unsubscribe": rpc.NewWSRPCFunc(Unsubscribe, []string{"event"}),
  10. "status": rpc.NewRPCFunc(StatusResult(network), ""),
  11. "blockchain": rpc.NewRPCFunc(GetChainResult(network), "chain"),
  12. "validator_set": rpc.NewRPCFunc(GetValidatorSetResult(network), "valsetID"),
  13. "validator": rpc.NewRPCFunc(GetValidatorResult(network), "valSetID,valID"),
  14. "start_meter": rpc.NewRPCFunc(network.StartMeter, "chainID,valID,event"),
  15. "stop_meter": rpc.NewRPCFunc(network.StopMeter, "chainID,valID,event"),
  16. "meter": rpc.NewRPCFunc(GetMeterResult(network), "chainID,valID,event"),
  17. }
  18. }
  19. func StatusResult(network *TendermintNetwork) interface{} {
  20. return func() (NetMonResult, error) {
  21. return network.Status()
  22. }
  23. }
  24. func GetChainResult(network *TendermintNetwork) interface{} {
  25. return func(chain string) (NetMonResult, error) {
  26. return network.GetChain(chain)
  27. }
  28. }
  29. func GetValidatorSetResult(network *TendermintNetwork) interface{} {
  30. return func(valSetID string) (NetMonResult, error) {
  31. return network.GetValidatorSet(valSetID)
  32. }
  33. }
  34. func GetValidatorResult(network *TendermintNetwork) interface{} {
  35. return func(valSetID, valID string) (NetMonResult, error) {
  36. return network.GetValidator(valSetID, valID)
  37. }
  38. }
  39. func GetMeterResult(network *TendermintNetwork) interface{} {
  40. return func(chainID, valID, eventID string) (NetMonResult, error) {
  41. return network.GetMeter(chainID, valID, eventID)
  42. }
  43. }