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.

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