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.

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