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.

229 lines
5.6 KiB

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