diff --git a/rpc/client/http/client.go b/rpc/client/http/client.go index c0c8d00ed..f57162670 100644 --- a/rpc/client/http/client.go +++ b/rpc/client/http/client.go @@ -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) { diff --git a/rpc/client/interface.go b/rpc/client/interface.go new file mode 100644 index 000000000..33f5dace5 --- /dev/null +++ b/rpc/client/interface.go @@ -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) +} diff --git a/rpc/client/local/client.go b/rpc/client/local/client.go index 3817e2df1..f050b6b18 100644 --- a/rpc/client/local/client.go +++ b/rpc/client/local/client.go @@ -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() }