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.

220 lines
5.3 KiB

8 years ago
8 years ago
8 years ago
  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. // TODO: better system than "unsafe" prefix
  8. var Routes = map[string]*rpc.RPCFunc{
  9. // subscribe/unsubscribe are reserved for websocket events.
  10. "subscribe": rpc.NewWSRPCFunc(SubscribeResult, "event"),
  11. "unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
  12. // info API
  13. "status": rpc.NewRPCFunc(StatusResult, ""),
  14. "net_info": rpc.NewRPCFunc(NetInfoResult, ""),
  15. "blockchain": rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
  16. "genesis": rpc.NewRPCFunc(GenesisResult, ""),
  17. "block": rpc.NewRPCFunc(BlockResult, "height"),
  18. "validators": rpc.NewRPCFunc(ValidatorsResult, ""),
  19. "dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
  20. "unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
  21. "num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
  22. // broadcast API
  23. "broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommitResult, "tx"),
  24. "broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
  25. "broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
  26. // abci API
  27. "abci_query": rpc.NewRPCFunc(ABCIQueryResult, "query"),
  28. "abci_info": rpc.NewRPCFunc(ABCIInfoResult, ""),
  29. // control API
  30. "dial_seeds": rpc.NewRPCFunc(UnsafeDialSeedsResult, "seeds"),
  31. "unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""),
  32. "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
  33. // profiler API
  34. "unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
  35. "unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
  36. "unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
  37. }
  38. func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  39. if r, err := Subscribe(wsCtx, event); err != nil {
  40. return nil, err
  41. } else {
  42. return r, nil
  43. }
  44. }
  45. func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  46. if r, err := Unsubscribe(wsCtx, event); err != nil {
  47. return nil, err
  48. } else {
  49. return r, nil
  50. }
  51. }
  52. func StatusResult() (ctypes.TMResult, error) {
  53. if r, err := Status(); err != nil {
  54. return nil, err
  55. } else {
  56. return r, nil
  57. }
  58. }
  59. func NetInfoResult() (ctypes.TMResult, error) {
  60. if r, err := NetInfo(); err != nil {
  61. return nil, err
  62. } else {
  63. return r, nil
  64. }
  65. }
  66. func UnsafeDialSeedsResult(seeds []string) (ctypes.TMResult, error) {
  67. if r, err := UnsafeDialSeeds(seeds); err != nil {
  68. return nil, err
  69. } else {
  70. return r, nil
  71. }
  72. }
  73. func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
  74. if r, err := BlockchainInfo(min, max); err != nil {
  75. return nil, err
  76. } else {
  77. return r, nil
  78. }
  79. }
  80. func GenesisResult() (ctypes.TMResult, error) {
  81. if r, err := Genesis(); err != nil {
  82. return nil, err
  83. } else {
  84. return r, nil
  85. }
  86. }
  87. func BlockResult(height int) (ctypes.TMResult, error) {
  88. if r, err := Block(height); err != nil {
  89. return nil, err
  90. } else {
  91. return r, nil
  92. }
  93. }
  94. func ValidatorsResult() (ctypes.TMResult, error) {
  95. if r, err := Validators(); err != nil {
  96. return nil, err
  97. } else {
  98. return r, nil
  99. }
  100. }
  101. func DumpConsensusStateResult() (ctypes.TMResult, error) {
  102. if r, err := DumpConsensusState(); err != nil {
  103. return nil, err
  104. } else {
  105. return r, nil
  106. }
  107. }
  108. func UnconfirmedTxsResult() (ctypes.TMResult, error) {
  109. if r, err := UnconfirmedTxs(); err != nil {
  110. return nil, err
  111. } else {
  112. return r, nil
  113. }
  114. }
  115. func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
  116. if r, err := NumUnconfirmedTxs(); err != nil {
  117. return nil, err
  118. } else {
  119. return r, nil
  120. }
  121. }
  122. func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
  123. if r, err := BroadcastTxCommit(tx); err != nil {
  124. return nil, err
  125. } else {
  126. return r, nil
  127. }
  128. }
  129. func BroadcastTxSyncResult(tx []byte) (ctypes.TMResult, error) {
  130. if r, err := BroadcastTxSync(tx); err != nil {
  131. return nil, err
  132. } else {
  133. return r, nil
  134. }
  135. }
  136. func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
  137. if r, err := BroadcastTxAsync(tx); err != nil {
  138. return nil, err
  139. } else {
  140. return r, nil
  141. }
  142. }
  143. func ABCIQueryResult(query []byte) (ctypes.TMResult, error) {
  144. if r, err := ABCIQuery(query); err != nil {
  145. return nil, err
  146. } else {
  147. return r, nil
  148. }
  149. }
  150. func ABCIInfoResult() (ctypes.TMResult, error) {
  151. if r, err := ABCIInfo(); err != nil {
  152. return nil, err
  153. } else {
  154. return r, nil
  155. }
  156. }
  157. func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
  158. if r, err := UnsafeFlushMempool(); err != nil {
  159. return nil, err
  160. } else {
  161. return r, nil
  162. }
  163. }
  164. func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
  165. if r, err := UnsafeSetConfig(typ, key, value); err != nil {
  166. return nil, err
  167. } else {
  168. return r, nil
  169. }
  170. }
  171. func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
  172. if r, err := UnsafeStartCPUProfiler(filename); err != nil {
  173. return nil, err
  174. } else {
  175. return r, nil
  176. }
  177. }
  178. func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
  179. if r, err := UnsafeStopCPUProfiler(); err != nil {
  180. return nil, err
  181. } else {
  182. return r, nil
  183. }
  184. }
  185. func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
  186. if r, err := UnsafeWriteHeapProfile(filename); err != nil {
  187. return nil, err
  188. } else {
  189. return r, nil
  190. }
  191. }