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.

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