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.

85 lines
3.0 KiB

  1. /*
  2. package client provides a general purpose interface (Client) for connecting
  3. to a tendermint node, as well as higher-level functionality.
  4. The main implementation for production code is client.HTTP, which
  5. connects via http to the jsonrpc interface of the tendermint node.
  6. For connecting to a node running in the same process (eg. when
  7. compiling the abci app in the same process), you can use the client.Local
  8. implementation.
  9. For mocking out server responses during testing to see behavior for
  10. arbitrary return values, use the mock package.
  11. In addition to the Client interface, which should be used externally
  12. for maximum flexibility and testability, and two implementations,
  13. this package also provides helper functions that work on any Client
  14. implementation.
  15. */
  16. package client
  17. import (
  18. data "github.com/tendermint/go-wire/data"
  19. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  20. "github.com/tendermint/tendermint/types"
  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 data.Bytes) (*ctypes.ResultABCIQuery, error)
  29. ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
  30. // writing to abci app
  31. BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
  32. BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
  33. BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
  34. }
  35. // SignClient groups together the interfaces need to get valid
  36. // signatures and prove anything about the chain
  37. type SignClient interface {
  38. Block(height *int) (*ctypes.ResultBlock, error)
  39. Commit(height *int) (*ctypes.ResultCommit, error)
  40. Validators(height *int) (*ctypes.ResultValidators, error)
  41. Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
  42. }
  43. // HistoryClient shows us data from genesis to now in large chunks.
  44. type HistoryClient interface {
  45. Genesis() (*ctypes.ResultGenesis, error)
  46. BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error)
  47. }
  48. type StatusClient interface {
  49. // general chain info
  50. Status() (*ctypes.ResultStatus, error)
  51. }
  52. // Client wraps most important rpc calls a client would make
  53. // if you want to listen for events, test if it also
  54. // implements events.EventSwitch
  55. type Client interface {
  56. ABCIClient
  57. SignClient
  58. HistoryClient
  59. StatusClient
  60. // this Client is reactive, you can subscribe to any TMEventData
  61. // type, given the proper string. see tendermint/types/events.go
  62. types.EventSwitch
  63. }
  64. // NetworkClient is general info about the network state. May not
  65. // be needed usually.
  66. //
  67. // Not included in the Client interface, but generally implemented
  68. // by concrete implementations.
  69. type NetworkClient interface {
  70. NetInfo() (*ctypes.ResultNetInfo, error)
  71. DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
  72. }