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.

84 lines
2.9 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, prove bool) (*ctypes.ResultABCIQuery, error)
  29. // writing to abci app
  30. BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
  31. BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
  32. BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
  33. }
  34. // SignClient groups together the interfaces need to get valid
  35. // signatures and prove anything about the chain
  36. type SignClient interface {
  37. Block(height *int) (*ctypes.ResultBlock, error)
  38. Commit(height *int) (*ctypes.ResultCommit, error)
  39. Validators(height *int) (*ctypes.ResultValidators, error)
  40. Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
  41. }
  42. // HistoryClient shows us data from genesis to now in large chunks.
  43. type HistoryClient interface {
  44. Genesis() (*ctypes.ResultGenesis, error)
  45. BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error)
  46. }
  47. type StatusClient interface {
  48. // general chain info
  49. Status() (*ctypes.ResultStatus, error)
  50. }
  51. // Client wraps most important rpc calls a client would make
  52. // if you want to listen for events, test if it also
  53. // implements events.EventSwitch
  54. type Client interface {
  55. ABCIClient
  56. SignClient
  57. HistoryClient
  58. StatusClient
  59. // this Client is reactive, you can subscribe to any TMEventData
  60. // type, given the proper string. see tendermint/types/events.go
  61. types.EventSwitch
  62. }
  63. // NetworkClient is general info about the network state. May not
  64. // be needed usually.
  65. //
  66. // Not included in the Client interface, but generally implemented
  67. // by concrete implementations.
  68. type NetworkClient interface {
  69. NetInfo() (*ctypes.ResultNetInfo, error)
  70. DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
  71. }