cleanup: Reduce and normalize import path aliasing. (#6975)

The code in the Tendermint repository makes heavy use of import aliasing.
This is made necessary by our extensive reuse of common base package names, and
by repetition of similar names across different subdirectories.

Unfortunately we have not been very consistent about which packages we alias in
various circumstances, and the aliases we use vary. In the spirit of the advice
in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports,
his change makes an effort to clean up and normalize import aliasing.

This change makes no API or behavioral changes. It is a pure cleanup intended
o help make the code more readable to developers (including myself) trying to
understand what is being imported where.

Only unexported names have been modified, and the changes were generated and
applied mechanically with gofmt -r and comby, respecting the lexical and
syntactic rules of Go.  Even so, I did not fix every inconsistency. Where the
changes would be too disruptive, I left it alone.

The principles I followed in this cleanup are:

- Remove aliases that restate the package name.
- Remove aliases where the base package name is unambiguous.
- Move overly-terse abbreviations from the import to the usage site.
- Fix lexical issues (remove underscores, remove capitalization).
- Fix import groupings to more closely match the style guide.
- Group blank (side-effecting) imports and ensure they are commented.
- Add aliases to multiple imports with the same base package name.
This commit is contained in:
M. J. Fromberger
2021-09-23 07:52:07 -07:00
committed by GitHub
parent c9beef796d
commit cf7537ea5f
127 changed files with 1473 additions and 1473 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/types"
)
@@ -127,7 +127,7 @@ func testTxEventsSent(t *testing.T, broadcastMethod string) {
// send
go func() {
var (
txres *ctypes.ResultBroadcastTx
txres *coretypes.ResultBroadcastTx
err error
ctx = context.Background()
)
+2 -2
View File
@@ -11,7 +11,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/tmhash"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/privval"
@@ -150,7 +150,7 @@ func TestBroadcastEvidence_DuplicateVoteEvidence(t *testing.T) {
err = abci.ReadMessage(bytes.NewReader(qres.Value), &v)
require.NoError(t, err, "Error reading query result, value %v", qres.Value)
pk, err := cryptoenc.PubKeyFromProto(v.PubKey)
pk, err := encoding.PubKeyFromProto(v.PubKey)
require.NoError(t, err)
require.EqualValues(t, rawpub, pk, "Stored PubKey not equal with expected, value %v", string(qres.Value))
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"github.com/tendermint/tendermint/abci/example/kvstore"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctest "github.com/tendermint/tendermint/rpc/test"
)
@@ -138,7 +138,7 @@ func ExampleHTTP_batching() {
// Each result in the returned list is the deserialized result of each
// respective ABCIQuery response
for _, result := range results {
qr, ok := result.(*ctypes.ResultABCIQuery)
qr, ok := result.(*coretypes.ResultABCIQuery)
if !ok {
log.Fatal("invalid result type from ABCIQuery request")
}
+5 -5
View File
@@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/client/mock"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
)
func TestWaitForHeight(t *testing.T) {
@@ -33,7 +33,7 @@ func TestWaitForHeight(t *testing.T) {
// now set current block height to 10
m.Call = mock.Call{
Response: &ctypes.ResultStatus{SyncInfo: ctypes.SyncInfo{LatestBlockHeight: 10}},
Response: &coretypes.ResultStatus{SyncInfo: coretypes.SyncInfo{LatestBlockHeight: 10}},
}
// we will not wait for more than 10 blocks
@@ -53,7 +53,7 @@ func TestWaitForHeight(t *testing.T) {
// we use the callback to update the status height
myWaiter := func(delta int64) error {
// update the height for the next call
m.Call.Response = &ctypes.ResultStatus{SyncInfo: ctypes.SyncInfo{LatestBlockHeight: 15}}
m.Call.Response = &coretypes.ResultStatus{SyncInfo: coretypes.SyncInfo{LatestBlockHeight: 15}}
return client.DefaultWaitStrategy(delta)
}
@@ -65,13 +65,13 @@ func TestWaitForHeight(t *testing.T) {
pre := r.Calls[3]
require.Nil(pre.Error)
prer, ok := pre.Response.(*ctypes.ResultStatus)
prer, ok := pre.Response.(*coretypes.ResultStatus)
require.True(ok)
assert.Equal(int64(10), prer.SyncInfo.LatestBlockHeight)
post := r.Calls[4]
require.Nil(post.Error)
postr, ok := post.Response.(*ctypes.ResultStatus)
postr, ok := post.Response.(*coretypes.ResultStatus)
require.True(ok)
assert.Equal(int64(15), postr.SyncInfo.LatestBlockHeight)
}
+54 -54
View File
@@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/libs/bytes"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tendermint/tendermint/types"
)
@@ -198,8 +198,8 @@ func (b *BatchHTTP) Count() int {
//-----------------------------------------------------------------------------
// baseRPCClient
func (c *baseRPCClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
result := new(ctypes.ResultStatus)
func (c *baseRPCClient) Status(ctx context.Context) (*coretypes.ResultStatus, error) {
result := new(coretypes.ResultStatus)
_, err := c.caller.Call(ctx, "status", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -208,8 +208,8 @@ func (c *baseRPCClient) Status(ctx context.Context) (*ctypes.ResultStatus, error
return result, nil
}
func (c *baseRPCClient) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
result := new(ctypes.ResultABCIInfo)
func (c *baseRPCClient) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
result := new(coretypes.ResultABCIInfo)
_, err := c.caller.Call(ctx, "abci_info", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -222,7 +222,7 @@ func (c *baseRPCClient) ABCIQuery(
ctx context.Context,
path string,
data bytes.HexBytes,
) (*ctypes.ResultABCIQuery, error) {
) (*coretypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(ctx, path, data, rpcclient.DefaultABCIQueryOptions)
}
@@ -230,8 +230,8 @@ func (c *baseRPCClient) ABCIQueryWithOptions(
ctx context.Context,
path string,
data bytes.HexBytes,
opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
result := new(ctypes.ResultABCIQuery)
opts rpcclient.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) {
result := new(coretypes.ResultABCIQuery)
_, err := c.caller.Call(ctx, "abci_query",
map[string]interface{}{"path": path, "data": data, "height": opts.Height, "prove": opts.Prove},
result)
@@ -245,8 +245,8 @@ func (c *baseRPCClient) ABCIQueryWithOptions(
func (c *baseRPCClient) BroadcastTxCommit(
ctx context.Context,
tx types.Tx,
) (*ctypes.ResultBroadcastTxCommit, error) {
result := new(ctypes.ResultBroadcastTxCommit)
) (*coretypes.ResultBroadcastTxCommit, error) {
result := new(coretypes.ResultBroadcastTxCommit)
_, err := c.caller.Call(ctx, "broadcast_tx_commit", map[string]interface{}{"tx": tx}, result)
if err != nil {
return nil, err
@@ -257,14 +257,14 @@ func (c *baseRPCClient) BroadcastTxCommit(
func (c *baseRPCClient) BroadcastTxAsync(
ctx context.Context,
tx types.Tx,
) (*ctypes.ResultBroadcastTx, error) {
) (*coretypes.ResultBroadcastTx, error) {
return c.broadcastTX(ctx, "broadcast_tx_async", tx)
}
func (c *baseRPCClient) BroadcastTxSync(
ctx context.Context,
tx types.Tx,
) (*ctypes.ResultBroadcastTx, error) {
) (*coretypes.ResultBroadcastTx, error) {
return c.broadcastTX(ctx, "broadcast_tx_sync", tx)
}
@@ -272,8 +272,8 @@ func (c *baseRPCClient) broadcastTX(
ctx context.Context,
route string,
tx types.Tx,
) (*ctypes.ResultBroadcastTx, error) {
result := new(ctypes.ResultBroadcastTx)
) (*coretypes.ResultBroadcastTx, error) {
result := new(coretypes.ResultBroadcastTx)
_, err := c.caller.Call(ctx, route, map[string]interface{}{"tx": tx}, result)
if err != nil {
return nil, err
@@ -284,8 +284,8 @@ func (c *baseRPCClient) broadcastTX(
func (c *baseRPCClient) UnconfirmedTxs(
ctx context.Context,
limit *int,
) (*ctypes.ResultUnconfirmedTxs, error) {
result := new(ctypes.ResultUnconfirmedTxs)
) (*coretypes.ResultUnconfirmedTxs, error) {
result := new(coretypes.ResultUnconfirmedTxs)
params := make(map[string]interface{})
if limit != nil {
params["limit"] = limit
@@ -297,8 +297,8 @@ func (c *baseRPCClient) UnconfirmedTxs(
return result, nil
}
func (c *baseRPCClient) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUnconfirmedTxs, error) {
result := new(ctypes.ResultUnconfirmedTxs)
func (c *baseRPCClient) NumUnconfirmedTxs(ctx context.Context) (*coretypes.ResultUnconfirmedTxs, error) {
result := new(coretypes.ResultUnconfirmedTxs)
_, err := c.caller.Call(ctx, "num_unconfirmed_txs", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -306,8 +306,8 @@ func (c *baseRPCClient) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUn
return result, nil
}
func (c *baseRPCClient) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) {
result := new(ctypes.ResultCheckTx)
func (c *baseRPCClient) CheckTx(ctx context.Context, tx types.Tx) (*coretypes.ResultCheckTx, error) {
result := new(coretypes.ResultCheckTx)
_, err := c.caller.Call(ctx, "check_tx", map[string]interface{}{"tx": tx}, result)
if err != nil {
return nil, err
@@ -315,8 +315,8 @@ func (c *baseRPCClient) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.Resul
return result, nil
}
func (c *baseRPCClient) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error) {
result := new(ctypes.ResultNetInfo)
func (c *baseRPCClient) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, error) {
result := new(coretypes.ResultNetInfo)
_, err := c.caller.Call(ctx, "net_info", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -324,8 +324,8 @@ func (c *baseRPCClient) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, err
return result, nil
}
func (c *baseRPCClient) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error) {
result := new(ctypes.ResultDumpConsensusState)
func (c *baseRPCClient) DumpConsensusState(ctx context.Context) (*coretypes.ResultDumpConsensusState, error) {
result := new(coretypes.ResultDumpConsensusState)
_, err := c.caller.Call(ctx, "dump_consensus_state", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -333,8 +333,8 @@ func (c *baseRPCClient) DumpConsensusState(ctx context.Context) (*ctypes.ResultD
return result, nil
}
func (c *baseRPCClient) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error) {
result := new(ctypes.ResultConsensusState)
func (c *baseRPCClient) ConsensusState(ctx context.Context) (*coretypes.ResultConsensusState, error) {
result := new(coretypes.ResultConsensusState)
_, err := c.caller.Call(ctx, "consensus_state", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -345,8 +345,8 @@ func (c *baseRPCClient) ConsensusState(ctx context.Context) (*ctypes.ResultConse
func (c *baseRPCClient) ConsensusParams(
ctx context.Context,
height *int64,
) (*ctypes.ResultConsensusParams, error) {
result := new(ctypes.ResultConsensusParams)
) (*coretypes.ResultConsensusParams, error) {
result := new(coretypes.ResultConsensusParams)
params := make(map[string]interface{})
if height != nil {
params["height"] = height
@@ -358,8 +358,8 @@ func (c *baseRPCClient) ConsensusParams(
return result, nil
}
func (c *baseRPCClient) Health(ctx context.Context) (*ctypes.ResultHealth, error) {
result := new(ctypes.ResultHealth)
func (c *baseRPCClient) Health(ctx context.Context) (*coretypes.ResultHealth, error) {
result := new(coretypes.ResultHealth)
_, err := c.caller.Call(ctx, "health", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -371,8 +371,8 @@ func (c *baseRPCClient) BlockchainInfo(
ctx context.Context,
minHeight,
maxHeight int64,
) (*ctypes.ResultBlockchainInfo, error) {
result := new(ctypes.ResultBlockchainInfo)
) (*coretypes.ResultBlockchainInfo, error) {
result := new(coretypes.ResultBlockchainInfo)
_, err := c.caller.Call(ctx, "blockchain",
map[string]interface{}{"minHeight": minHeight, "maxHeight": maxHeight},
result)
@@ -382,8 +382,8 @@ func (c *baseRPCClient) BlockchainInfo(
return result, nil
}
func (c *baseRPCClient) Genesis(ctx context.Context) (*ctypes.ResultGenesis, error) {
result := new(ctypes.ResultGenesis)
func (c *baseRPCClient) Genesis(ctx context.Context) (*coretypes.ResultGenesis, error) {
result := new(coretypes.ResultGenesis)
_, err := c.caller.Call(ctx, "genesis", map[string]interface{}{}, result)
if err != nil {
return nil, err
@@ -391,8 +391,8 @@ func (c *baseRPCClient) Genesis(ctx context.Context) (*ctypes.ResultGenesis, err
return result, nil
}
func (c *baseRPCClient) GenesisChunked(ctx context.Context, id uint) (*ctypes.ResultGenesisChunk, error) {
result := new(ctypes.ResultGenesisChunk)
func (c *baseRPCClient) GenesisChunked(ctx context.Context, id uint) (*coretypes.ResultGenesisChunk, error) {
result := new(coretypes.ResultGenesisChunk)
_, err := c.caller.Call(ctx, "genesis_chunked", map[string]interface{}{"chunk": id}, result)
if err != nil {
return nil, err
@@ -400,8 +400,8 @@ func (c *baseRPCClient) GenesisChunked(ctx context.Context, id uint) (*ctypes.Re
return result, nil
}
func (c *baseRPCClient) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) {
result := new(ctypes.ResultBlock)
func (c *baseRPCClient) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) {
result := new(coretypes.ResultBlock)
params := make(map[string]interface{})
if height != nil {
params["height"] = height
@@ -413,8 +413,8 @@ func (c *baseRPCClient) Block(ctx context.Context, height *int64) (*ctypes.Resul
return result, nil
}
func (c *baseRPCClient) BlockByHash(ctx context.Context, hash bytes.HexBytes) (*ctypes.ResultBlock, error) {
result := new(ctypes.ResultBlock)
func (c *baseRPCClient) BlockByHash(ctx context.Context, hash bytes.HexBytes) (*coretypes.ResultBlock, error) {
result := new(coretypes.ResultBlock)
params := map[string]interface{}{
"hash": hash,
}
@@ -428,8 +428,8 @@ func (c *baseRPCClient) BlockByHash(ctx context.Context, hash bytes.HexBytes) (*
func (c *baseRPCClient) BlockResults(
ctx context.Context,
height *int64,
) (*ctypes.ResultBlockResults, error) {
result := new(ctypes.ResultBlockResults)
) (*coretypes.ResultBlockResults, error) {
result := new(coretypes.ResultBlockResults)
params := make(map[string]interface{})
if height != nil {
params["height"] = height
@@ -441,8 +441,8 @@ func (c *baseRPCClient) BlockResults(
return result, nil
}
func (c *baseRPCClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
result := new(ctypes.ResultCommit)
func (c *baseRPCClient) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) {
result := new(coretypes.ResultCommit)
params := make(map[string]interface{})
if height != nil {
params["height"] = height
@@ -454,8 +454,8 @@ func (c *baseRPCClient) Commit(ctx context.Context, height *int64) (*ctypes.Resu
return result, nil
}
func (c *baseRPCClient) Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*ctypes.ResultTx, error) {
result := new(ctypes.ResultTx)
func (c *baseRPCClient) Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*coretypes.ResultTx, error) {
result := new(coretypes.ResultTx)
params := map[string]interface{}{
"hash": hash,
"prove": prove,
@@ -474,9 +474,9 @@ func (c *baseRPCClient) TxSearch(
page,
perPage *int,
orderBy string,
) (*ctypes.ResultTxSearch, error) {
) (*coretypes.ResultTxSearch, error) {
result := new(ctypes.ResultTxSearch)
result := new(coretypes.ResultTxSearch)
params := map[string]interface{}{
"query": query,
"prove": prove,
@@ -503,9 +503,9 @@ func (c *baseRPCClient) BlockSearch(
query string,
page, perPage *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error) {
) (*coretypes.ResultBlockSearch, error) {
result := new(ctypes.ResultBlockSearch)
result := new(coretypes.ResultBlockSearch)
params := map[string]interface{}{
"query": query,
"order_by": orderBy,
@@ -531,8 +531,8 @@ func (c *baseRPCClient) Validators(
height *int64,
page,
perPage *int,
) (*ctypes.ResultValidators, error) {
result := new(ctypes.ResultValidators)
) (*coretypes.ResultValidators, error) {
result := new(coretypes.ResultValidators)
params := make(map[string]interface{})
if page != nil {
params["page"] = page
@@ -553,8 +553,8 @@ func (c *baseRPCClient) Validators(
func (c *baseRPCClient) BroadcastEvidence(
ctx context.Context,
ev types.Evidence,
) (*ctypes.ResultBroadcastEvidence, error) {
result := new(ctypes.ResultBroadcastEvidence)
) (*coretypes.ResultBroadcastEvidence, error) {
result := new(coretypes.ResultBroadcastEvidence)
_, err := c.caller.Call(ctx, "broadcast_evidence", map[string]interface{}{"evidence": ev}, result)
if err != nil {
return nil, err
+7 -7
View File
@@ -9,9 +9,9 @@ import (
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
tmjson "github.com/tendermint/tendermint/libs/json"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
"github.com/tendermint/tendermint/libs/pubsub"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
)
@@ -53,7 +53,7 @@ type wsEvents struct {
}
type wsSubscription struct {
res chan ctypes.ResultEvent
res chan coretypes.ResultEvent
id string
query string
}
@@ -119,7 +119,7 @@ func (w *wsEvents) Stop() error { return w.ws.Stop() }
//
// It returns an error if wsEvents is not running.
func (w *wsEvents) Subscribe(ctx context.Context, subscriber, query string,
outCapacity ...int) (out <-chan ctypes.ResultEvent, err error) {
outCapacity ...int) (out <-chan coretypes.ResultEvent, err error) {
if !w.IsRunning() {
return nil, rpcclient.ErrClientNotRunning
@@ -134,7 +134,7 @@ func (w *wsEvents) Subscribe(ctx context.Context, subscriber, query string,
outCap = outCapacity[0]
}
outc := make(chan ctypes.ResultEvent, outCap)
outc := make(chan coretypes.ResultEvent, outCap)
w.mtx.Lock()
defer w.mtx.Unlock()
// subscriber param is ignored because Tendermint will override it with
@@ -213,7 +213,7 @@ func (w *wsEvents) redoSubscriptionsAfter(d time.Duration) {
}
func isErrAlreadySubscribed(err error) bool {
return strings.Contains(err.Error(), tmpubsub.ErrAlreadySubscribed.Error())
return strings.Contains(err.Error(), pubsub.ErrAlreadySubscribed.Error())
}
func (w *wsEvents) eventListener() {
@@ -238,7 +238,7 @@ func (w *wsEvents) eventListener() {
continue
}
result := new(ctypes.ResultEvent)
result := new(coretypes.ResultEvent)
err := tmjson.Unmarshal(resp.Result, result)
if err != nil {
w.Logger.Error("failed to unmarshal response", "err", err)
+29 -29
View File
@@ -24,7 +24,7 @@ import (
"context"
"github.com/tendermint/tendermint/libs/bytes"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/types"
)
@@ -61,26 +61,26 @@ type Client interface {
// is easier to mock.
type ABCIClient interface {
// Reading from abci app
ABCIInfo(context.Context) (*ctypes.ResultABCIInfo, error)
ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)
ABCIInfo(context.Context) (*coretypes.ResultABCIInfo, error)
ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error)
ABCIQueryWithOptions(ctx context.Context, path string, data bytes.HexBytes,
opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
opts ABCIQueryOptions) (*coretypes.ResultABCIQuery, error)
// Writing to abci app
BroadcastTxCommit(context.Context, types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
BroadcastTxAsync(context.Context, types.Tx) (*ctypes.ResultBroadcastTx, error)
BroadcastTxSync(context.Context, types.Tx) (*ctypes.ResultBroadcastTx, error)
BroadcastTxCommit(context.Context, types.Tx) (*coretypes.ResultBroadcastTxCommit, error)
BroadcastTxAsync(context.Context, types.Tx) (*coretypes.ResultBroadcastTx, error)
BroadcastTxSync(context.Context, types.Tx) (*coretypes.ResultBroadcastTx, error)
}
// SignClient groups together the functionality needed to get valid signatures
// and prove anything about the chain.
type SignClient interface {
Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error)
BlockByHash(ctx context.Context, hash bytes.HexBytes) (*ctypes.ResultBlock, error)
BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error)
Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error)
Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error)
Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*ctypes.ResultTx, error)
Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error)
BlockByHash(ctx context.Context, hash bytes.HexBytes) (*coretypes.ResultBlock, error)
BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error)
Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error)
Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error)
Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*coretypes.ResultTx, error)
// TxSearch defines a method to search for a paginated set of transactions by
// DeliverTx event search criteria.
@@ -90,7 +90,7 @@ type SignClient interface {
prove bool,
page, perPage *int,
orderBy string,
) (*ctypes.ResultTxSearch, error)
) (*coretypes.ResultTxSearch, error)
// BlockSearch defines a method to search for a paginated set of blocks by
// BeginBlock and EndBlock event search criteria.
@@ -99,29 +99,29 @@ type SignClient interface {
query string,
page, perPage *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error)
) (*coretypes.ResultBlockSearch, error)
}
// HistoryClient provides access to data from genesis to now in large chunks.
type HistoryClient interface {
Genesis(context.Context) (*ctypes.ResultGenesis, error)
GenesisChunked(context.Context, uint) (*ctypes.ResultGenesisChunk, error)
BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
Genesis(context.Context) (*coretypes.ResultGenesis, error)
GenesisChunked(context.Context, uint) (*coretypes.ResultGenesisChunk, error)
BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error)
}
// StatusClient provides access to general chain info.
type StatusClient interface {
Status(context.Context) (*ctypes.ResultStatus, error)
Status(context.Context) (*coretypes.ResultStatus, error)
}
// NetworkClient is general info about the network state. May not be needed
// usually.
type NetworkClient interface {
NetInfo(context.Context) (*ctypes.ResultNetInfo, error)
DumpConsensusState(context.Context) (*ctypes.ResultDumpConsensusState, error)
ConsensusState(context.Context) (*ctypes.ResultConsensusState, error)
ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error)
Health(context.Context) (*ctypes.ResultHealth, error)
NetInfo(context.Context) (*coretypes.ResultNetInfo, error)
DumpConsensusState(context.Context) (*coretypes.ResultDumpConsensusState, error)
ConsensusState(context.Context) (*coretypes.ResultConsensusState, error)
ConsensusParams(ctx context.Context, height *int64) (*coretypes.ResultConsensusParams, error)
Health(context.Context) (*coretypes.ResultHealth, error)
}
// EventsClient is reactive, you can subscribe to any message, given the proper
@@ -134,7 +134,7 @@ type EventsClient interface {
//
// ctx cannot be used to unsubscribe. To unsubscribe, use either Unsubscribe
// or UnsubscribeAll.
Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error)
Subscribe(ctx context.Context, subscriber, query string, outCapacity ...int) (out <-chan coretypes.ResultEvent, err error) //nolint:lll
// Unsubscribe unsubscribes given subscriber from query.
Unsubscribe(ctx context.Context, subscriber, query string) error
// UnsubscribeAll unsubscribes given subscriber from all the queries.
@@ -143,15 +143,15 @@ type EventsClient interface {
// MempoolClient shows us data about current mempool state.
type MempoolClient interface {
UnconfirmedTxs(ctx context.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error)
NumUnconfirmedTxs(context.Context) (*ctypes.ResultUnconfirmedTxs, error)
CheckTx(context.Context, types.Tx) (*ctypes.ResultCheckTx, error)
UnconfirmedTxs(ctx context.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error)
NumUnconfirmedTxs(context.Context) (*coretypes.ResultUnconfirmedTxs, error)
CheckTx(context.Context, types.Tx) (*coretypes.ResultCheckTx, error)
}
// EvidenceClient is used for submitting an evidence of the malicious
// behavior.
type EvidenceClient interface {
BroadcastEvidence(context.Context, types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
BroadcastEvidence(context.Context, types.Evidence) (*coretypes.ResultBroadcastEvidence, error)
}
// RemoteClient is a Client, which can also return the remote network address.
+49 -49
View File
@@ -9,10 +9,10 @@ import (
rpccore "github.com/tendermint/tendermint/internal/rpc/core"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/libs/pubsub"
"github.com/tendermint/tendermint/libs/pubsub/query"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)
@@ -72,15 +72,15 @@ func (c *Local) SetLogger(l log.Logger) {
c.Logger = l
}
func (c *Local) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
func (c *Local) Status(ctx context.Context) (*coretypes.ResultStatus, error) {
return c.env.Status(c.ctx)
}
func (c *Local) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
func (c *Local) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
return c.env.ABCIInfo(c.ctx)
}
func (c *Local) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (c *Local) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(ctx, path, data, rpcclient.DefaultABCIQueryOptions)
}
@@ -88,55 +88,55 @@ func (c *Local) ABCIQueryWithOptions(
ctx context.Context,
path string,
data bytes.HexBytes,
opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
opts rpcclient.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) {
return c.env.ABCIQuery(c.ctx, path, data, opts.Height, opts.Prove)
}
func (c *Local) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
func (c *Local) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
return c.env.BroadcastTxCommit(c.ctx, tx)
}
func (c *Local) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (c *Local) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.env.BroadcastTxAsync(c.ctx, tx)
}
func (c *Local) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (c *Local) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.env.BroadcastTxSync(c.ctx, tx)
}
func (c *Local) UnconfirmedTxs(ctx context.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) {
func (c *Local) UnconfirmedTxs(ctx context.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error) {
return c.env.UnconfirmedTxs(c.ctx, limit)
}
func (c *Local) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUnconfirmedTxs, error) {
func (c *Local) NumUnconfirmedTxs(ctx context.Context) (*coretypes.ResultUnconfirmedTxs, error) {
return c.env.NumUnconfirmedTxs(c.ctx)
}
func (c *Local) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) {
func (c *Local) CheckTx(ctx context.Context, tx types.Tx) (*coretypes.ResultCheckTx, error) {
return c.env.CheckTx(c.ctx, tx)
}
func (c *Local) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error) {
func (c *Local) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, error) {
return c.env.NetInfo(c.ctx)
}
func (c *Local) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error) {
func (c *Local) DumpConsensusState(ctx context.Context) (*coretypes.ResultDumpConsensusState, error) {
return c.env.DumpConsensusState(c.ctx)
}
func (c *Local) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error) {
func (c *Local) ConsensusState(ctx context.Context) (*coretypes.ResultConsensusState, error) {
return c.env.GetConsensusState(c.ctx)
}
func (c *Local) ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error) {
func (c *Local) ConsensusParams(ctx context.Context, height *int64) (*coretypes.ResultConsensusParams, error) {
return c.env.ConsensusParams(c.ctx, height)
}
func (c *Local) Health(ctx context.Context) (*ctypes.ResultHealth, error) {
func (c *Local) Health(ctx context.Context) (*coretypes.ResultHealth, error) {
return c.env.Health(c.ctx)
}
func (c *Local) DialSeeds(ctx context.Context, seeds []string) (*ctypes.ResultDialSeeds, error) {
func (c *Local) DialSeeds(ctx context.Context, seeds []string) (*coretypes.ResultDialSeeds, error) {
return c.env.UnsafeDialSeeds(c.ctx, seeds)
}
@@ -146,76 +146,76 @@ func (c *Local) DialPeers(
persistent,
unconditional,
private bool,
) (*ctypes.ResultDialPeers, error) {
) (*coretypes.ResultDialPeers, error) {
return c.env.UnsafeDialPeers(c.ctx, peers, persistent, unconditional, private)
}
func (c *Local) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
func (c *Local) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) { //nolint:lll
return c.env.BlockchainInfo(c.ctx, minHeight, maxHeight)
}
func (c *Local) Genesis(ctx context.Context) (*ctypes.ResultGenesis, error) {
func (c *Local) Genesis(ctx context.Context) (*coretypes.ResultGenesis, error) {
return c.env.Genesis(c.ctx)
}
func (c *Local) GenesisChunked(ctx context.Context, id uint) (*ctypes.ResultGenesisChunk, error) {
func (c *Local) GenesisChunked(ctx context.Context, id uint) (*coretypes.ResultGenesisChunk, error) {
return c.env.GenesisChunked(c.ctx, id)
}
func (c *Local) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) {
func (c *Local) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) {
return c.env.Block(c.ctx, height)
}
func (c *Local) BlockByHash(ctx context.Context, hash bytes.HexBytes) (*ctypes.ResultBlock, error) {
func (c *Local) BlockByHash(ctx context.Context, hash bytes.HexBytes) (*coretypes.ResultBlock, error) {
return c.env.BlockByHash(c.ctx, hash)
}
func (c *Local) BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error) {
func (c *Local) BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) {
return c.env.BlockResults(c.ctx, height)
}
func (c *Local) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
func (c *Local) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) {
return c.env.Commit(c.ctx, height)
}
func (c *Local) Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) {
func (c *Local) Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) { //nolint:lll
return c.env.Validators(c.ctx, height, page, perPage)
}
func (c *Local) Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*ctypes.ResultTx, error) {
func (c *Local) Tx(ctx context.Context, hash bytes.HexBytes, prove bool) (*coretypes.ResultTx, error) {
return c.env.Tx(c.ctx, hash, prove)
}
func (c *Local) TxSearch(
_ context.Context,
query string,
queryString string,
prove bool,
page,
perPage *int,
orderBy string,
) (*ctypes.ResultTxSearch, error) {
return c.env.TxSearch(c.ctx, query, prove, page, perPage, orderBy)
) (*coretypes.ResultTxSearch, error) {
return c.env.TxSearch(c.ctx, queryString, prove, page, perPage, orderBy)
}
func (c *Local) BlockSearch(
_ context.Context,
query string,
queryString string,
page, perPage *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error) {
return c.env.BlockSearch(c.ctx, query, page, perPage, orderBy)
) (*coretypes.ResultBlockSearch, error) {
return c.env.BlockSearch(c.ctx, queryString, page, perPage, orderBy)
}
func (c *Local) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
func (c *Local) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error) {
return c.env.BroadcastEvidence(c.ctx, ev)
}
func (c *Local) Subscribe(
ctx context.Context,
subscriber,
query string,
outCapacity ...int) (out <-chan ctypes.ResultEvent, err error) {
q, err := tmquery.New(query)
queryString string,
outCapacity ...int) (out <-chan coretypes.ResultEvent, err error) {
q, err := query.New(queryString)
if err != nil {
return nil, fmt.Errorf("failed to parse query: %w", err)
}
@@ -235,7 +235,7 @@ func (c *Local) Subscribe(
return nil, fmt.Errorf("failed to subscribe: %w", err)
}
outc := make(chan ctypes.ResultEvent, outCap)
outc := make(chan coretypes.ResultEvent, outCap)
go c.eventsRoutine(sub, subscriber, q, outc)
return outc, nil
@@ -244,12 +244,12 @@ func (c *Local) Subscribe(
func (c *Local) eventsRoutine(
sub types.Subscription,
subscriber string,
q tmpubsub.Query,
outc chan<- ctypes.ResultEvent) {
q pubsub.Query,
outc chan<- coretypes.ResultEvent) {
for {
select {
case msg := <-sub.Out():
result := ctypes.ResultEvent{
result := coretypes.ResultEvent{
SubscriptionID: msg.SubscriptionID(),
Query: q.String(),
Data: msg.Data(),
@@ -266,7 +266,7 @@ func (c *Local) eventsRoutine(
}
}
case <-sub.Canceled():
if sub.Err() == tmpubsub.ErrUnsubscribed {
if sub.Err() == pubsub.ErrUnsubscribed {
return
}
@@ -282,7 +282,7 @@ func (c *Local) eventsRoutine(
}
// Try to resubscribe with exponential backoff.
func (c *Local) resubscribe(subscriber string, q tmpubsub.Query) types.Subscription {
func (c *Local) resubscribe(subscriber string, q pubsub.Query) types.Subscription {
attempts := 0
for {
if !c.IsRunning() {
@@ -299,17 +299,17 @@ func (c *Local) resubscribe(subscriber string, q tmpubsub.Query) types.Subscript
}
}
func (c *Local) Unsubscribe(ctx context.Context, subscriber, query string) error {
args := tmpubsub.UnsubscribeArgs{Subscriber: subscriber}
func (c *Local) Unsubscribe(ctx context.Context, subscriber, queryString string) error {
args := pubsub.UnsubscribeArgs{Subscriber: subscriber}
var err error
args.Query, err = tmquery.New(query)
args.Query, err = query.New(queryString)
if err != nil {
// if this isn't a valid query it might be an ID, so
// we'll try that. It'll turn into an error when we
// try to unsubscribe. Eventually, perhaps, we'll want
// to change the interface to only allow
// unsubscription by ID, but that's a larger change.
args.ID = query
args.ID = queryString
}
return c.EventBus.Unsubscribe(ctx, args)
}
+29 -29
View File
@@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/internal/proxy"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/types"
)
@@ -24,11 +24,11 @@ var (
_ client.ABCIClient = (*ABCIRecorder)(nil)
)
func (a ABCIApp) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
return &ctypes.ResultABCIInfo{Response: a.App.Info(proxy.RequestInfo)}, nil
func (a ABCIApp) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
return &coretypes.ResultABCIInfo{Response: a.App.Info(proxy.RequestInfo)}, nil
}
func (a ABCIApp) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (a ABCIApp) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error) {
return a.ABCIQueryWithOptions(ctx, path, data, client.DefaultABCIQueryOptions)
}
@@ -36,21 +36,21 @@ func (a ABCIApp) ABCIQueryWithOptions(
ctx context.Context,
path string,
data bytes.HexBytes,
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
opts client.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) {
q := a.App.Query(abci.RequestQuery{
Data: data,
Path: path,
Height: opts.Height,
Prove: opts.Prove,
})
return &ctypes.ResultABCIQuery{Response: q}, nil
return &coretypes.ResultABCIQuery{Response: q}, nil
}
// NOTE: Caller should call a.App.Commit() separately,
// this function does not actually wait for a commit.
// TODO: Make it wait for a commit and set res.Height appropriately.
func (a ABCIApp) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
res := ctypes.ResultBroadcastTxCommit{}
func (a ABCIApp) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
res := coretypes.ResultBroadcastTxCommit{}
res.CheckTx = a.App.CheckTx(abci.RequestCheckTx{Tx: tx})
if res.CheckTx.IsErr() {
return &res, nil
@@ -60,13 +60,13 @@ func (a ABCIApp) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.Re
return &res, nil
}
func (a ABCIApp) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (a ABCIApp) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
c := a.App.CheckTx(abci.RequestCheckTx{Tx: tx})
// and this gets written in a background thread...
if !c.IsErr() {
go func() { a.App.DeliverTx(abci.RequestDeliverTx{Tx: tx}) }()
}
return &ctypes.ResultBroadcastTx{
return &coretypes.ResultBroadcastTx{
Code: c.Code,
Data: c.Data,
Log: c.Log,
@@ -75,13 +75,13 @@ func (a ABCIApp) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.Res
}, nil
}
func (a ABCIApp) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (a ABCIApp) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
c := a.App.CheckTx(abci.RequestCheckTx{Tx: tx})
// and this gets written in a background thread...
if !c.IsErr() {
go func() { a.App.DeliverTx(abci.RequestDeliverTx{Tx: tx}) }()
}
return &ctypes.ResultBroadcastTx{
return &coretypes.ResultBroadcastTx{
Code: c.Code,
Data: c.Data,
Log: c.Log,
@@ -100,15 +100,15 @@ type ABCIMock struct {
Broadcast Call
}
func (m ABCIMock) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
func (m ABCIMock) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
res, err := m.Info.GetResponse(nil)
if err != nil {
return nil, err
}
return &ctypes.ResultABCIInfo{Response: res.(abci.ResponseInfo)}, nil
return &coretypes.ResultABCIInfo{Response: res.(abci.ResponseInfo)}, nil
}
func (m ABCIMock) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (m ABCIMock) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error) {
return m.ABCIQueryWithOptions(ctx, path, data, client.DefaultABCIQueryOptions)
}
@@ -116,37 +116,37 @@ func (m ABCIMock) ABCIQueryWithOptions(
ctx context.Context,
path string,
data bytes.HexBytes,
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
opts client.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) {
res, err := m.Query.GetResponse(QueryArgs{path, data, opts.Height, opts.Prove})
if err != nil {
return nil, err
}
resQuery := res.(abci.ResponseQuery)
return &ctypes.ResultABCIQuery{Response: resQuery}, nil
return &coretypes.ResultABCIQuery{Response: resQuery}, nil
}
func (m ABCIMock) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
func (m ABCIMock) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
res, err := m.BroadcastCommit.GetResponse(tx)
if err != nil {
return nil, err
}
return res.(*ctypes.ResultBroadcastTxCommit), nil
return res.(*coretypes.ResultBroadcastTxCommit), nil
}
func (m ABCIMock) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (m ABCIMock) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
res, err := m.Broadcast.GetResponse(tx)
if err != nil {
return nil, err
}
return res.(*ctypes.ResultBroadcastTx), nil
return res.(*coretypes.ResultBroadcastTx), nil
}
func (m ABCIMock) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (m ABCIMock) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
res, err := m.Broadcast.GetResponse(tx)
if err != nil {
return nil, err
}
return res.(*ctypes.ResultBroadcastTx), nil
return res.(*coretypes.ResultBroadcastTx), nil
}
// ABCIRecorder can wrap another type (ABCIApp, ABCIMock, or Client)
@@ -174,7 +174,7 @@ func (r *ABCIRecorder) addCall(call Call) {
r.Calls = append(r.Calls, call)
}
func (r *ABCIRecorder) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
func (r *ABCIRecorder) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
res, err := r.Client.ABCIInfo(ctx)
r.addCall(Call{
Name: "abci_info",
@@ -188,7 +188,7 @@ func (r *ABCIRecorder) ABCIQuery(
ctx context.Context,
path string,
data bytes.HexBytes,
) (*ctypes.ResultABCIQuery, error) {
) (*coretypes.ResultABCIQuery, error) {
return r.ABCIQueryWithOptions(ctx, path, data, client.DefaultABCIQueryOptions)
}
@@ -196,7 +196,7 @@ func (r *ABCIRecorder) ABCIQueryWithOptions(
ctx context.Context,
path string,
data bytes.HexBytes,
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
opts client.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) {
res, err := r.Client.ABCIQueryWithOptions(ctx, path, data, opts)
r.addCall(Call{
Name: "abci_query",
@@ -207,7 +207,7 @@ func (r *ABCIRecorder) ABCIQueryWithOptions(
return res, err
}
func (r *ABCIRecorder) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
func (r *ABCIRecorder) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
res, err := r.Client.BroadcastTxCommit(ctx, tx)
r.addCall(Call{
Name: "broadcast_tx_commit",
@@ -218,7 +218,7 @@ func (r *ABCIRecorder) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*cty
return res, err
}
func (r *ABCIRecorder) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (r *ABCIRecorder) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
res, err := r.Client.BroadcastTxAsync(ctx, tx)
r.addCall(Call{
Name: "broadcast_tx_async",
@@ -229,7 +229,7 @@ func (r *ABCIRecorder) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctyp
return res, err
}
func (r *ABCIRecorder) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (r *ABCIRecorder) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
res, err := r.Client.BroadcastTxSync(ctx, tx)
r.addCall(Call{
Name: "broadcast_tx_sync",
+3 -3
View File
@@ -14,7 +14,7 @@ import (
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/client/mock"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/types"
)
@@ -36,7 +36,7 @@ func TestABCIMock(t *testing.T) {
// Broadcast commit depends on call
BroadcastCommit: mock.Call{
Args: goodTx,
Response: &ctypes.ResultBroadcastTxCommit{
Response: &coretypes.ResultBroadcastTxCommit{
CheckTx: abci.ResponseCheckTx{Data: bytes.HexBytes("stand")},
DeliverTx: abci.ResponseDeliverTx{Data: bytes.HexBytes("deliver")},
},
@@ -112,7 +112,7 @@ func TestABCIRecorder(t *testing.T) {
assert.Nil(info.Error)
assert.Nil(info.Args)
require.NotNil(info.Response)
ir, ok := info.Response.(*ctypes.ResultABCIInfo)
ir, ok := info.Response.(*coretypes.ResultABCIInfo)
require.True(ok)
assert.Equal("data", ir.Response.Data)
assert.Equal("v0.9.9", ir.Response.Version)
+23 -23
View File
@@ -21,7 +21,7 @@ import (
"github.com/tendermint/tendermint/internal/rpc/core"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)
@@ -75,15 +75,15 @@ func (c Call) GetResponse(args interface{}) (interface{}, error) {
return nil, c.Error
}
func (c Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
func (c Client) Status(ctx context.Context) (*coretypes.ResultStatus, error) {
return c.env.Status(&rpctypes.Context{})
}
func (c Client) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
func (c Client) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
return c.env.ABCIInfo(&rpctypes.Context{})
}
func (c Client) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (c Client) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(ctx, path, data, client.DefaultABCIQueryOptions)
}
@@ -91,47 +91,47 @@ func (c Client) ABCIQueryWithOptions(
ctx context.Context,
path string,
data bytes.HexBytes,
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
opts client.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) {
return c.env.ABCIQuery(&rpctypes.Context{}, path, data, opts.Height, opts.Prove)
}
func (c Client) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
func (c Client) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
return c.env.BroadcastTxCommit(&rpctypes.Context{}, tx)
}
func (c Client) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (c Client) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.env.BroadcastTxAsync(&rpctypes.Context{}, tx)
}
func (c Client) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (c Client) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.env.BroadcastTxSync(&rpctypes.Context{}, tx)
}
func (c Client) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) {
func (c Client) CheckTx(ctx context.Context, tx types.Tx) (*coretypes.ResultCheckTx, error) {
return c.env.CheckTx(&rpctypes.Context{}, tx)
}
func (c Client) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error) {
func (c Client) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, error) {
return c.env.NetInfo(&rpctypes.Context{})
}
func (c Client) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error) {
func (c Client) ConsensusState(ctx context.Context) (*coretypes.ResultConsensusState, error) {
return c.env.GetConsensusState(&rpctypes.Context{})
}
func (c Client) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error) {
func (c Client) DumpConsensusState(ctx context.Context) (*coretypes.ResultDumpConsensusState, error) {
return c.env.DumpConsensusState(&rpctypes.Context{})
}
func (c Client) ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error) {
func (c Client) ConsensusParams(ctx context.Context, height *int64) (*coretypes.ResultConsensusParams, error) {
return c.env.ConsensusParams(&rpctypes.Context{}, height)
}
func (c Client) Health(ctx context.Context) (*ctypes.ResultHealth, error) {
func (c Client) Health(ctx context.Context) (*coretypes.ResultHealth, error) {
return c.env.Health(&rpctypes.Context{})
}
func (c Client) DialSeeds(ctx context.Context, seeds []string) (*ctypes.ResultDialSeeds, error) {
func (c Client) DialSeeds(ctx context.Context, seeds []string) (*coretypes.ResultDialSeeds, error) {
return c.env.UnsafeDialSeeds(&rpctypes.Context{}, seeds)
}
@@ -141,34 +141,34 @@ func (c Client) DialPeers(
persistent,
unconditional,
private bool,
) (*ctypes.ResultDialPeers, error) {
) (*coretypes.ResultDialPeers, error) {
return c.env.UnsafeDialPeers(&rpctypes.Context{}, peers, persistent, unconditional, private)
}
func (c Client) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
func (c Client) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) { //nolint:lll
return c.env.BlockchainInfo(&rpctypes.Context{}, minHeight, maxHeight)
}
func (c Client) Genesis(ctx context.Context) (*ctypes.ResultGenesis, error) {
func (c Client) Genesis(ctx context.Context) (*coretypes.ResultGenesis, error) {
return c.env.Genesis(&rpctypes.Context{})
}
func (c Client) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) {
func (c Client) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) {
return c.env.Block(&rpctypes.Context{}, height)
}
func (c Client) BlockByHash(ctx context.Context, hash bytes.HexBytes) (*ctypes.ResultBlock, error) {
func (c Client) BlockByHash(ctx context.Context, hash bytes.HexBytes) (*coretypes.ResultBlock, error) {
return c.env.BlockByHash(&rpctypes.Context{}, hash)
}
func (c Client) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
func (c Client) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) {
return c.env.Commit(&rpctypes.Context{}, height)
}
func (c Client) Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) {
func (c Client) Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) { //nolint:lll
return c.env.Validators(&rpctypes.Context{}, height, page, perPage)
}
func (c Client) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
func (c Client) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error) {
return c.env.BroadcastEvidence(&rpctypes.Context{}, ev)
}
+4 -4
View File
@@ -4,7 +4,7 @@ import (
"context"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
)
// StatusMock returns the result specified by the Call
@@ -17,12 +17,12 @@ var (
_ client.StatusClient = (*StatusRecorder)(nil)
)
func (m *StatusMock) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
func (m *StatusMock) Status(ctx context.Context) (*coretypes.ResultStatus, error) {
res, err := m.GetResponse(nil)
if err != nil {
return nil, err
}
return res.(*ctypes.ResultStatus), nil
return res.(*coretypes.ResultStatus), nil
}
// StatusRecorder can wrap another type (StatusMock, full client)
@@ -43,7 +43,7 @@ func (r *StatusRecorder) addCall(call Call) {
r.Calls = append(r.Calls, call)
}
func (r *StatusRecorder) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
func (r *StatusRecorder) Status(ctx context.Context) (*coretypes.ResultStatus, error) {
res, err := r.Client.Status(ctx)
r.addCall(Call{
Name: "status",
+4 -4
View File
@@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/rpc/client/mock"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
)
func TestStatus(t *testing.T) {
@@ -18,8 +18,8 @@ func TestStatus(t *testing.T) {
m := &mock.StatusMock{
Call: mock.Call{
Response: &ctypes.ResultStatus{
SyncInfo: ctypes.SyncInfo{
Response: &coretypes.ResultStatus{
SyncInfo: coretypes.SyncInfo{
LatestBlockHash: bytes.HexBytes("block"),
LatestAppHash: bytes.HexBytes("app"),
LatestBlockHeight: 10,
@@ -56,7 +56,7 @@ func TestStatus(t *testing.T) {
assert.Nil(rs.Args)
assert.Nil(rs.Error)
require.NotNil(rs.Response)
st, ok := rs.Response.(*ctypes.ResultStatus)
st, ok := rs.Response.(*coretypes.ResultStatus)
require.True(ok)
assert.EqualValues("block", st.SyncInfo.LatestBlockHash)
assert.EqualValues(10, st.SyncInfo.LatestBlockHeight)
+26 -26
View File
@@ -16,7 +16,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/config"
mempl "github.com/tendermint/tendermint/internal/mempool"
"github.com/tendermint/tendermint/internal/mempool"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmmath "github.com/tendermint/tendermint/libs/math"
@@ -24,7 +24,7 @@ import (
"github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
rpclocal "github.com/tendermint/tendermint/rpc/client/local"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/coretypes"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tendermint/tendermint/types"
)
@@ -425,8 +425,8 @@ func TestBroadcastTxSync(t *testing.T) {
defer cancel()
// TODO (melekes): use mempool which is set on RPC rather than getting it from node
mempool := getMempool(t, n)
initMempoolSize := mempool.Size()
pool := getMempool(t, n)
initMempoolSize := pool.Size()
for i, c := range GetClients(t, n, conf) {
_, _, tx := MakeTxKV()
@@ -434,18 +434,18 @@ func TestBroadcastTxSync(t *testing.T) {
require.Nil(t, err, "%d: %+v", i, err)
require.Equal(t, bres.Code, abci.CodeTypeOK) // FIXME
require.Equal(t, initMempoolSize+1, mempool.Size())
require.Equal(t, initMempoolSize+1, pool.Size())
txs := mempool.ReapMaxTxs(len(tx))
txs := pool.ReapMaxTxs(len(tx))
require.EqualValues(t, tx, txs[0])
mempool.Flush()
pool.Flush()
}
}
func getMempool(t *testing.T, srv service.Service) mempl.Mempool {
func getMempool(t *testing.T, srv service.Service) mempool.Mempool {
t.Helper()
n, ok := srv.(interface {
Mempool() mempl.Mempool
Mempool() mempool.Mempool
})
require.True(t, ok)
return n.Mempool()
@@ -457,7 +457,7 @@ func TestBroadcastTxCommit(t *testing.T) {
n, conf := NodeSuite(t)
mempool := getMempool(t, n)
pool := getMempool(t, n)
for i, c := range GetClients(t, n, conf) {
_, _, tx := MakeTxKV()
bres, err := c.BroadcastTxCommit(ctx, tx)
@@ -465,7 +465,7 @@ func TestBroadcastTxCommit(t *testing.T) {
require.True(t, bres.CheckTx.IsOK())
require.True(t, bres.DeliverTx.IsOK())
require.Equal(t, 0, mempool.Size())
require.Equal(t, 0, pool.Size())
}
}
@@ -477,8 +477,8 @@ func TestUnconfirmedTxs(t *testing.T) {
ch := make(chan *abci.Response, 1)
n, conf := NodeSuite(t)
mempool := getMempool(t, n)
err := mempool.CheckTx(ctx, tx, func(resp *abci.Response) { ch <- resp }, mempl.TxInfo{})
pool := getMempool(t, n)
err := pool.CheckTx(ctx, tx, func(resp *abci.Response) { ch <- resp }, mempool.TxInfo{})
require.NoError(t, err)
@@ -497,11 +497,11 @@ func TestUnconfirmedTxs(t *testing.T) {
assert.Equal(t, 1, res.Count)
assert.Equal(t, 1, res.Total)
assert.Equal(t, mempool.SizeBytes(), res.TotalBytes)
assert.Equal(t, pool.SizeBytes(), res.TotalBytes)
assert.Exactly(t, types.Txs{tx}, types.Txs(res.Txs))
}
mempool.Flush()
pool.Flush()
}
func TestNumUnconfirmedTxs(t *testing.T) {
@@ -512,9 +512,9 @@ func TestNumUnconfirmedTxs(t *testing.T) {
n, conf := NodeSuite(t)
ch := make(chan *abci.Response, 1)
mempool := getMempool(t, n)
pool := getMempool(t, n)
err := mempool.CheckTx(ctx, tx, func(resp *abci.Response) { ch <- resp }, mempl.TxInfo{})
err := pool.CheckTx(ctx, tx, func(resp *abci.Response) { ch <- resp }, mempool.TxInfo{})
require.NoError(t, err)
// wait for tx to arrive in mempoool.
@@ -524,7 +524,7 @@ func TestNumUnconfirmedTxs(t *testing.T) {
t.Error("Timed out waiting for CheckTx callback")
}
mempoolSize := mempool.Size()
mempoolSize := pool.Size()
for i, c := range GetClients(t, n, conf) {
mc, ok := c.(client.MempoolClient)
require.True(t, ok, "%d", i)
@@ -533,10 +533,10 @@ func TestNumUnconfirmedTxs(t *testing.T) {
assert.Equal(t, mempoolSize, res.Count)
assert.Equal(t, mempoolSize, res.Total)
assert.Equal(t, mempool.SizeBytes(), res.TotalBytes)
assert.Equal(t, pool.SizeBytes(), res.TotalBytes)
}
mempool.Flush()
pool.Flush()
}
func TestCheckTx(t *testing.T) {
@@ -544,7 +544,7 @@ func TestCheckTx(t *testing.T) {
defer cancel()
n, conf := NodeSuite(t)
mempool := getMempool(t, n)
pool := getMempool(t, n)
for _, c := range GetClients(t, n, conf) {
_, _, tx := MakeTxKV()
@@ -553,7 +553,7 @@ func TestCheckTx(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, abci.CodeTypeOK, res.Code)
assert.Equal(t, 0, mempool.Size(), "mempool must be empty")
assert.Equal(t, 0, pool.Size(), "mempool must be empty")
}
}
@@ -781,10 +781,10 @@ func testBatchedJSONRPCCalls(ctx context.Context, t *testing.T, c *rpchttp.HTTP)
require.Len(t, bresults, 2)
require.Equal(t, 0, batch.Count())
bresult1, ok := bresults[0].(*ctypes.ResultBroadcastTxCommit)
bresult1, ok := bresults[0].(*coretypes.ResultBroadcastTxCommit)
require.True(t, ok)
require.Equal(t, *bresult1, *r1)
bresult2, ok := bresults[1].(*ctypes.ResultBroadcastTxCommit)
bresult2, ok := bresults[1].(*coretypes.ResultBroadcastTxCommit)
require.True(t, ok)
require.Equal(t, *bresult2, *r2)
apph := tmmath.MaxInt64(bresult1.Height, bresult2.Height) + 1
@@ -802,10 +802,10 @@ func testBatchedJSONRPCCalls(ctx context.Context, t *testing.T, c *rpchttp.HTTP)
require.Len(t, qresults, 2)
require.Equal(t, 0, batch.Count())
qresult1, ok := qresults[0].(*ctypes.ResultABCIQuery)
qresult1, ok := qresults[0].(*coretypes.ResultABCIQuery)
require.True(t, ok)
require.Equal(t, *qresult1, *q1)
qresult2, ok := qresults[1].(*ctypes.ResultABCIQuery)
qresult2, ok := qresults[1].(*coretypes.ResultABCIQuery)
require.True(t, ok)
require.Equal(t, *qresult2, *q2)
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
abci "github.com/tendermint/tendermint/abci/types"
core "github.com/tendermint/tendermint/internal/rpc/core"
"github.com/tendermint/tendermint/internal/rpc/core"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/tendermint/tendermint/abci/example/kvstore"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/service"
core_grpc "github.com/tendermint/tendermint/rpc/grpc"
coregrpc "github.com/tendermint/tendermint/rpc/grpc"
rpctest "github.com/tendermint/tendermint/rpc/test"
)
@@ -37,7 +37,7 @@ func TestBroadcastTx(t *testing.T) {
res, err := rpctest.GetGRPCClient(conf).BroadcastTx(
context.Background(),
&core_grpc.RequestBroadcastTx{Tx: []byte("this is a tx")},
&coregrpc.RequestBroadcastTx{Tx: []byte("this is a tx")},
)
require.NoError(t, err)
require.EqualValues(t, 0, res.CheckTx.Code)
+12 -12
View File
@@ -6,18 +6,18 @@ import (
"fmt"
tmjson "github.com/tendermint/tendermint/libs/json"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
func unmarshalResponseBytes(
responseBytes []byte,
expectedID types.JSONRPCIntID,
expectedID rpctypes.JSONRPCIntID,
result interface{},
) (interface{}, error) {
// Read response. If rpc/core/types is imported, the result will unmarshal
// into the correct type.
response := &types.RPCResponse{}
response := &rpctypes.RPCResponse{}
if err := json.Unmarshal(responseBytes, response); err != nil {
return nil, fmt.Errorf("error unmarshaling: %w", err)
}
@@ -40,12 +40,12 @@ func unmarshalResponseBytes(
func unmarshalResponseBytesArray(
responseBytes []byte,
expectedIDs []types.JSONRPCIntID,
expectedIDs []rpctypes.JSONRPCIntID,
results []interface{},
) ([]interface{}, error) {
var (
responses []types.RPCResponse
responses []rpctypes.RPCResponse
)
if err := json.Unmarshal(responseBytes, &responses); err != nil {
@@ -64,10 +64,10 @@ func unmarshalResponseBytesArray(
}
// Intersect IDs from responses with expectedIDs.
ids := make([]types.JSONRPCIntID, len(responses))
ids := make([]rpctypes.JSONRPCIntID, len(responses))
var ok bool
for i, resp := range responses {
ids[i], ok = resp.ID.(types.JSONRPCIntID)
ids[i], ok = resp.ID.(rpctypes.JSONRPCIntID)
if !ok {
return nil, fmt.Errorf("expected JSONRPCIntID, got %T", resp.ID)
}
@@ -85,8 +85,8 @@ func unmarshalResponseBytesArray(
return results, nil
}
func validateResponseIDs(ids, expectedIDs []types.JSONRPCIntID) error {
m := make(map[types.JSONRPCIntID]bool, len(expectedIDs))
func validateResponseIDs(ids, expectedIDs []rpctypes.JSONRPCIntID) error {
m := make(map[rpctypes.JSONRPCIntID]bool, len(expectedIDs))
for _, expectedID := range expectedIDs {
m[expectedID] = true
}
@@ -104,11 +104,11 @@ func validateResponseIDs(ids, expectedIDs []types.JSONRPCIntID) error {
// From the JSON-RPC 2.0 spec:
// id: It MUST be the same as the value of the id member in the Request Object.
func validateAndVerifyID(res *types.RPCResponse, expectedID types.JSONRPCIntID) error {
func validateAndVerifyID(res *rpctypes.RPCResponse, expectedID rpctypes.JSONRPCIntID) error {
if err := validateResponseID(res.ID); err != nil {
return err
}
if expectedID != res.ID.(types.JSONRPCIntID) { // validateResponseID ensured res.ID has the right type
if expectedID != res.ID.(rpctypes.JSONRPCIntID) { // validateResponseID ensured res.ID has the right type
return fmt.Errorf("response ID (%d) does not match request ID (%d)", res.ID, expectedID)
}
return nil
@@ -118,7 +118,7 @@ func validateResponseID(id interface{}) error {
if id == nil {
return errors.New("no ID")
}
_, ok := id.(types.JSONRPCIntID)
_, ok := id.(rpctypes.JSONRPCIntID)
if !ok {
return fmt.Errorf("expected JSONRPCIntID, but got: %T", id)
}
+9 -9
View File
@@ -13,7 +13,7 @@ import (
"time"
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
const (
@@ -189,7 +189,7 @@ func (c *Client) Call(
) (interface{}, error) {
id := c.nextRequestID()
request, err := types.MapToRequest(id, method, params)
request, err := rpctypes.MapToRequest(id, method, params)
if err != nil {
return nil, fmt.Errorf("failed to encode params: %w", err)
}
@@ -235,7 +235,7 @@ func (c *Client) NewRequestBatch() *RequestBatch {
}
func (c *Client) sendBatch(ctx context.Context, requests []*jsonRPCBufferedRequest) ([]interface{}, error) {
reqs := make([]types.RPCRequest, 0, len(requests))
reqs := make([]rpctypes.RPCRequest, 0, len(requests))
results := make([]interface{}, 0, len(requests))
for _, req := range requests {
reqs = append(reqs, req.request)
@@ -272,20 +272,20 @@ func (c *Client) sendBatch(ctx context.Context, requests []*jsonRPCBufferedReque
}
// collect ids to check responses IDs in unmarshalResponseBytesArray
ids := make([]types.JSONRPCIntID, len(requests))
ids := make([]rpctypes.JSONRPCIntID, len(requests))
for i, req := range requests {
ids[i] = req.request.ID.(types.JSONRPCIntID)
ids[i] = req.request.ID.(rpctypes.JSONRPCIntID)
}
return unmarshalResponseBytesArray(responseBytes, ids, results)
}
func (c *Client) nextRequestID() types.JSONRPCIntID {
func (c *Client) nextRequestID() rpctypes.JSONRPCIntID {
c.mtx.Lock()
id := c.nextReqID
c.nextReqID++
c.mtx.Unlock()
return types.JSONRPCIntID(id)
return rpctypes.JSONRPCIntID(id)
}
//------------------------------------------------------------------------------------
@@ -293,7 +293,7 @@ func (c *Client) nextRequestID() types.JSONRPCIntID {
// jsonRPCBufferedRequest encapsulates a single buffered request, as well as its
// anticipated response structure.
type jsonRPCBufferedRequest struct {
request types.RPCRequest
request rpctypes.RPCRequest
result interface{} // The result will be deserialized into this object.
}
@@ -354,7 +354,7 @@ func (b *RequestBatch) Call(
result interface{},
) (interface{}, error) {
id := b.client.nextRequestID()
request, err := types.MapToRequest(id, method, params)
request, err := rpctypes.MapToRequest(id, method, params)
if err != nil {
return nil, err
}
+2 -2
View File
@@ -7,12 +7,12 @@ import (
"net/http"
"strings"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
const (
// URIClientRequestID in a request ID used by URIClient
URIClientRequestID = types.JSONRPCIntID(-1)
URIClientRequestID = rpctypes.JSONRPCIntID(-1)
)
// URIClient is a JSON-RPC client, which sends POST form HTTP requests to the
+15 -15
View File
@@ -15,7 +15,7 @@ import (
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
tmclient "github.com/tendermint/tendermint/rpc/client"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// WSOptions for WSClient.
@@ -50,16 +50,16 @@ type WSClient struct { // nolint: maligned
// Single user facing channel to read RPCResponses from, closed only when the
// client is being stopped.
ResponsesCh chan types.RPCResponse
ResponsesCh chan rpctypes.RPCResponse
// Callback, which will be called each time after successful reconnect.
onReconnect func()
// internal channels
send chan types.RPCRequest // user requests
backlog chan types.RPCRequest // stores a single user request received during a conn failure
reconnectAfter chan error // reconnect requests
readRoutineQuit chan struct{} // a way for readRoutine to close writeRoutine
send chan rpctypes.RPCRequest // user requests
backlog chan rpctypes.RPCRequest // stores a single user request received during a conn failure
reconnectAfter chan error // reconnect requests
readRoutineQuit chan struct{} // a way for readRoutine to close writeRoutine
// Maximum reconnect attempts (0 or greater; default: 25).
maxReconnectAttempts uint
@@ -152,15 +152,15 @@ func (c *WSClient) Start() error {
return err
}
c.ResponsesCh = make(chan types.RPCResponse)
c.ResponsesCh = make(chan rpctypes.RPCResponse)
c.send = make(chan types.RPCRequest)
c.send = make(chan rpctypes.RPCRequest)
// 1 additional error may come from the read/write
// goroutine depending on which failed first.
c.reconnectAfter = make(chan error, 1)
// capacity for 1 request. a user won't be able to send more because the send
// channel is unbuffered.
c.backlog = make(chan types.RPCRequest, 1)
c.backlog = make(chan rpctypes.RPCRequest, 1)
c.startReadWriteRoutines()
go c.reconnectRoutine()
@@ -195,7 +195,7 @@ func (c *WSClient) IsActive() bool {
// Send the given RPC request to the server. Results will be available on
// ResponsesCh, errors, if any, on ErrorsCh. Will block until send succeeds or
// ctx.Done is closed.
func (c *WSClient) Send(ctx context.Context, request types.RPCRequest) error {
func (c *WSClient) Send(ctx context.Context, request rpctypes.RPCRequest) error {
select {
case c.send <- request:
c.Logger.Info("sent a request", "req", request)
@@ -210,7 +210,7 @@ func (c *WSClient) Send(ctx context.Context, request types.RPCRequest) error {
// Call enqueues a call request onto the Send queue. Requests are JSON encoded.
func (c *WSClient) Call(ctx context.Context, method string, params map[string]interface{}) error {
request, err := types.MapToRequest(c.nextRequestID(), method, params)
request, err := rpctypes.MapToRequest(c.nextRequestID(), method, params)
if err != nil {
return err
}
@@ -220,7 +220,7 @@ func (c *WSClient) Call(ctx context.Context, method string, params map[string]in
// CallWithArrayParams enqueues a call request onto the Send queue. Params are
// in a form of array (e.g. []interface{}{"abcd"}). Requests are JSON encoded.
func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error {
request, err := types.ArrayToRequest(c.nextRequestID(), method, params)
request, err := rpctypes.ArrayToRequest(c.nextRequestID(), method, params)
if err != nil {
return err
}
@@ -229,12 +229,12 @@ func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, param
// Private methods
func (c *WSClient) nextRequestID() types.JSONRPCIntID {
func (c *WSClient) nextRequestID() rpctypes.JSONRPCIntID {
c.mtx.Lock()
id := c.nextReqID
c.nextReqID++
c.mtx.Unlock()
return types.JSONRPCIntID(id)
return rpctypes.JSONRPCIntID(id)
}
func (c *WSClient) dial() error {
@@ -462,7 +462,7 @@ func (c *WSClient) readRoutine() {
return
}
var response types.RPCResponse
var response rpctypes.RPCResponse
err = json.Unmarshal(data, &response)
if err != nil {
c.Logger.Error("failed to parse response", "err", err, "data", string(data))
+3 -3
View File
@@ -14,7 +14,7 @@ import (
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
"github.com/tendermint/tendermint/libs/log"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
var wsCallTimeout = 5 * time.Second
@@ -41,7 +41,7 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
var req types.RPCRequest
var req rpctypes.RPCRequest
err = json.Unmarshal(in, &req)
if err != nil {
panic(err)
@@ -56,7 +56,7 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.mtx.RUnlock()
res := json.RawMessage(`{}`)
emptyRespBytes, _ := json.Marshal(types.RPCResponse{Result: res, ID: req.ID})
emptyRespBytes, _ := json.Marshal(rpctypes.RPCResponse{Result: res, ID: req.ID})
if err := conn.WriteMessage(messageType, emptyRespBytes); err != nil {
return
}
+8 -8
View File
@@ -18,9 +18,9 @@ import (
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
client "github.com/tendermint/tendermint/rpc/jsonrpc/client"
server "github.com/tendermint/tendermint/rpc/jsonrpc/server"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tendermint/tendermint/rpc/jsonrpc/server"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// Client and Server should work over tcp or unix sockets
@@ -64,23 +64,23 @@ var Routes = map[string]*server.RPCFunc{
"echo_int": server.NewRPCFunc(EchoIntResult, "arg", false),
}
func EchoResult(ctx *types.Context, v string) (*ResultEcho, error) {
func EchoResult(ctx *rpctypes.Context, v string) (*ResultEcho, error) {
return &ResultEcho{v}, nil
}
func EchoWSResult(ctx *types.Context, v string) (*ResultEcho, error) {
func EchoWSResult(ctx *rpctypes.Context, v string) (*ResultEcho, error) {
return &ResultEcho{v}, nil
}
func EchoIntResult(ctx *types.Context, v int) (*ResultEchoInt, error) {
func EchoIntResult(ctx *rpctypes.Context, v int) (*ResultEchoInt, error) {
return &ResultEchoInt{v}, nil
}
func EchoBytesResult(ctx *types.Context, v []byte) (*ResultEchoBytes, error) {
func EchoBytesResult(ctx *rpctypes.Context, v []byte) (*ResultEchoBytes, error) {
return &ResultEchoBytes{v}, nil
}
func EchoDataBytesResult(ctx *types.Context, v tmbytes.HexBytes) (*ResultEchoDataBytes, error) {
func EchoDataBytesResult(ctx *rpctypes.Context, v tmbytes.HexBytes) (*ResultEchoDataBytes, error) {
return &ResultEchoDataBytes{v}, nil
}
+20 -20
View File
@@ -12,8 +12,8 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
"github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// HTTP + JSON handler
@@ -23,7 +23,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
return func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
res := types.RPCInvalidRequestError(nil,
res := rpctypes.RPCInvalidRequestError(nil,
fmt.Errorf("error reading request body: %w", err),
)
if wErr := WriteRPCResponseHTTPError(w, res); wErr != nil {
@@ -41,20 +41,20 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
// first try to unmarshal the incoming request as an array of RPC requests
var (
requests []types.RPCRequest
responses []types.RPCResponse
requests []rpctypes.RPCRequest
responses []rpctypes.RPCResponse
)
if err := json.Unmarshal(b, &requests); err != nil {
// next, try to unmarshal as a single request
var request types.RPCRequest
var request rpctypes.RPCRequest
if err := json.Unmarshal(b, &request); err != nil {
res := types.RPCParseError(fmt.Errorf("error unmarshaling request: %w", err))
res := rpctypes.RPCParseError(fmt.Errorf("error unmarshaling request: %w", err))
if wErr := WriteRPCResponseHTTPError(w, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
}
return
}
requests = []types.RPCRequest{request}
requests = []rpctypes.RPCRequest{request}
}
// Set the default response cache to true unless
@@ -77,25 +77,25 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
if len(r.URL.Path) > 1 {
responses = append(
responses,
types.RPCInvalidRequestError(request.ID, fmt.Errorf("path %s is invalid", r.URL.Path)),
rpctypes.RPCInvalidRequestError(request.ID, fmt.Errorf("path %s is invalid", r.URL.Path)),
)
c = false
continue
}
rpcFunc, ok := funcMap[request.Method]
if !ok || rpcFunc.ws {
responses = append(responses, types.RPCMethodNotFoundError(request.ID))
responses = append(responses, rpctypes.RPCMethodNotFoundError(request.ID))
c = false
continue
}
ctx := &types.Context{JSONReq: &request, HTTPReq: r}
ctx := &rpctypes.Context{JSONReq: &request, HTTPReq: r}
args := []reflect.Value{reflect.ValueOf(ctx)}
if len(request.Params) > 0 {
fnArgs, err := jsonParamsToArgs(rpcFunc, request.Params)
if err != nil {
responses = append(
responses,
types.RPCInvalidParamsError(request.ID, fmt.Errorf("error converting json params to arguments: %w", err)),
rpctypes.RPCInvalidParamsError(request.ID, fmt.Errorf("error converting json params to arguments: %w", err)),
)
c = false
continue
@@ -114,22 +114,22 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
switch e := err.(type) {
// if no error then return a success response
case nil:
responses = append(responses, types.NewRPCSuccessResponse(request.ID, result))
responses = append(responses, rpctypes.NewRPCSuccessResponse(request.ID, result))
// if this already of type RPC error then forward that error
case *types.RPCError:
responses = append(responses, types.NewRPCErrorResponse(request.ID, e.Code, e.Message, e.Data))
case *rpctypes.RPCError:
responses = append(responses, rpctypes.NewRPCErrorResponse(request.ID, e.Code, e.Message, e.Data))
c = false
default: // we need to unwrap the error and parse it accordingly
switch errors.Unwrap(err) {
// check if the error was due to an invald request
case ctypes.ErrZeroOrNegativeHeight, ctypes.ErrZeroOrNegativePerPage,
ctypes.ErrPageOutOfRange, ctypes.ErrInvalidRequest:
responses = append(responses, types.RPCInvalidRequestError(request.ID, err))
case coretypes.ErrZeroOrNegativeHeight, coretypes.ErrZeroOrNegativePerPage,
coretypes.ErrPageOutOfRange, coretypes.ErrInvalidRequest:
responses = append(responses, rpctypes.RPCInvalidRequestError(request.ID, err))
c = false
// lastly default all remaining errors as internal errors
default: // includes ctypes.ErrHeightNotAvailable and ctypes.ErrHeightExceedsChainHead
responses = append(responses, types.RPCInternalError(request.ID, err))
responses = append(responses, rpctypes.RPCInternalError(request.ID, err))
c = false
}
}
@@ -277,7 +277,7 @@ func writeListOfEndpoints(w http.ResponseWriter, r *http.Request, funcMap map[st
w.Write(buf.Bytes()) // nolint: errcheck
}
func hasDefaultHeight(r types.RPCRequest, h []reflect.Value) bool {
func hasDefaultHeight(r rpctypes.RPCRequest, h []reflect.Value) bool {
switch r.Method {
case "block", "block_results", "commit", "consensus_params", "validators":
return len(h) < 2 || h[1].IsZero()
+25 -25
View File
@@ -12,13 +12,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
func testMux() *http.ServeMux {
funcMap := map[string]*RPCFunc{
"c": NewRPCFunc(func(ctx *types.Context, s string, i int) (string, error) { return "foo", nil }, "s,i", false),
"block": NewRPCFunc(func(ctx *types.Context, h int) (string, error) { return "block", nil }, "height", true),
"c": NewRPCFunc(func(ctx *rpctypes.Context, s string, i int) (string, error) { return "foo", nil }, "s,i", false),
"block": NewRPCFunc(func(ctx *rpctypes.Context, h int) (string, error) { return "block", nil }, "height", true),
}
mux := http.NewServeMux()
logger := log.NewNopLogger()
@@ -40,21 +40,21 @@ func TestRPCParams(t *testing.T) {
expectedID interface{}
}{
// bad
{`{"jsonrpc": "2.0", "id": "0"}`, "Method not found", types.JSONRPCStringID("0")},
{`{"jsonrpc": "2.0", "method": "y", "id": "0"}`, "Method not found", types.JSONRPCStringID("0")},
{`{"jsonrpc": "2.0", "id": "0"}`, "Method not found", rpctypes.JSONRPCStringID("0")},
{`{"jsonrpc": "2.0", "method": "y", "id": "0"}`, "Method not found", rpctypes.JSONRPCStringID("0")},
// id not captured in JSON parsing failures
{`{"method": "c", "id": "0", "params": a}`, "invalid character", nil},
{`{"method": "c", "id": "0", "params": ["a"]}`, "got 1", types.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": ["a", "b"]}`, "invalid character", types.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": [1, 1]}`, "of type string", types.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": ["a"]}`, "got 1", rpctypes.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": ["a", "b"]}`, "invalid character", rpctypes.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": [1, 1]}`, "of type string", rpctypes.JSONRPCStringID("0")},
// no ID - notification
// {`{"jsonrpc": "2.0", "method": "c", "params": ["a", "10"]}`, false, nil},
// good
{`{"jsonrpc": "2.0", "method": "c", "id": "0", "params": null}`, "", types.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": {}}`, "", types.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": ["a", "10"]}`, "", types.JSONRPCStringID("0")},
{`{"jsonrpc": "2.0", "method": "c", "id": "0", "params": null}`, "", rpctypes.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": {}}`, "", rpctypes.JSONRPCStringID("0")},
{`{"method": "c", "id": "0", "params": ["a", "10"]}`, "", rpctypes.JSONRPCStringID("0")},
}
for i, tt := range tests {
@@ -71,9 +71,9 @@ func TestRPCParams(t *testing.T) {
continue
}
recv := new(types.RPCResponse)
recv := new(rpctypes.RPCResponse)
assert.Nil(t, json.Unmarshal(blob, recv), "#%d: expecting successful parsing of an RPCResponse:\nblob: %s", i, blob)
assert.NotEqual(t, recv, new(types.RPCResponse), "#%d: not expecting a blank RPCResponse", i)
assert.NotEqual(t, recv, new(rpctypes.RPCResponse), "#%d: not expecting a blank RPCResponse", i)
assert.Equal(t, tt.expectedID, recv.ID, "#%d: expected ID not matched in RPCResponse", i)
if tt.wantErr == "" {
assert.Nil(t, recv.Error, "#%d: not expecting an error", i)
@@ -93,12 +93,12 @@ func TestJSONRPCID(t *testing.T) {
expectedID interface{}
}{
// good id
{`{"jsonrpc": "2.0", "method": "c", "id": "0", "params": ["a", "10"]}`, false, types.JSONRPCStringID("0")},
{`{"jsonrpc": "2.0", "method": "c", "id": "abc", "params": ["a", "10"]}`, false, types.JSONRPCStringID("abc")},
{`{"jsonrpc": "2.0", "method": "c", "id": 0, "params": ["a", "10"]}`, false, types.JSONRPCIntID(0)},
{`{"jsonrpc": "2.0", "method": "c", "id": 1, "params": ["a", "10"]}`, false, types.JSONRPCIntID(1)},
{`{"jsonrpc": "2.0", "method": "c", "id": 1.3, "params": ["a", "10"]}`, false, types.JSONRPCIntID(1)},
{`{"jsonrpc": "2.0", "method": "c", "id": -1, "params": ["a", "10"]}`, false, types.JSONRPCIntID(-1)},
{`{"jsonrpc": "2.0", "method": "c", "id": "0", "params": ["a", "10"]}`, false, rpctypes.JSONRPCStringID("0")},
{`{"jsonrpc": "2.0", "method": "c", "id": "abc", "params": ["a", "10"]}`, false, rpctypes.JSONRPCStringID("abc")},
{`{"jsonrpc": "2.0", "method": "c", "id": 0, "params": ["a", "10"]}`, false, rpctypes.JSONRPCIntID(0)},
{`{"jsonrpc": "2.0", "method": "c", "id": 1, "params": ["a", "10"]}`, false, rpctypes.JSONRPCIntID(1)},
{`{"jsonrpc": "2.0", "method": "c", "id": 1.3, "params": ["a", "10"]}`, false, rpctypes.JSONRPCIntID(1)},
{`{"jsonrpc": "2.0", "method": "c", "id": -1, "params": ["a", "10"]}`, false, rpctypes.JSONRPCIntID(-1)},
// bad id
{`{"jsonrpc": "2.0", "method": "c", "id": {}, "params": ["a", "10"]}`, true, nil},
@@ -119,11 +119,11 @@ func TestJSONRPCID(t *testing.T) {
}
res.Body.Close()
recv := new(types.RPCResponse)
recv := new(rpctypes.RPCResponse)
err = json.Unmarshal(blob, recv)
assert.Nil(t, err, "#%d: expecting successful parsing of an RPCResponse:\nblob: %s", i, blob)
if !tt.wantErr {
assert.NotEqual(t, recv, new(types.RPCResponse), "#%d: not expecting a blank RPCResponse", i)
assert.NotEqual(t, recv, new(rpctypes.RPCResponse), "#%d: not expecting a blank RPCResponse", i)
assert.Equal(t, tt.expectedID, recv.ID, "#%d: expected ID not matched in RPCResponse", i)
assert.Nil(t, recv.Error, "#%d: not expecting an error", i)
} else {
@@ -185,7 +185,7 @@ func TestRPCNotificationInBatch(t *testing.T) {
}
res.Body.Close()
var responses []types.RPCResponse
var responses []rpctypes.RPCResponse
// try to unmarshal an array first
err = json.Unmarshal(blob, &responses)
if err != nil {
@@ -195,14 +195,14 @@ func TestRPCNotificationInBatch(t *testing.T) {
continue
} else {
// we were expecting an error here, so let's unmarshal a single response
var response types.RPCResponse
var response rpctypes.RPCResponse
err = json.Unmarshal(blob, &response)
if err != nil {
t.Errorf("#%d: expected successful parsing of an RPCResponse\nblob: %s", i, blob)
continue
}
// have a single-element result
responses = []types.RPCResponse{response}
responses = []rpctypes.RPCResponse{response}
}
}
if tt.expectCount != len(responses) {
@@ -210,7 +210,7 @@ func TestRPCNotificationInBatch(t *testing.T) {
continue
}
for _, response := range responses {
assert.NotEqual(t, response, new(types.RPCResponse), "#%d: not expecting a blank RPCResponse", i)
assert.NotEqual(t, response, new(rpctypes.RPCResponse), "#%d: not expecting a blank RPCResponse", i)
}
}
}
+5 -5
View File
@@ -16,7 +16,7 @@ import (
"golang.org/x/net/netutil"
"github.com/tendermint/tendermint/libs/log"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// Config is a RPC server configuration.
@@ -105,7 +105,7 @@ func ServeTLS(
// source: https://www.jsonrpc.org/historical/json-rpc-over-http.html
func WriteRPCResponseHTTPError(
w http.ResponseWriter,
res types.RPCResponse,
res rpctypes.RPCResponse,
) error {
if res.Error == nil {
panic("tried to write http error response without RPC error")
@@ -134,7 +134,7 @@ func WriteRPCResponseHTTPError(
// WriteRPCResponseHTTP marshals res as JSON (with indent) and writes it to w.
// If the rpc response can be cached, add cache-control to the response header.
func WriteRPCResponseHTTP(w http.ResponseWriter, c bool, res ...types.RPCResponse) error {
func WriteRPCResponseHTTP(w http.ResponseWriter, c bool, res ...rpctypes.RPCResponse) error {
var v interface{}
if len(res) == 1 {
v = res[0]
@@ -189,7 +189,7 @@ func RecoverAndLogHandler(handler http.Handler, logger log.Logger) http.Handler
if e := recover(); e != nil {
// If RPCResponse
if res, ok := e.(types.RPCResponse); ok {
if res, ok := e.(rpctypes.RPCResponse); ok {
if wErr := WriteRPCResponseHTTP(rww, false, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
}
@@ -208,7 +208,7 @@ func RecoverAndLogHandler(handler http.Handler, logger log.Logger) http.Handler
logger.Error("panic in RPC HTTP handler", "err", e, "stack", string(debug.Stack()))
res := types.RPCInternalError(types.JSONRPCIntID(-1), err)
res := rpctypes.RPCInternalError(rpctypes.JSONRPCIntID(-1), err)
if wErr := WriteRPCResponseHTTPError(rww, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
}
+6 -6
View File
@@ -17,7 +17,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
type sampleResult struct {
@@ -107,11 +107,11 @@ func TestServeTLS(t *testing.T) {
}
func TestWriteRPCResponseHTTP(t *testing.T) {
id := types.JSONRPCIntID(-1)
id := rpctypes.JSONRPCIntID(-1)
// one argument
w := httptest.NewRecorder()
err := WriteRPCResponseHTTP(w, true, types.NewRPCSuccessResponse(id, &sampleResult{"hello"}))
err := WriteRPCResponseHTTP(w, true, rpctypes.NewRPCSuccessResponse(id, &sampleResult{"hello"}))
require.NoError(t, err)
resp := w.Result()
body, err := ioutil.ReadAll(resp.Body)
@@ -132,8 +132,8 @@ func TestWriteRPCResponseHTTP(t *testing.T) {
w = httptest.NewRecorder()
err = WriteRPCResponseHTTP(w,
false,
types.NewRPCSuccessResponse(id, &sampleResult{"hello"}),
types.NewRPCSuccessResponse(id, &sampleResult{"world"}))
rpctypes.NewRPCSuccessResponse(id, &sampleResult{"hello"}),
rpctypes.NewRPCSuccessResponse(id, &sampleResult{"world"}))
require.NoError(t, err)
resp = w.Result()
body, err = ioutil.ReadAll(resp.Body)
@@ -162,7 +162,7 @@ func TestWriteRPCResponseHTTP(t *testing.T) {
func TestWriteRPCResponseHTTPError(t *testing.T) {
w := httptest.NewRecorder()
err := WriteRPCResponseHTTPError(w, types.RPCInternalError(types.JSONRPCIntID(-1), errors.New("foo")))
err := WriteRPCResponseHTTPError(w, rpctypes.RPCInternalError(rpctypes.JSONRPCIntID(-1), errors.New("foo")))
require.NoError(t, err)
resp := w.Result()
body, err := ioutil.ReadAll(resp.Body)
+16 -16
View File
@@ -11,8 +11,8 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// HTTP + URI handler
@@ -22,12 +22,12 @@ var reInt = regexp.MustCompile(`^-?[0-9]+$`)
// convert from a function name to the http handler
func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWriter, *http.Request) {
// Always return -1 as there's no ID here.
dummyID := types.JSONRPCIntID(-1) // URIClientRequestID
dummyID := rpctypes.JSONRPCIntID(-1) // URIClientRequestID
// Exception for websocket endpoints
if rpcFunc.ws {
return func(w http.ResponseWriter, r *http.Request) {
res := types.RPCMethodNotFoundError(dummyID)
res := rpctypes.RPCMethodNotFoundError(dummyID)
if wErr := WriteRPCResponseHTTPError(w, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
}
@@ -38,12 +38,12 @@ func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWrit
return func(w http.ResponseWriter, r *http.Request) {
logger.Debug("HTTP HANDLER", "req", r)
ctx := &types.Context{HTTPReq: r}
ctx := &rpctypes.Context{HTTPReq: r}
args := []reflect.Value{reflect.ValueOf(ctx)}
fnArgs, err := httpParamsToArgs(rpcFunc, r)
if err != nil {
res := types.RPCInvalidParamsError(dummyID,
res := rpctypes.RPCInvalidParamsError(dummyID,
fmt.Errorf("error converting http params to arguments: %w", err),
)
if wErr := WriteRPCResponseHTTPError(w, res); wErr != nil {
@@ -60,29 +60,29 @@ func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWrit
switch e := err.(type) {
// if no error then return a success response
case nil:
res := types.NewRPCSuccessResponse(dummyID, result)
res := rpctypes.NewRPCSuccessResponse(dummyID, result)
if wErr := WriteRPCResponseHTTP(w, rpcFunc.cache, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
}
// if this already of type RPC error then forward that error.
case *types.RPCError:
res := types.NewRPCErrorResponse(dummyID, e.Code, e.Message, e.Data)
case *rpctypes.RPCError:
res := rpctypes.NewRPCErrorResponse(dummyID, e.Code, e.Message, e.Data)
if wErr := WriteRPCResponseHTTPError(w, res); wErr != nil {
logger.Error("failed to write response", "res", res, "err", wErr)
}
default: // we need to unwrap the error and parse it accordingly
var res types.RPCResponse
var res rpctypes.RPCResponse
switch errors.Unwrap(err) {
case ctypes.ErrZeroOrNegativeHeight,
ctypes.ErrZeroOrNegativePerPage,
ctypes.ErrPageOutOfRange,
ctypes.ErrInvalidRequest:
res = types.RPCInvalidRequestError(dummyID, err)
case coretypes.ErrZeroOrNegativeHeight,
coretypes.ErrZeroOrNegativePerPage,
coretypes.ErrPageOutOfRange,
coretypes.ErrInvalidRequest:
res = rpctypes.RPCInvalidRequestError(dummyID, err)
default: // ctypes.ErrHeightNotAvailable, ctypes.ErrHeightExceedsChainHead:
res = types.RPCInternalError(dummyID, err)
res = rpctypes.RPCInternalError(dummyID, err)
}
if wErr := WriteRPCResponseHTTPError(w, res); wErr != nil {
+3 -3
View File
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/libs/bytes"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
func TestParseJSONMap(t *testing.T) {
@@ -134,7 +134,7 @@ func TestParseJSONArray(t *testing.T) {
}
func TestParseJSONRPC(t *testing.T) {
demo := func(ctx *types.Context, height int, name string) {}
demo := func(ctx *rpctypes.Context, height int, name string) {}
call := NewRPCFunc(demo, "height,name", false)
cases := []struct {
@@ -171,7 +171,7 @@ func TestParseJSONRPC(t *testing.T) {
}
func TestParseURI(t *testing.T) {
demo := func(ctx *types.Context, height int, name string) {}
demo := func(ctx *rpctypes.Context, height int, name string) {}
call := NewRPCFunc(demo, "height,name", false)
cases := []struct {
+20 -20
View File
@@ -14,8 +14,8 @@ import (
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// WebSocket handler
@@ -111,7 +111,7 @@ type wsConnection struct {
remoteAddr string
baseConn *websocket.Conn
// writeChan is never closed, to allow WriteRPCResponse() to fail.
writeChan chan types.RPCResponse
writeChan chan rpctypes.RPCResponse
// chan, which is closed when/if readRoutine errors
// used to abort writeRoutine
@@ -224,7 +224,7 @@ func (wsc *wsConnection) Start() error {
if err := wsc.RunState.Start(); err != nil {
return err
}
wsc.writeChan = make(chan types.RPCResponse, wsc.writeChanCapacity)
wsc.writeChan = make(chan rpctypes.RPCResponse, wsc.writeChanCapacity)
// Read subscriptions/unsubscriptions to events
go wsc.readRoutine()
@@ -257,7 +257,7 @@ func (wsc *wsConnection) GetRemoteAddr() string {
// WriteRPCResponse pushes a response to the writeChan, and blocks until it is
// accepted.
// It implements WSRPCConnection. It is Goroutine-safe.
func (wsc *wsConnection) WriteRPCResponse(ctx context.Context, resp types.RPCResponse) error {
func (wsc *wsConnection) WriteRPCResponse(ctx context.Context, resp rpctypes.RPCResponse) error {
select {
case <-wsc.Quit():
return errors.New("connection was stopped")
@@ -271,7 +271,7 @@ func (wsc *wsConnection) WriteRPCResponse(ctx context.Context, resp types.RPCRes
// TryWriteRPCResponse attempts to push a response to the writeChan, but does
// not block.
// It implements WSRPCConnection. It is Goroutine-safe
func (wsc *wsConnection) TryWriteRPCResponse(resp types.RPCResponse) bool {
func (wsc *wsConnection) TryWriteRPCResponse(resp rpctypes.RPCResponse) bool {
select {
case <-wsc.Quit():
return false
@@ -304,7 +304,7 @@ func (wsc *wsConnection) readRoutine() {
err = fmt.Errorf("WSJSONRPC: %v", r)
}
wsc.Logger.Error("Panic in WSJSONRPC handler", "err", err, "stack", string(debug.Stack()))
if err := wsc.WriteRPCResponse(writeCtx, types.RPCInternalError(types.JSONRPCIntID(-1), err)); err != nil {
if err := wsc.WriteRPCResponse(writeCtx, rpctypes.RPCInternalError(rpctypes.JSONRPCIntID(-1), err)); err != nil {
wsc.Logger.Error("Error writing RPC response", "err", err)
}
go wsc.readRoutine()
@@ -340,11 +340,11 @@ func (wsc *wsConnection) readRoutine() {
}
dec := json.NewDecoder(r)
var request types.RPCRequest
var request rpctypes.RPCRequest
err = dec.Decode(&request)
if err != nil {
if err := wsc.WriteRPCResponse(writeCtx,
types.RPCParseError(fmt.Errorf("error unmarshaling request: %w", err))); err != nil {
rpctypes.RPCParseError(fmt.Errorf("error unmarshaling request: %w", err))); err != nil {
wsc.Logger.Error("Error writing RPC response", "err", err)
}
continue
@@ -363,19 +363,19 @@ func (wsc *wsConnection) readRoutine() {
// Now, fetch the RPCFunc and execute it.
rpcFunc := wsc.funcMap[request.Method]
if rpcFunc == nil {
if err := wsc.WriteRPCResponse(writeCtx, types.RPCMethodNotFoundError(request.ID)); err != nil {
if err := wsc.WriteRPCResponse(writeCtx, rpctypes.RPCMethodNotFoundError(request.ID)); err != nil {
wsc.Logger.Error("Error writing RPC response", "err", err)
}
continue
}
ctx := &types.Context{JSONReq: &request, WSConn: wsc}
ctx := &rpctypes.Context{JSONReq: &request, WSConn: wsc}
args := []reflect.Value{reflect.ValueOf(ctx)}
if len(request.Params) > 0 {
fnArgs, err := jsonParamsToArgs(rpcFunc, request.Params)
if err != nil {
if err := wsc.WriteRPCResponse(writeCtx,
types.RPCInvalidParamsError(request.ID, fmt.Errorf("error converting json params to arguments: %w", err)),
rpctypes.RPCInvalidParamsError(request.ID, fmt.Errorf("error converting json params to arguments: %w", err)),
); err != nil {
wsc.Logger.Error("Error writing RPC response", "err", err)
}
@@ -389,27 +389,27 @@ func (wsc *wsConnection) readRoutine() {
// TODO: Need to encode args/returns to string if we want to log them
wsc.Logger.Info("WSJSONRPC", "method", request.Method)
var resp types.RPCResponse
var resp rpctypes.RPCResponse
result, err := unreflectResult(returns)
switch e := err.(type) {
// if no error then return a success response
case nil:
resp = types.NewRPCSuccessResponse(request.ID, result)
resp = rpctypes.NewRPCSuccessResponse(request.ID, result)
// if this already of type RPC error then forward that error
case *types.RPCError:
resp = types.NewRPCErrorResponse(request.ID, e.Code, e.Message, e.Data)
case *rpctypes.RPCError:
resp = rpctypes.NewRPCErrorResponse(request.ID, e.Code, e.Message, e.Data)
default: // we need to unwrap the error and parse it accordingly
switch errors.Unwrap(err) {
// check if the error was due to an invald request
case ctypes.ErrZeroOrNegativeHeight, ctypes.ErrZeroOrNegativePerPage,
ctypes.ErrPageOutOfRange, ctypes.ErrInvalidRequest:
resp = types.RPCInvalidRequestError(request.ID, err)
case coretypes.ErrZeroOrNegativeHeight, coretypes.ErrZeroOrNegativePerPage,
coretypes.ErrPageOutOfRange, coretypes.ErrInvalidRequest:
resp = rpctypes.RPCInvalidRequestError(request.ID, err)
// lastly default all remaining errors as internal errors
default: // includes ctypes.ErrHeightNotAvailable and ctypes.ErrHeightExceedsChainHead
resp = types.RPCInternalError(request.ID, err)
resp = rpctypes.RPCInternalError(request.ID, err)
}
}
+5 -5
View File
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
func TestWebsocketManagerHandler(t *testing.T) {
@@ -26,8 +26,8 @@ func TestWebsocketManagerHandler(t *testing.T) {
}
// check basic functionality works
req, err := types.MapToRequest(
types.JSONRPCStringID("TestWebsocketManager"),
req, err := rpctypes.MapToRequest(
rpctypes.JSONRPCStringID("TestWebsocketManager"),
"c",
map[string]interface{}{"s": "a", "i": 10},
)
@@ -35,7 +35,7 @@ func TestWebsocketManagerHandler(t *testing.T) {
err = c.WriteJSON(req)
require.NoError(t, err)
var resp types.RPCResponse
var resp rpctypes.RPCResponse
err = c.ReadJSON(&resp)
require.NoError(t, err)
require.Nil(t, resp.Error)
@@ -44,7 +44,7 @@ func TestWebsocketManagerHandler(t *testing.T) {
func newWSServer() *httptest.Server {
funcMap := map[string]*RPCFunc{
"c": NewWSRPCFunc(func(ctx *types.Context, s string, i int) (string, error) { return "foo", nil }, "s,i"),
"c": NewWSRPCFunc(func(ctx *rpctypes.Context, s string, i int) (string, error) { return "foo", nil }, "s,i"),
}
wm := NewWebsocketManager(funcMap)
wm.SetLogger(log.TestingLogger())
+18 -18
View File
@@ -8,13 +8,13 @@ import (
abciclient "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
tmnet "github.com/tendermint/tendermint/libs/net"
"github.com/tendermint/tendermint/libs/service"
nm "github.com/tendermint/tendermint/node"
ctypes "github.com/tendermint/tendermint/rpc/coretypes"
core_grpc "github.com/tendermint/tendermint/rpc/grpc"
"github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/rpc/coretypes"
coregrpc "github.com/tendermint/tendermint/rpc/grpc"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
)
@@ -24,13 +24,13 @@ type Options struct {
suppressStdout bool
}
func waitForRPC(ctx context.Context, conf *cfg.Config) {
func waitForRPC(ctx context.Context, conf *config.Config) {
laddr := conf.RPC.ListenAddress
client, err := rpcclient.New(laddr)
if err != nil {
panic(err)
}
result := new(ctypes.ResultStatus)
result := new(coretypes.ResultStatus)
for {
_, err := client.Call(ctx, "status", map[string]interface{}{}, result)
if err == nil {
@@ -42,10 +42,10 @@ func waitForRPC(ctx context.Context, conf *cfg.Config) {
}
}
func waitForGRPC(ctx context.Context, conf *cfg.Config) {
func waitForGRPC(ctx context.Context, conf *config.Config) {
client := GetGRPCClient(conf)
for {
_, err := client.Ping(ctx, &core_grpc.RequestPing{})
_, err := client.Ping(ctx, &coregrpc.RequestPing{})
if err == nil {
return
}
@@ -66,8 +66,8 @@ func makeAddrs() (string, string, string) {
fmt.Sprintf("tcp://127.0.0.1:%d", randPort())
}
func CreateConfig(testName string) *cfg.Config {
c := cfg.ResetTestRoot(testName)
func CreateConfig(testName string) *config.Config {
c := config.ResetTestRoot(testName)
// and we use random ports to run in parallel
tm, rpc, grpc := makeAddrs()
@@ -78,15 +78,15 @@ func CreateConfig(testName string) *cfg.Config {
return c
}
func GetGRPCClient(conf *cfg.Config) core_grpc.BroadcastAPIClient {
func GetGRPCClient(conf *config.Config) coregrpc.BroadcastAPIClient {
grpcAddr := conf.RPC.GRPCListenAddress
return core_grpc.StartGRPCClient(grpcAddr)
return coregrpc.StartGRPCClient(grpcAddr)
}
type ServiceCloser func(context.Context) error
func StartTendermint(ctx context.Context,
conf *cfg.Config,
conf *config.Config,
app abci.Application,
opts ...func(*Options)) (service.Service, ServiceCloser, error) {
@@ -101,12 +101,12 @@ func StartTendermint(ctx context.Context,
logger = log.MustNewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo, false)
}
papp := abciclient.NewLocalCreator(app)
node, err := nm.New(conf, logger, papp, nil)
tmNode, err := node.New(conf, logger, papp, nil)
if err != nil {
return nil, func(_ context.Context) error { return nil }, err
}
err = node.Start()
err = tmNode.Start()
if err != nil {
return nil, func(_ context.Context) error { return nil }, err
}
@@ -119,11 +119,11 @@ func StartTendermint(ctx context.Context,
fmt.Println("Tendermint running!")
}
return node, func(ctx context.Context) error {
if err := node.Stop(); err != nil {
return tmNode, func(ctx context.Context) error {
if err := tmNode.Stop(); err != nil {
logger.Error("Error when trying to stop node", "err", err)
}
node.Wait()
tmNode.Wait()
os.RemoveAll(conf.RootDir)
return nil
}, nil