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.

110 lines
2.9 KiB

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