mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 09:24:30 +00:00
libs/common: Refactor libs/common 4 (#4237)
* libs/common: Refactor libs/common 4 - move byte function out of cmn to its own pkg - move tempfile out of cmn to its own pkg - move throttletimer to its own pkg ref #4147 Signed-off-by: Marko Baricevic <marbar3778@yahoo.com> * add changelog entry * fix linting issues
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
@@ -172,13 +172,13 @@ func (c *baseRPCClient) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *baseRPCClient) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
func (c *baseRPCClient) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions)
|
||||
}
|
||||
|
||||
func (c *baseRPCClient) ABCIQueryWithOptions(
|
||||
path string,
|
||||
data cmn.HexBytes,
|
||||
data bytes.HexBytes,
|
||||
opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||
result := new(ctypes.ResultABCIQuery)
|
||||
_, err := c.caller.Call("abci_query",
|
||||
|
||||
@@ -23,7 +23,7 @@ implementation.
|
||||
import (
|
||||
"context"
|
||||
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -51,8 +51,8 @@ type Client interface {
|
||||
type ABCIClient interface {
|
||||
// Reading from abci app
|
||||
ABCIInfo() (*ctypes.ResultABCIInfo, error)
|
||||
ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error)
|
||||
ABCIQueryWithOptions(path string, data cmn.HexBytes,
|
||||
ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)
|
||||
ABCIQueryWithOptions(path string, data bytes.HexBytes,
|
||||
opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
|
||||
|
||||
// Writing to abci app
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"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"
|
||||
@@ -73,13 +73,13 @@ func (c *Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
return core.ABCIInfo(c.ctx)
|
||||
}
|
||||
|
||||
func (c *Local) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
func (c *Local) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions)
|
||||
}
|
||||
|
||||
func (c *Local) ABCIQueryWithOptions(
|
||||
path string,
|
||||
data cmn.HexBytes,
|
||||
data bytes.HexBytes,
|
||||
opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||
return core.ABCIQuery(c.ctx, path, data, opts.Height, opts.Prove)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package mock
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
@@ -26,13 +26,13 @@ func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
return &ctypes.ResultABCIInfo{Response: a.App.Info(proxy.RequestInfo)}, nil
|
||||
}
|
||||
|
||||
func (a ABCIApp) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
func (a ABCIApp) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
return a.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
|
||||
}
|
||||
|
||||
func (a ABCIApp) ABCIQueryWithOptions(
|
||||
path string,
|
||||
data cmn.HexBytes,
|
||||
data bytes.HexBytes,
|
||||
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||
q := a.App.Query(abci.RequestQuery{
|
||||
Data: data,
|
||||
@@ -93,13 +93,13 @@ func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
return &ctypes.ResultABCIInfo{Response: res.(abci.ResponseInfo)}, nil
|
||||
}
|
||||
|
||||
func (m ABCIMock) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
func (m ABCIMock) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
return m.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
|
||||
}
|
||||
|
||||
func (m ABCIMock) ABCIQueryWithOptions(
|
||||
path string,
|
||||
data cmn.HexBytes,
|
||||
data bytes.HexBytes,
|
||||
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||
res, err := m.Query.GetResponse(QueryArgs{path, data, opts.Height, opts.Prove})
|
||||
if err != nil {
|
||||
@@ -149,7 +149,7 @@ func NewABCIRecorder(client client.ABCIClient) *ABCIRecorder {
|
||||
|
||||
type QueryArgs struct {
|
||||
Path string
|
||||
Data cmn.HexBytes
|
||||
Data bytes.HexBytes
|
||||
Height int64
|
||||
Prove bool
|
||||
}
|
||||
@@ -168,13 +168,13 @@ func (r *ABCIRecorder) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (r *ABCIRecorder) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
func (r *ABCIRecorder) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
return r.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
|
||||
}
|
||||
|
||||
func (r *ABCIRecorder) ABCIQueryWithOptions(
|
||||
path string,
|
||||
data cmn.HexBytes,
|
||||
data bytes.HexBytes,
|
||||
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||
res, err := r.Client.ABCIQueryWithOptions(path, data, opts)
|
||||
r.addCall(Call{
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"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/core/types"
|
||||
@@ -37,8 +37,8 @@ func TestABCIMock(t *testing.T) {
|
||||
BroadcastCommit: mock.Call{
|
||||
Args: goodTx,
|
||||
Response: &ctypes.ResultBroadcastTxCommit{
|
||||
CheckTx: abci.ResponseCheckTx{Data: cmn.HexBytes("stand")},
|
||||
DeliverTx: abci.ResponseDeliverTx{Data: cmn.HexBytes("deliver")},
|
||||
CheckTx: abci.ResponseCheckTx{Data: bytes.HexBytes("stand")},
|
||||
DeliverTx: abci.ResponseDeliverTx{Data: bytes.HexBytes("deliver")},
|
||||
},
|
||||
Error: errors.New("bad tx"),
|
||||
},
|
||||
@@ -98,7 +98,7 @@ func TestABCIRecorder(t *testing.T) {
|
||||
_, err := r.ABCIInfo()
|
||||
assert.Nil(err, "expected no err on info")
|
||||
|
||||
_, err = r.ABCIQueryWithOptions("path", cmn.HexBytes("data"), client.ABCIQueryOptions{Prove: false})
|
||||
_, err = r.ABCIQueryWithOptions("path", bytes.HexBytes("data"), client.ABCIQueryOptions{Prove: false})
|
||||
assert.NotNil(err, "expected error on query")
|
||||
require.Equal(2, len(r.Calls))
|
||||
|
||||
@@ -180,7 +180,7 @@ func TestABCIApp(t *testing.T) {
|
||||
}
|
||||
|
||||
// check the key
|
||||
_qres, err := m.ABCIQueryWithOptions("/key", cmn.HexBytes(key), client.ABCIQueryOptions{Prove: true})
|
||||
_qres, err := m.ABCIQueryWithOptions("/key", bytes.HexBytes(key), client.ABCIQueryOptions{Prove: true})
|
||||
qres := _qres.Response
|
||||
require.Nil(err)
|
||||
assert.EqualValues(value, qres.Value)
|
||||
|
||||
@@ -17,7 +17,7 @@ want to directly call a tendermint node in process, you can use the
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
"github.com/tendermint/tendermint/rpc/core"
|
||||
@@ -87,13 +87,13 @@ func (c Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
return core.ABCIInfo(&rpctypes.Context{})
|
||||
}
|
||||
|
||||
func (c Client) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
func (c Client) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
return c.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
|
||||
}
|
||||
|
||||
func (c Client) ABCIQueryWithOptions(
|
||||
path string,
|
||||
data cmn.HexBytes,
|
||||
data bytes.HexBytes,
|
||||
opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||
return core.ABCIQuery(&rpctypes.Context{}, path, data, opts.Height, opts.Prove)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
"github.com/tendermint/tendermint/rpc/client/mock"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
)
|
||||
@@ -18,8 +18,8 @@ func TestStatus(t *testing.T) {
|
||||
Call: mock.Call{
|
||||
Response: &ctypes.ResultStatus{
|
||||
SyncInfo: ctypes.SyncInfo{
|
||||
LatestBlockHash: cmn.HexBytes("block"),
|
||||
LatestAppHash: cmn.HexBytes("app"),
|
||||
LatestBlockHash: bytes.HexBytes("block"),
|
||||
LatestAppHash: bytes.HexBytes("app"),
|
||||
LatestBlockHeight: 10,
|
||||
},
|
||||
}},
|
||||
|
||||
Reference in New Issue
Block a user