Extracted Clients into a consistent interface, fixed type issue in http.Client
This commit is contained in:
parent
7c26be3242
commit
ce044dbb76
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tendermint/go-rpc/client"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
@ -37,6 +38,10 @@ func New(remote, wsEndpoint string) *Client {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Client) _assertIsClient() client.Client {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Client) Status() (*ctypes.ResultStatus, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("status", []interface{}{}, tmResult)
|
||||
|
@ -66,24 +71,29 @@ func (c *Client) ABCIQuery(path string, data []byte, prove bool) (*ctypes.Result
|
|||
}
|
||||
|
||||
func (c *Client) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
return c.broadcastTX("broadcast_tx_commit", tx)
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call("broadcast_tx_commit", []interface{}{tx}, tmResult)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "broadcast_tx_commit")
|
||||
}
|
||||
return (*tmResult).(*ctypes.ResultBroadcastTxCommit), nil
|
||||
}
|
||||
|
||||
func (c *Client) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
func (c *Client) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return c.broadcastTX("broadcast_tx_async", tx)
|
||||
}
|
||||
|
||||
func (c *Client) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
func (c *Client) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
return c.broadcastTX("broadcast_tx_sync", tx)
|
||||
}
|
||||
|
||||
func (c *Client) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
func (c *Client) broadcastTX(route string, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
_, err := c.rpc.Call(route, []interface{}{tx}, tmResult)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, route)
|
||||
}
|
||||
return (*tmResult).(*ctypes.ResultBroadcastTxCommit), nil
|
||||
return (*tmResult).(*ctypes.ResultBroadcastTx), nil
|
||||
}
|
||||
|
||||
func (c *Client) NetInfo() (*ctypes.ResultNetInfo, error) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
package client provides a general purpose interface for connecting
|
||||
to a tendermint node, as well as higher-level functionality.
|
||||
|
||||
The main implementation for production code is http, which connects
|
||||
via http to the jsonrpc interface of the tendermint node.
|
||||
|
||||
For connecting to a node running in the same process (eg. when
|
||||
compiling the abci app in the same process), you can use the local
|
||||
implementation.
|
||||
|
||||
For mocking out server responses during testing to see behavior for
|
||||
arbitrary return values, use the mock package.
|
||||
|
||||
In addition to the Client interface, which should be used externally
|
||||
for maximum flexibility and testability, this package also provides
|
||||
a wrapper that accepts any Client implementation and adds some
|
||||
higher-level functionality.
|
||||
*/
|
||||
package client
|
||||
|
||||
import (
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
type Client interface {
|
||||
// general chain info
|
||||
Status() (*ctypes.ResultStatus, error)
|
||||
NetInfo() (*ctypes.ResultNetInfo, error)
|
||||
Genesis() (*ctypes.ResultGenesis, error)
|
||||
|
||||
// reading from abci app
|
||||
ABCIInfo() (*ctypes.ResultABCIInfo, error)
|
||||
ABCIQuery(path string, data []byte, prove bool) (*ctypes.ResultABCIQuery, error)
|
||||
|
||||
// writing to abci app
|
||||
BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
|
||||
BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
|
||||
BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error)
|
||||
|
||||
// validating block info
|
||||
BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error)
|
||||
Block(height int) (*ctypes.ResultBlock, error)
|
||||
Commit(height int) (*ctypes.ResultCommit, error)
|
||||
Validators() (*ctypes.ResultValidators, error)
|
||||
|
||||
// TODO: add some sort of generic subscription mechanism...
|
||||
|
||||
// remove this???
|
||||
// DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error)
|
||||
}
|
|
@ -16,6 +16,7 @@ package localclient
|
|||
|
||||
import (
|
||||
nm "github.com/tendermint/tendermint/node"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
"github.com/tendermint/tendermint/rpc/core"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
@ -38,6 +39,10 @@ func New(node *nm.Node) Client {
|
|||
}
|
||||
}
|
||||
|
||||
func (c Client) _assertIsClient() client.Client {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Client) Status() (*ctypes.ResultStatus, error) {
|
||||
return core.Status()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue