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.

111 lines
3.1 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. var (
  38. _ Client = Local{}
  39. _ NetworkClient = Local{}
  40. )
  41. func (c Local) Status() (*ctypes.ResultStatus, error) {
  42. return core.Status()
  43. }
  44. func (c Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
  45. return core.ABCIInfo()
  46. }
  47. func (c Local) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
  48. return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions)
  49. }
  50. func (c Local) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
  51. return core.ABCIQuery(path, data, opts.Height, opts.Trusted)
  52. }
  53. func (c Local) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
  54. return core.BroadcastTxCommit(tx)
  55. }
  56. func (c Local) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  57. return core.BroadcastTxAsync(tx)
  58. }
  59. func (c Local) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  60. return core.BroadcastTxSync(tx)
  61. }
  62. func (c Local) NetInfo() (*ctypes.ResultNetInfo, error) {
  63. return core.NetInfo()
  64. }
  65. func (c Local) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
  66. return core.DumpConsensusState()
  67. }
  68. func (c Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
  69. return core.UnsafeDialSeeds(seeds)
  70. }
  71. func (c Local) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
  72. return core.BlockchainInfo(minHeight, maxHeight)
  73. }
  74. func (c Local) Genesis() (*ctypes.ResultGenesis, error) {
  75. return core.Genesis()
  76. }
  77. func (c Local) Block(height *int) (*ctypes.ResultBlock, error) {
  78. return core.Block(height)
  79. }
  80. func (c Local) Commit(height *int) (*ctypes.ResultCommit, error) {
  81. return core.Commit(height)
  82. }
  83. func (c Local) Validators(height *int) (*ctypes.ResultValidators, error) {
  84. return core.Validators(height)
  85. }
  86. func (c Local) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
  87. return core.Tx(hash, prove)
  88. }