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.

212 lines
5.2 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_commit": rpc.NewRPCFunc(BroadcastTxCommitResult, "tx"),
  20. "broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
  21. "broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
  22. "unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
  23. "num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
  24. "tmsp_query": rpc.NewRPCFunc(TMSPQueryResult, "query"),
  25. "tmsp_info": rpc.NewRPCFunc(TMSPInfoResult, ""),
  26. "unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""),
  27. "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
  28. "unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
  29. "unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
  30. "unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
  31. }
  32. func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  33. if r, err := Subscribe(wsCtx, event); err != nil {
  34. return nil, err
  35. } else {
  36. return r, nil
  37. }
  38. }
  39. func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  40. if r, err := Unsubscribe(wsCtx, event); err != nil {
  41. return nil, err
  42. } else {
  43. return r, nil
  44. }
  45. }
  46. func StatusResult() (ctypes.TMResult, error) {
  47. if r, err := Status(); err != nil {
  48. return nil, err
  49. } else {
  50. return r, nil
  51. }
  52. }
  53. func NetInfoResult() (ctypes.TMResult, error) {
  54. if r, err := NetInfo(); err != nil {
  55. return nil, err
  56. } else {
  57. return r, nil
  58. }
  59. }
  60. func DialSeedsResult(seeds []string) (ctypes.TMResult, error) {
  61. if r, err := DialSeeds(seeds); err != nil {
  62. return nil, err
  63. } else {
  64. return r, nil
  65. }
  66. }
  67. func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
  68. if r, err := BlockchainInfo(min, max); err != nil {
  69. return nil, err
  70. } else {
  71. return r, nil
  72. }
  73. }
  74. func GenesisResult() (ctypes.TMResult, error) {
  75. if r, err := Genesis(); err != nil {
  76. return nil, err
  77. } else {
  78. return r, nil
  79. }
  80. }
  81. func BlockResult(height int) (ctypes.TMResult, error) {
  82. if r, err := Block(height); err != nil {
  83. return nil, err
  84. } else {
  85. return r, nil
  86. }
  87. }
  88. func ValidatorsResult() (ctypes.TMResult, error) {
  89. if r, err := Validators(); err != nil {
  90. return nil, err
  91. } else {
  92. return r, nil
  93. }
  94. }
  95. func DumpConsensusStateResult() (ctypes.TMResult, error) {
  96. if r, err := DumpConsensusState(); err != nil {
  97. return nil, err
  98. } else {
  99. return r, nil
  100. }
  101. }
  102. func UnconfirmedTxsResult() (ctypes.TMResult, error) {
  103. if r, err := UnconfirmedTxs(); err != nil {
  104. return nil, err
  105. } else {
  106. return r, nil
  107. }
  108. }
  109. func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
  110. if r, err := NumUnconfirmedTxs(); err != nil {
  111. return nil, err
  112. } else {
  113. return r, nil
  114. }
  115. }
  116. func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
  117. if r, err := BroadcastTxCommit(tx); err != nil {
  118. return nil, err
  119. } else {
  120. return r, nil
  121. }
  122. }
  123. func BroadcastTxSyncResult(tx []byte) (ctypes.TMResult, error) {
  124. if r, err := BroadcastTxSync(tx); err != nil {
  125. return nil, err
  126. } else {
  127. return r, nil
  128. }
  129. }
  130. func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
  131. if r, err := BroadcastTxAsync(tx); err != nil {
  132. return nil, err
  133. } else {
  134. return r, nil
  135. }
  136. }
  137. func TMSPQueryResult(query []byte) (ctypes.TMResult, error) {
  138. if r, err := TMSPQuery(query); err != nil {
  139. return nil, err
  140. } else {
  141. return r, nil
  142. }
  143. }
  144. func TMSPInfoResult() (ctypes.TMResult, error) {
  145. if r, err := TMSPInfo(); err != nil {
  146. return nil, err
  147. } else {
  148. return r, nil
  149. }
  150. }
  151. func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
  152. if r, err := UnsafeFlushMempool(); err != nil {
  153. return nil, err
  154. } else {
  155. return r, nil
  156. }
  157. }
  158. func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
  159. if r, err := UnsafeSetConfig(typ, key, value); err != nil {
  160. return nil, err
  161. } else {
  162. return r, nil
  163. }
  164. }
  165. func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
  166. if r, err := UnsafeStartCPUProfiler(filename); err != nil {
  167. return nil, err
  168. } else {
  169. return r, nil
  170. }
  171. }
  172. func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
  173. if r, err := UnsafeStopCPUProfiler(); err != nil {
  174. return nil, err
  175. } else {
  176. return r, nil
  177. }
  178. }
  179. func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
  180. if r, err := UnsafeWriteHeapProfile(filename); err != nil {
  181. return nil, err
  182. } else {
  183. return r, nil
  184. }
  185. }