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.

153 lines
4.6 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package core
  2. import (
  3. "strings"
  4. rpc "github.com/tendermint/go-rpc/server"
  5. "github.com/tendermint/go-rpc/types"
  6. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. // TODO: better system than "unsafe" prefix
  10. var Routes = map[string]*rpc.RPCFunc{
  11. // subscribe/unsubscribe are reserved for websocket events.
  12. "subscribe": rpc.NewWSRPCFunc(SubscribeResult, "event"),
  13. "unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
  14. // info API
  15. "status": rpc.NewRPCFunc(StatusResult, ""),
  16. "net_info": rpc.NewRPCFunc(NetInfoResult, ""),
  17. "blockchain": rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
  18. "genesis": rpc.NewRPCFunc(GenesisResult, ""),
  19. "block": rpc.NewRPCFunc(BlockResult, "height"),
  20. "commit": rpc.NewRPCFunc(CommitResult, "height"),
  21. "validators": rpc.NewRPCFunc(ValidatorsResult, ""),
  22. "dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
  23. "unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
  24. "num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
  25. "tx": rpc.NewRPCFunc(Tx, "hash"),
  26. // broadcast API
  27. "broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommitResult, "tx"),
  28. "broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
  29. "broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
  30. // abci API
  31. "abci_query": rpc.NewRPCFunc(ABCIQueryResult, "path,data,prove"),
  32. "abci_info": rpc.NewRPCFunc(ABCIInfoResult, ""),
  33. // control API
  34. "dial_seeds": rpc.NewRPCFunc(UnsafeDialSeedsResult, "seeds"),
  35. "unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""),
  36. "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
  37. // profiler API
  38. "unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
  39. "unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
  40. "unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
  41. }
  42. func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  43. return Subscribe(wsCtx, event)
  44. }
  45. func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  46. return Unsubscribe(wsCtx, event)
  47. }
  48. func StatusResult() (ctypes.TMResult, error) {
  49. return Status()
  50. }
  51. func NetInfoResult() (ctypes.TMResult, error) {
  52. return NetInfo()
  53. }
  54. func UnsafeDialSeedsResult(seeds []string) (ctypes.TMResult, error) {
  55. return UnsafeDialSeeds(seeds)
  56. }
  57. func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
  58. return BlockchainInfo(min, max)
  59. }
  60. func GenesisResult() (ctypes.TMResult, error) {
  61. return Genesis()
  62. }
  63. func BlockResult(height int) (ctypes.TMResult, error) {
  64. return Block(height)
  65. }
  66. func CommitResult(height int) (ctypes.TMResult, error) {
  67. return Commit(height)
  68. }
  69. func ValidatorsResult() (ctypes.TMResult, error) {
  70. return Validators()
  71. }
  72. func DumpConsensusStateResult() (ctypes.TMResult, error) {
  73. return DumpConsensusState()
  74. }
  75. func UnconfirmedTxsResult() (ctypes.TMResult, error) {
  76. return UnconfirmedTxs()
  77. }
  78. func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
  79. return NumUnconfirmedTxs()
  80. }
  81. // Tx allow user to query the transaction results. `nil` could mean the
  82. // transaction is in the mempool, invalidated, or was not send in the first
  83. // place.
  84. func Tx(hash string) (ctypes.TMResult, error) {
  85. r, err := txIndexer.Tx(strings.ToLower(hash))
  86. // nil-pointer interface values are forbidden in go-rpc
  87. if r == (*types.TxResult)(nil) {
  88. return nil, err
  89. }
  90. return r, err
  91. }
  92. func BroadcastTxCommitResult(tx []byte) (ctypes.TMResult, error) {
  93. return BroadcastTxCommit(tx)
  94. }
  95. func BroadcastTxSyncResult(tx []byte) (ctypes.TMResult, error) {
  96. return BroadcastTxSync(tx)
  97. }
  98. func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
  99. return BroadcastTxAsync(tx)
  100. }
  101. func ABCIQueryResult(path string, data []byte, prove bool) (ctypes.TMResult, error) {
  102. return ABCIQuery(path, data, prove)
  103. }
  104. func ABCIInfoResult() (ctypes.TMResult, error) {
  105. return ABCIInfo()
  106. }
  107. func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
  108. return UnsafeFlushMempool()
  109. }
  110. func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
  111. return UnsafeSetConfig(typ, key, value)
  112. }
  113. func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
  114. return UnsafeStartCPUProfiler(filename)
  115. }
  116. func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
  117. return UnsafeStopCPUProfiler()
  118. }
  119. func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
  120. return UnsafeWriteHeapProfile(filename)
  121. }