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.

95 lines
3.3 KiB

  1. package client
  2. /*
  3. The client package provides a general purpose interface (Client) for connecting
  4. to a tendermint node, as well as higher-level functionality.
  5. The main implementation for production code is client.HTTP, which
  6. connects via http to the jsonrpc interface of the tendermint node.
  7. For connecting to a node running in the same process (eg. when
  8. compiling the abci app in the same process), you can use the client.Local
  9. implementation.
  10. For mocking out server responses during testing to see behavior for
  11. arbitrary return values, use the mock package.
  12. In addition to the Client interface, which should be used externally
  13. for maximum flexibility and testability, and two implementations,
  14. this package also provides helper functions that work on any Client
  15. implementation.
  16. */
  17. import (
  18. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  19. "github.com/tendermint/tendermint/types"
  20. cmn "github.com/tendermint/tmlibs/common"
  21. )
  22. // ABCIClient groups together the functionality that principally
  23. // affects the ABCI app. In many cases this will be all we want,
  24. // so we can accept an interface which is easier to mock
  25. type ABCIClient interface {
  26. // Reading from abci app
  27. ABCIInfo() (*ctypes.ResultABCIInfo, error)
  28. ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error)
  29. ABCIQueryWithOptions(path string, data cmn.HexBytes,
  30. opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
  31. // Writing to abci app
  32. BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
  33. BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
  34. BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
  35. }
  36. // SignClient groups together the interfaces need to get valid
  37. // signatures and prove anything about the chain
  38. type SignClient interface {
  39. Block(height *int64) (*ctypes.ResultBlock, error)
  40. BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
  41. Commit(height *int64) (*ctypes.ResultCommit, error)
  42. Validators(height *int64) (*ctypes.ResultValidators, error)
  43. Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
  44. TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error)
  45. }
  46. // HistoryClient shows us data from genesis to now in large chunks.
  47. type HistoryClient interface {
  48. Genesis() (*ctypes.ResultGenesis, error)
  49. BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
  50. }
  51. type StatusClient interface {
  52. // General chain info
  53. Status() (*ctypes.ResultStatus, error)
  54. }
  55. // Client wraps most important rpc calls a client would make
  56. // if you want to listen for events, test if it also
  57. // implements events.EventSwitch
  58. type Client interface {
  59. cmn.Service
  60. ABCIClient
  61. SignClient
  62. HistoryClient
  63. StatusClient
  64. EventsClient
  65. }
  66. // NetworkClient is general info about the network state. May not
  67. // be needed usually.
  68. //
  69. // Not included in the Client interface, but generally implemented
  70. // by concrete implementations.
  71. type NetworkClient interface {
  72. NetInfo() (*ctypes.ResultNetInfo, error)
  73. DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
  74. ConsensusState() (*ctypes.ResultConsensusState, error)
  75. Health() (*ctypes.ResultHealth, error)
  76. }
  77. // EventsClient is reactive, you can subscribe to any message, given the proper
  78. // string. see tendermint/types/events.go
  79. type EventsClient interface {
  80. types.EventBusSubscriber
  81. }