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.

149 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. data "github.com/tendermint/go-wire/data"
  4. rpc "github.com/tendermint/tendermint/rpc/lib/server"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. "github.com/tendermint/tendermint/rpc/lib/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. "tx": rpc.NewRPCFunc(TxResult, "hash,prove"),
  22. "validators": rpc.NewRPCFunc(ValidatorsResult, ""),
  23. "dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
  24. "unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
  25. "num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),
  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. // config is not in general thread safe. expose specifics if you need em
  37. // "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
  38. // profiler API
  39. "unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
  40. "unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
  41. "unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
  42. }
  43. func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  44. return Subscribe(wsCtx, event)
  45. }
  46. func UnsubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
  47. return Unsubscribe(wsCtx, event)
  48. }
  49. func StatusResult() (ctypes.TMResult, error) {
  50. return Status()
  51. }
  52. func NetInfoResult() (ctypes.TMResult, error) {
  53. return NetInfo()
  54. }
  55. func UnsafeDialSeedsResult(seeds []string) (ctypes.TMResult, error) {
  56. return UnsafeDialSeeds(seeds)
  57. }
  58. func BlockchainInfoResult(min, max int) (ctypes.TMResult, error) {
  59. return BlockchainInfo(min, max)
  60. }
  61. func GenesisResult() (ctypes.TMResult, error) {
  62. return Genesis()
  63. }
  64. func BlockResult(height int) (ctypes.TMResult, error) {
  65. return Block(height)
  66. }
  67. func CommitResult(height int) (ctypes.TMResult, error) {
  68. return Commit(height)
  69. }
  70. func ValidatorsResult() (ctypes.TMResult, error) {
  71. return Validators()
  72. }
  73. func DumpConsensusStateResult() (ctypes.TMResult, error) {
  74. return DumpConsensusState()
  75. }
  76. func UnconfirmedTxsResult() (ctypes.TMResult, error) {
  77. return UnconfirmedTxs()
  78. }
  79. func NumUnconfirmedTxsResult() (ctypes.TMResult, error) {
  80. return NumUnconfirmedTxs()
  81. }
  82. // Tx allow user to query the transaction results. `nil` could mean the
  83. // transaction is in the mempool, invalidated, or was not send in the first
  84. // place.
  85. func TxResult(hash []byte, prove bool) (ctypes.TMResult, error) {
  86. return Tx(hash, prove)
  87. }
  88. func BroadcastTxCommitResult(tx types.Tx) (ctypes.TMResult, error) {
  89. return BroadcastTxCommit(tx)
  90. }
  91. func BroadcastTxSyncResult(tx types.Tx) (ctypes.TMResult, error) {
  92. return BroadcastTxSync(tx)
  93. }
  94. func BroadcastTxAsyncResult(tx types.Tx) (ctypes.TMResult, error) {
  95. return BroadcastTxAsync(tx)
  96. }
  97. func ABCIQueryResult(path string, data data.Bytes, prove bool) (ctypes.TMResult, error) {
  98. return ABCIQuery(path, data, prove)
  99. }
  100. func ABCIInfoResult() (ctypes.TMResult, error) {
  101. return ABCIInfo()
  102. }
  103. func UnsafeFlushMempoolResult() (ctypes.TMResult, error) {
  104. return UnsafeFlushMempool()
  105. }
  106. func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
  107. return UnsafeSetConfig(typ, key, value)
  108. }
  109. func UnsafeStartCPUProfilerResult(filename string) (ctypes.TMResult, error) {
  110. return UnsafeStartCPUProfiler(filename)
  111. }
  112. func UnsafeStopCPUProfilerResult() (ctypes.TMResult, error) {
  113. return UnsafeStopCPUProfiler()
  114. }
  115. func UnsafeWriteHeapProfileResult(filename string) (ctypes.TMResult, error) {
  116. return UnsafeWriteHeapProfile(filename)
  117. }