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.

166 lines
4.1 KiB

  1. package core
  2. import (
  3. rpc "github.com/tendermint/go-rpc/server"
  4. "github.com/tendermint/go-rpc/types"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. )
  7. var Routes = map[string]*rpc.RPCFunc{
  8. // subscribe/unsubscribe are reserved for websocket events.
  9. "subscribe": rpc.NewWSRPCFunc(SubscribeResult, "event"),
  10. "unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
  11. "status": rpc.NewRPCFunc(StatusResult, ""),
  12. "net_info": rpc.NewRPCFunc(NetInfoResult, ""),
  13. "dial_seeds": rpc.NewRPCFunc(DialSeedsResult, "seeds"),
  14. "blockchain": rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
  15. "genesis": rpc.NewRPCFunc(GenesisResult, ""),
  16. "block": rpc.NewRPCFunc(BlockResult, "height"),
  17. "validators": rpc.NewRPCFunc(ValidatorsResult, ""),
  18. "dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
  19. "broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
  20. "broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
  21. "unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
  22. "num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
  23. "unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
  24. "unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
  25. "unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
  26. }
  27. func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  28. if r, err := Subscribe(wsCtx, event); err != nil {
  29. return nil, err
  30. } else {
  31. return r, nil
  32. }
  33. }
  34. func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  35. if r, err := Unsubscribe(wsCtx, event); err != nil {
  36. return nil, err
  37. } else {
  38. return r, nil
  39. }
  40. }
  41. func StatusResult() (ctypes.TMResult, error) {
  42. if r, err := Status(); err != nil {
  43. return nil, err
  44. } else {
  45. return r, nil
  46. }
  47. }
  48. func NetInfoResult() (ctypes.TMResult, error) {
  49. if r, err := NetInfo(); err != nil {
  50. return nil, err
  51. } else {
  52. return r, nil
  53. }
  54. }
  55. func DialSeedsResult(seeds []string) (ctypes.TMResult, error) {
  56. if r, err := DialSeeds(seeds); err != nil {
  57. return nil, err
  58. } else {
  59. return r, nil
  60. }
  61. }
  62. func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
  63. if r, err := BlockchainInfo(min, max); err != nil {
  64. return nil, err
  65. } else {
  66. return r, nil
  67. }
  68. }
  69. func GenesisResult() (ctypes.TMResult, error) {
  70. if r, err := Genesis(); err != nil {
  71. return nil, err
  72. } else {
  73. return r, nil
  74. }
  75. }
  76. func BlockResult(height int) (ctypes.TMResult, error) {
  77. if r, err := Block(height); err != nil {
  78. return nil, err
  79. } else {
  80. return r, nil
  81. }
  82. }
  83. func ValidatorsResult() (ctypes.TMResult, error) {
  84. if r, err := Validators(); err != nil {
  85. return nil, err
  86. } else {
  87. return r, nil
  88. }
  89. }
  90. func DumpConsensusStateResult() (ctypes.TMResult, error) {
  91. if r, err := DumpConsensusState(); err != nil {
  92. return nil, err
  93. } else {
  94. return r, nil
  95. }
  96. }
  97. func UnconfirmedTxsResult() (ctypes.TMResult, error) {
  98. if r, err := UnconfirmedTxs(); err != nil {
  99. return nil, err
  100. } else {
  101. return r, nil
  102. }
  103. }
  104. func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
  105. if r, err := NumUnconfirmedTxs(); err != nil {
  106. return nil, err
  107. } else {
  108. return r, nil
  109. }
  110. }
  111. func BroadcastTxSyncResult(tx []byte) (ctypes.TMResult, error) {
  112. if r, err := BroadcastTxSync(tx); err != nil {
  113. return nil, err
  114. } else {
  115. return r, nil
  116. }
  117. }
  118. func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
  119. if r, err := BroadcastTxAsync(tx); err != nil {
  120. return nil, err
  121. } else {
  122. return r, nil
  123. }
  124. }
  125. func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
  126. if r, err := UnsafeStartCPUProfiler(filename); err != nil {
  127. return nil, err
  128. } else {
  129. return r, nil
  130. }
  131. }
  132. func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
  133. if r, err := UnsafeStopCPUProfiler(); err != nil {
  134. return nil, err
  135. } else {
  136. return r, nil
  137. }
  138. }
  139. func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
  140. if r, err := UnsafeWriteHeapProfile(filename); err != nil {
  141. return nil, err
  142. } else {
  143. return r, nil
  144. }
  145. }