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.

105 lines
2.8 KiB

  1. package client
  2. import (
  3. nm "github.com/tendermint/tendermint/node"
  4. "github.com/tendermint/tendermint/rpc/core"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. /*
  9. Local is a Client implementation that directly executes the rpc
  10. functions on a given node, without going through HTTP or GRPC
  11. This implementation is useful for:
  12. * Running tests against a node in-process without the overhead
  13. of going through an http server
  14. * Communication between an ABCI app and tendermin core when they
  15. are compiled in process.
  16. For real clients, you probably want to use client.HTTP. For more
  17. powerful control during testing, you probably want the "client/mock" package.
  18. */
  19. type Local struct {
  20. node *nm.Node
  21. types.EventSwitch
  22. }
  23. // NewLocal configures a client that calls the Node directly.
  24. //
  25. // Note that given how rpc/core works with package singletons, that
  26. // you can only have one node per process. So make sure test cases
  27. // don't run in parallel, or try to simulate an entire network in
  28. // one process...
  29. func NewLocal(node *nm.Node) Local {
  30. node.ConfigureRPC()
  31. return Local{
  32. node: node,
  33. EventSwitch: node.EventSwitch(),
  34. }
  35. }
  36. func (c Local) _assertIsClient() Client {
  37. return c
  38. }
  39. func (c Local) _assertIsNetworkClient() NetworkClient {
  40. return c
  41. }
  42. func (c Local) Status() (*ctypes.ResultStatus, error) {
  43. return core.Status()
  44. }
  45. func (c Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
  46. return core.ABCIInfo()
  47. }
  48. func (c Local) ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error) {
  49. return core.ABCIQuery(path, data, prove)
  50. }
  51. func (c Local) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
  52. return core.BroadcastTxCommit(tx)
  53. }
  54. func (c Local) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  55. return core.BroadcastTxAsync(tx)
  56. }
  57. func (c Local) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  58. return core.BroadcastTxSync(tx)
  59. }
  60. func (c Local) NetInfo() (*ctypes.ResultNetInfo, error) {
  61. return core.NetInfo()
  62. }
  63. func (c Local) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
  64. return core.DumpConsensusState()
  65. }
  66. func (c Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
  67. return core.UnsafeDialSeeds(seeds)
  68. }
  69. func (c Local) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
  70. return core.BlockchainInfo(minHeight, maxHeight)
  71. }
  72. func (c Local) Genesis() (*ctypes.ResultGenesis, error) {
  73. return core.Genesis()
  74. }
  75. func (c Local) Block(height int) (*ctypes.ResultBlock, error) {
  76. return core.Block(height)
  77. }
  78. func (c Local) Commit(height int) (*ctypes.ResultCommit, error) {
  79. return core.Commit(height)
  80. }
  81. func (c Local) Validators() (*ctypes.ResultValidators, error) {
  82. return core.Validators()
  83. }