2017-02-23 14:16:59 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2017-04-21 18:13:25 -04:00
|
|
|
data "github.com/tendermint/go-wire/data"
|
2017-02-23 14:16:59 +01:00
|
|
|
nm "github.com/tendermint/tendermint/node"
|
2017-04-26 19:57:33 -04:00
|
|
|
"github.com/tendermint/tendermint/rpc/core"
|
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2017-02-23 14:16:59 +01:00
|
|
|
"github.com/tendermint/tendermint/types"
|
|
|
|
)
|
|
|
|
|
2017-02-22 14:41:10 +01:00
|
|
|
/*
|
2017-02-23 14:16:59 +01:00
|
|
|
Local is a Client implementation that directly executes the rpc
|
|
|
|
functions on a given node, without going through HTTP or GRPC
|
2017-02-22 14:41:10 +01:00
|
|
|
|
|
|
|
This implementation is useful for:
|
|
|
|
|
|
|
|
* Running tests against a node in-process without the overhead
|
|
|
|
of going through an http server
|
|
|
|
* Communication between an ABCI app and tendermin core when they
|
|
|
|
are compiled in process.
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
For real clients, you probably want to use client.HTTP. For more
|
|
|
|
powerful control during testing, you probably want the "client/mock" package.
|
2017-02-22 14:41:10 +01:00
|
|
|
*/
|
2017-02-23 14:16:59 +01:00
|
|
|
type Local struct {
|
2017-02-22 14:41:10 +01:00
|
|
|
node *nm.Node
|
2017-02-24 17:51:19 +01:00
|
|
|
types.EventSwitch
|
2017-02-22 14:41:10 +01:00
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
// NewLocal configures a client that calls the Node directly.
|
2017-02-22 14:41:10 +01:00
|
|
|
//
|
|
|
|
// Note that given how rpc/core works with package singletons, that
|
|
|
|
// you can only have one node per process. So make sure test cases
|
|
|
|
// don't run in parallel, or try to simulate an entire network in
|
|
|
|
// one process...
|
2017-02-23 14:16:59 +01:00
|
|
|
func NewLocal(node *nm.Node) Local {
|
2017-02-22 14:41:10 +01:00
|
|
|
node.ConfigureRPC()
|
2017-02-23 14:16:59 +01:00
|
|
|
return Local{
|
2017-02-24 17:51:19 +01:00
|
|
|
node: node,
|
|
|
|
EventSwitch: node.EventSwitch(),
|
2017-02-22 14:41:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) _assertIsClient() Client {
|
2017-02-22 14:54:13 +01:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2017-02-24 17:04:38 +01:00
|
|
|
func (c Local) _assertIsNetworkClient() NetworkClient {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) Status() (*ctypes.ResultStatus, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.Status()
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.ABCIInfo()
|
|
|
|
}
|
|
|
|
|
2017-10-11 01:31:31 +04:00
|
|
|
func (c Local) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
|
|
|
|
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Local) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
|
|
|
return core.ABCIQuery(path, data, opts.Height, opts.Prove)
|
2017-02-22 14:41:10 +01:00
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.BroadcastTxCommit(tx)
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.BroadcastTxAsync(tx)
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.BroadcastTxSync(tx)
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) NetInfo() (*ctypes.ResultNetInfo, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.NetInfo()
|
|
|
|
}
|
|
|
|
|
2017-02-24 17:04:38 +01:00
|
|
|
func (c Local) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
|
|
|
return core.DumpConsensusState()
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.UnsafeDialSeeds(seeds)
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.BlockchainInfo(minHeight, maxHeight)
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:16:59 +01:00
|
|
|
func (c Local) Genesis() (*ctypes.ResultGenesis, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.Genesis()
|
|
|
|
}
|
|
|
|
|
2017-08-22 17:42:23 -04:00
|
|
|
func (c Local) Block(height *int) (*ctypes.ResultBlock, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.Block(height)
|
|
|
|
}
|
|
|
|
|
2017-08-22 17:42:23 -04:00
|
|
|
func (c Local) Commit(height *int) (*ctypes.ResultCommit, error) {
|
2017-02-22 14:41:10 +01:00
|
|
|
return core.Commit(height)
|
|
|
|
}
|
|
|
|
|
2017-08-21 18:11:16 -04:00
|
|
|
func (c Local) Validators(height *int) (*ctypes.ResultValidators, error) {
|
|
|
|
return core.Validators(height)
|
2017-02-22 14:41:10 +01:00
|
|
|
}
|
2017-04-13 21:49:21 +02:00
|
|
|
|
2017-04-18 19:56:41 -04:00
|
|
|
func (c Local) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|
|
|
return core.Tx(hash, prove)
|
2017-04-13 21:49:21 +02:00
|
|
|
}
|