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.

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