Browse Source

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
pull/4242/head
Marko 5 years ago
committed by GitHub
parent
commit
89f0bbbd76
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 181 additions and 251 deletions
  1. +3
    -0
      CHANGELOG_PENDING.md
  2. +3
    -2
      abci/client/socket_client.go
  3. +2
    -2
      cmd/tendermint/commands/testnet.go
  4. +2
    -1
      consensus/common_test.go
  5. +5
    -4
      consensus/reactor_test.go
  6. +4
    -4
      consensus/types/round_state.go
  7. +2
    -2
      crypto/crypto.go
  8. +0
    -19
      libs/.editorconfig
  9. +0
    -5
      libs/.gitignore
  10. +0
    -44
      libs/README.md
  11. +1
    -1
      libs/bytes/bytes.go
  12. +1
    -1
      libs/bytes/bytes_test.go
  13. +1
    -1
      libs/bytes/byteslice.go
  14. +1
    -1
      libs/tempfile/tempfile.go
  15. +1
    -1
      libs/tempfile/tempfile_test.go
  16. +0
    -15
      libs/test.sh
  17. +1
    -1
      libs/timer/throttle_timer.go
  18. +1
    -1
      libs/timer/throttle_timer_test.go
  19. +3
    -3
      lite/proxy/proxy.go
  20. +2
    -2
      lite/proxy/query.go
  21. +3
    -4
      lite/proxy/wrapper.go
  22. +3
    -3
      lite2/proxy/routes.go
  23. +3
    -3
      lite2/rpc/client.go
  24. +4
    -3
      p2p/conn/connection.go
  25. +4
    -3
      p2p/node_info.go
  26. +2
    -2
      p2p/peer_test.go
  27. +2
    -2
      p2p/pex/file.go
  28. +9
    -7
      privval/file.go
  29. +2
    -2
      privval/file_deprecated.go
  30. +3
    -3
      rpc/client/httpclient.go
  31. +3
    -3
      rpc/client/interface.go
  32. +3
    -3
      rpc/client/localclient.go
  33. +8
    -8
      rpc/client/mock/abci.go
  34. +5
    -5
      rpc/client/mock/abci_test.go
  35. +3
    -3
      rpc/client/mock/client.go
  36. +3
    -3
      rpc/client/mock/status_test.go
  37. +2
    -2
      rpc/core/abci.go
  38. +3
    -3
      rpc/core/status.go
  39. +15
    -15
      rpc/core/types/responses.go
  40. +5
    -5
      rpc/lib/rpc_test.go
  41. +10
    -10
      rpc/lib/server/parse_test.go
  42. +22
    -21
      types/block.go
  43. +9
    -8
      types/block_test.go
  44. +3
    -3
      types/canonical.go
  45. +2
    -1
      types/genesis.go
  46. +6
    -5
      types/part_set.go
  47. +2
    -2
      types/proposal.go
  48. +3
    -3
      types/results.go
  49. +2
    -2
      types/tx.go
  50. +4
    -4
      types/vote.go

+ 3
- 0
CHANGELOG_PENDING.md View File

@ -74,6 +74,9 @@ program](https://hackerone.com/tendermint).
- [libs/common] \#4232 Move `Service` & `BaseService` from `libs/common` to `libs/service`
- [libs/common] \#4232 Move `common/nil.go` to `types/utils.go` & make the functions private
- [libs/common] \#4231 Move random functions from `libs/common` into pkg `rand`
- [libs/common] \#4237 Move byte functions from `libs/common` into pkg `bytes`
- [libs/common] \#4237 Move throttletimer functions from `libs/common` into pkg `timer`
- [libs/common] \#4237 Move tempfile functions from `libs/common` into pkg `tempfile`
- Blockchain Protocol


+ 3
- 2
abci/client/socket_client.go View File

@ -14,6 +14,7 @@ import (
"github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/service"
"github.com/tendermint/tendermint/libs/timer"
)
const reqQueueSize = 256 // TODO make configurable
@ -33,7 +34,7 @@ type socketClient struct {
conn net.Conn
reqQueue chan *ReqRes
flushTimer *cmn.ThrottleTimer
flushTimer *timer.ThrottleTimer
mtx sync.Mutex
err error
@ -45,7 +46,7 @@ type socketClient struct {
func NewSocketClient(addr string, mustConnect bool) *socketClient {
cli := &socketClient{
reqQueue: make(chan *ReqRes, reqQueueSize),
flushTimer: cmn.NewThrottleTimer("socketClient", flushThrottleMS),
flushTimer: timer.NewThrottleTimer("socketClient", flushThrottleMS),
mustConnect: mustConnect,
addr: addr,


+ 2
- 2
cmd/tendermint/commands/testnet.go View File

@ -11,7 +11,7 @@ import (
"github.com/spf13/viper"
cfg "github.com/tendermint/tendermint/config"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
@ -262,5 +262,5 @@ func moniker(i int) string {
}
func randomMoniker() string {
return cmn.HexBytes(rand.RandBytes(8)).String()
return bytes.HexBytes(rand.RandBytes(8)).String()
}

+ 2
- 1
consensus/common_test.go View File

@ -22,6 +22,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
cstypes "github.com/tendermint/tendermint/consensus/types"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
@ -518,7 +519,7 @@ func ensureNewBlock(blockCh <-chan tmpubsub.Message, height int64) {
}
}
func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHash cmn.HexBytes) {
func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHash tmbytes.HexBytes) {
select {
case <-time.After(ensureTimeout):
panic("Timeout expired while waiting for NewBlockHeader event")


+ 5
- 4
consensus/reactor_test.go View File

@ -20,6 +20,7 @@ import (
cfg "github.com/tendermint/tendermint/config"
cstypes "github.com/tendermint/tendermint/consensus/types"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
mempl "github.com/tendermint/tendermint/mempool"
@ -850,10 +851,10 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) {
validBlockID := types.BlockID{}
invalidBlockID := types.BlockID{
Hash: cmn.HexBytes{},
Hash: bytes.HexBytes{},
PartsHeader: types.PartSetHeader{
Total: -1,
Hash: cmn.HexBytes{},
Hash: bytes.HexBytes{},
},
}
@ -898,10 +899,10 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
{func(msg *VoteSetBitsMessage) { msg.Type = 0x03 }, "invalid Type"},
{func(msg *VoteSetBitsMessage) {
msg.BlockID = types.BlockID{
Hash: cmn.HexBytes{},
Hash: bytes.HexBytes{},
PartsHeader: types.PartSetHeader{
Total: -1,
Hash: cmn.HexBytes{},
Hash: bytes.HexBytes{},
},
}
}, "wrong BlockID: wrong PartsHeader: negative Total"},


+ 4
- 4
consensus/types/round_state.go View File

@ -5,7 +5,7 @@ import (
"fmt"
"time"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/types"
)
@ -97,9 +97,9 @@ type RoundState struct {
type RoundStateSimple struct {
HeightRoundStep string `json:"height/round/step"`
StartTime time.Time `json:"start_time"`
ProposalBlockHash cmn.HexBytes `json:"proposal_block_hash"`
LockedBlockHash cmn.HexBytes `json:"locked_block_hash"`
ValidBlockHash cmn.HexBytes `json:"valid_block_hash"`
ProposalBlockHash bytes.HexBytes `json:"proposal_block_hash"`
LockedBlockHash bytes.HexBytes `json:"locked_block_hash"`
ValidBlockHash bytes.HexBytes `json:"valid_block_hash"`
Votes json.RawMessage `json:"height_vote_set"`
}


+ 2
- 2
crypto/crypto.go View File

@ -2,7 +2,7 @@ package crypto
import (
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
)
const (
@ -13,7 +13,7 @@ const (
// An address is a []byte, but hex-encoded even in JSON.
// []byte leaves us the option to change the address length.
// Use an alias so Unmarshal methods (with ptr receivers) are available too.
type Address = cmn.HexBytes
type Address = bytes.HexBytes
func AddressHash(bz []byte) Address {
return Address(tmhash.SumTruncated(bz))


+ 0
- 19
libs/.editorconfig View File

@ -1,19 +0,0 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[Makefile]
indent_style = tab
[*.sh]
indent_style = tab
[*.proto]
indent_style = space
indent_size = 2

+ 0
- 5
libs/.gitignore View File

@ -1,5 +0,0 @@
*.sw[opqr]
vendor
.glide
pubsub/query/fuzz_test/output

+ 0
- 44
libs/README.md View File

@ -1,44 +0,0 @@
# TMLIBS
This repo is a home for various small packages.
## autofile
Autofile is file access with automatic log rotation. A group of files is maintained and rotation happens
when the leading file gets too big. Provides a reader for reading from the file group.
## cli
CLI wraps the `cobra` and `viper` packages and handles some common elements of building a CLI like flags and env vars for the home directory and the logger.
## clist
Clist provides a linked list that is safe for concurrent access by many readers.
## common
Common provides a hodgepodge of useful functions.
## events
Events is a synchronous PubSub package.
## flowrate
Flowrate is a fork of https://github.com/mxk/go-flowrate that added a `SetREMA` method.
## log
Log is a log package structured around key-value pairs that allows logging level to be set differently for different keys.
## merkle
Merkle provides a simple static merkle tree and corresponding proofs.
## process
Process is a simple utility for spawning OS processes.
## pubsub
PubSub is an asynchronous PubSub package.

libs/common/bytes.go → libs/bytes/bytes.go View File


libs/common/bytes_test.go → libs/bytes/bytes_test.go View File


libs/common/byteslice.go → libs/bytes/byteslice.go View File


libs/common/tempfile.go → libs/tempfile/tempfile.go View File


libs/common/tempfile_test.go → libs/tempfile/tempfile_test.go View File


+ 0
- 15
libs/test.sh View File

@ -1,15 +0,0 @@
#!/usr/bin/env bash
set -e
# run the linter
# make lint
# run the unit tests with coverage
echo "" > coverage.txt
for d in $(go list ./... | grep -v vendor); do
go test -race -coverprofile=profile.out -covermode=atomic "$d"
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done

libs/common/throttle_timer.go → libs/timer/throttle_timer.go View File


libs/common/throttle_timer_test.go → libs/timer/throttle_timer_test.go View File


+ 3
- 3
lite/proxy/proxy.go View File

@ -6,7 +6,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"
"github.com/tendermint/tendermint/rpc/client"
rpcclient "github.com/tendermint/tendermint/rpc/client"
@ -168,9 +168,9 @@ func makeBroadcastTxAsyncFunc(c rpcclient.Client) func(
func makeABCIQueryFunc(c rpcclient.Client) func(
ctx *rpctypes.Context,
path string,
data cmn.HexBytes,
data bytes.HexBytes,
) (*ctypes.ResultABCIQuery, error) {
return func(ctx *rpctypes.Context, path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQuery(path, data)
}
}


+ 2
- 2
lite/proxy/query.go View File

@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/lite"
lerr "github.com/tendermint/tendermint/lite/errors"
rpcclient "github.com/tendermint/tendermint/rpc/client"
@ -21,7 +21,7 @@ import (
// If there is any error in checking, returns an error.
func GetWithProof(prt *merkle.ProofRuntime, key []byte, reqHeight int64, node rpcclient.Client,
cert lite.Verifier) (
val cmn.HexBytes, height int64, proof *merkle.Proof, err error) {
val bytes.HexBytes, height int64, proof *merkle.Proof, err error) {
if reqHeight < 0 {
err = errors.New("height cannot be negative")


+ 3
- 4
lite/proxy/wrapper.go View File

@ -3,9 +3,8 @@ package proxy
import (
"context"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/lite"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -39,7 +38,7 @@ func SecureClient(c rpcclient.Client, cert *lite.DynamicVerifier) Wrapper {
}
// ABCIQueryWithOptions exposes all options for the ABCI query and verifies the returned proof
func (w Wrapper) ABCIQueryWithOptions(path string, data cmn.HexBytes,
func (w Wrapper) ABCIQueryWithOptions(path string, data bytes.HexBytes,
opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
res, err := GetWithProofOptions(w.prt, path, data, opts, w.Client, w.cert)
@ -47,7 +46,7 @@ func (w Wrapper) ABCIQueryWithOptions(path string, data cmn.HexBytes,
}
// ABCIQuery uses default options for the ABCI query and verifies the returned proof
func (w Wrapper) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (w Wrapper) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
return w.ABCIQueryWithOptions(path, data, rpcclient.DefaultABCIQueryOptions)
}


+ 3
- 3
lite2/proxy/routes.go View File

@ -1,7 +1,7 @@
package proxy
import (
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
lrpc "github.com/tendermint/tendermint/lite2/rpc"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
@ -203,10 +203,10 @@ func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc {
}
}
type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error)
type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)
func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc {
return func(ctx *rpctypes.Context, path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQuery(path, data)
}
}


+ 3
- 3
lite2/rpc/client.go View File

@ -10,7 +10,7 @@ import (
"github.com/pkg/errors"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
service "github.com/tendermint/tendermint/libs/service"
lite "github.com/tendermint/tendermint/lite2"
rpcclient "github.com/tendermint/tendermint/rpc/client"
@ -63,13 +63,13 @@ func (c *Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return c.next.ABCIInfo()
}
func (c *Client) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (c *Client) ABCIQuery(path string, data tmbytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(path, data, rpcclient.DefaultABCIQueryOptions)
}
// GetWithProofOptions is useful if you want full access to the ABCIQueryOptions.
// XXX Usage of path? It's not used, and sometimes it's /, sometimes /key, sometimes /store.
func (c *Client) ABCIQueryWithOptions(path string, data cmn.HexBytes,
func (c *Client) ABCIQueryWithOptions(path string, data tmbytes.HexBytes,
opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
res, err := c.next.ABCIQueryWithOptions(path, data, opts)


+ 4
- 3
p2p/conn/connection.go View File

@ -20,6 +20,7 @@ import (
flow "github.com/tendermint/tendermint/libs/flowrate"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service"
"github.com/tendermint/tendermint/libs/timer"
)
const (
@ -101,8 +102,8 @@ type MConnection struct {
// are safe to call concurrently.
stopMtx sync.Mutex
flushTimer *cmn.ThrottleTimer // flush writes as necessary but throttled.
pingTimer *time.Ticker // send pings periodically
flushTimer *timer.ThrottleTimer // flush writes as necessary but throttled.
pingTimer *time.Ticker // send pings periodically
// close conn if pong is not received in pongTimeout
pongTimer *time.Timer
@ -218,7 +219,7 @@ func (c *MConnection) OnStart() error {
if err := c.BaseService.OnStart(); err != nil {
return err
}
c.flushTimer = cmn.NewThrottleTimer("flush", c.config.FlushThrottle)
c.flushTimer = timer.NewThrottleTimer("flush", c.config.FlushThrottle)
c.pingTimer = time.NewTicker(c.config.PingInterval)
c.pongTimeoutCh = make(chan bool, 1)
c.chStatsTimer = time.NewTicker(updateStats)


+ 4
- 3
p2p/node_info.go View File

@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/version"
)
@ -82,9 +83,9 @@ type DefaultNodeInfo struct {
// Check compatibility.
// Channels are HexBytes so easier to read as JSON
Network string `json:"network"` // network/chain ID
Version string `json:"version"` // major.minor.revision
Channels cmn.HexBytes `json:"channels"` // channels this node knows about
Network string `json:"network"` // network/chain ID
Version string `json:"version"` // major.minor.revision
Channels bytes.HexBytes `json:"channels"` // channels this node knows about
// ASCIIText fields
Moniker string `json:"moniker"` // arbitrary moniker


+ 2
- 2
p2p/peer_test.go View File

@ -13,7 +13,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/config"
@ -140,7 +140,7 @@ type remotePeer struct {
PrivKey crypto.PrivKey
Config *config.P2PConfig
addr *NetAddress
channels cmn.HexBytes
channels bytes.HexBytes
listenAddr string
listener net.Listener
}


+ 2
- 2
p2p/pex/file.go View File

@ -5,7 +5,7 @@ import (
"fmt"
"os"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/tempfile"
)
/* Loading & Saving */
@ -35,7 +35,7 @@ func (a *addrBook) saveToFile(filePath string) {
a.Logger.Error("Failed to save AddrBook to file", "err", err)
return
}
err = cmn.WriteFileAtomic(filePath, jsonBytes, 0644)
err = tempfile.WriteFileAtomic(filePath, jsonBytes, 0644)
if err != nil {
a.Logger.Error("Failed to save AddrBook to file", "file", filePath, "err", err)
}


+ 9
- 7
privval/file.go View File

@ -9,7 +9,9 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/tempfile"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -56,7 +58,7 @@ func (pvKey FilePVKey) Save() {
if err != nil {
panic(err)
}
err = cmn.WriteFileAtomic(outFile, jsonBytes, 0600)
err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0600)
if err != nil {
panic(err)
}
@ -67,11 +69,11 @@ func (pvKey FilePVKey) Save() {
// FilePVLastSignState stores the mutable part of PrivValidator.
type FilePVLastSignState struct {
Height int64 `json:"height"`
Round int `json:"round"`
Step int8 `json:"step"`
Signature []byte `json:"signature,omitempty"`
SignBytes cmn.HexBytes `json:"signbytes,omitempty"`
Height int64 `json:"height"`
Round int `json:"round"`
Step int8 `json:"step"`
Signature []byte `json:"signature,omitempty"`
SignBytes tmbytes.HexBytes `json:"signbytes,omitempty"`
filePath string
}
@ -127,7 +129,7 @@ func (lss *FilePVLastSignState) Save() {
if err != nil {
panic(err)
}
err = cmn.WriteFileAtomic(outFile, jsonBytes, 0600)
err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0600)
if err != nil {
panic(err)
}


+ 2
- 2
privval/file_deprecated.go View File

@ -5,7 +5,7 @@ import (
"os"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/types"
)
@ -18,7 +18,7 @@ type OldFilePV struct {
LastRound int `json:"last_round"`
LastStep int8 `json:"last_step"`
LastSignature []byte `json:"last_signature,omitempty"`
LastSignBytes cmn.HexBytes `json:"last_signbytes,omitempty"`
LastSignBytes bytes.HexBytes `json:"last_signbytes,omitempty"`
PrivKey crypto.PrivKey `json:"priv_key"`
filePath string


+ 3
- 3
rpc/client/httpclient.go View File

@ -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",


+ 3
- 3
rpc/client/interface.go View File

@ -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


+ 3
- 3
rpc/client/localclient.go View File

@ -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)
}


+ 8
- 8
rpc/client/mock/abci.go View File

@ -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{


+ 5
- 5
rpc/client/mock/abci_test.go View File

@ -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)


+ 3
- 3
rpc/client/mock/client.go View File

@ -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)
}


+ 3
- 3
rpc/client/mock/status_test.go View File

@ -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,
},
}},


+ 2
- 2
rpc/core/abci.go View File

@ -2,7 +2,7 @@ package core
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"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
@ -13,7 +13,7 @@ import (
func ABCIQuery(
ctx *rpctypes.Context,
path string,
data cmn.HexBytes,
data bytes.HexBytes,
height int64,
prove bool,
) (*ctypes.ResultABCIQuery, error) {


+ 3
- 3
rpc/core/status.go View File

@ -4,7 +4,7 @@ import (
"bytes"
"time"
cmn "github.com/tendermint/tendermint/libs/common"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/p2p"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
@ -24,8 +24,8 @@ func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
}
var (
latestBlockMeta *types.BlockMeta
latestBlockHash cmn.HexBytes
latestAppHash cmn.HexBytes
latestBlockHash tmbytes.HexBytes
latestAppHash tmbytes.HexBytes
latestBlockTimeNano int64
)
if latestHeight != 0 {


+ 15
- 15
rpc/core/types/responses.go View File

@ -6,7 +6,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
@ -61,18 +61,18 @@ func NewResultCommit(header *types.Header, commit *types.Commit,
// Info about the node's syncing state
type SyncInfo struct {
LatestBlockHash cmn.HexBytes `json:"latest_block_hash"`
LatestAppHash cmn.HexBytes `json:"latest_app_hash"`
LatestBlockHeight int64 `json:"latest_block_height"`
LatestBlockTime time.Time `json:"latest_block_time"`
CatchingUp bool `json:"catching_up"`
LatestBlockHash bytes.HexBytes `json:"latest_block_hash"`
LatestAppHash bytes.HexBytes `json:"latest_app_hash"`
LatestBlockHeight int64 `json:"latest_block_height"`
LatestBlockTime time.Time `json:"latest_block_time"`
CatchingUp bool `json:"catching_up"`
}
// Info about the node's validator
type ValidatorInfo struct {
Address cmn.HexBytes `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"`
Address bytes.HexBytes `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"`
}
// Node Status
@ -148,24 +148,24 @@ type ResultConsensusState struct {
// CheckTx result
type ResultBroadcastTx struct {
Code uint32 `json:"code"`
Data cmn.HexBytes `json:"data"`
Log string `json:"log"`
Code uint32 `json:"code"`
Data bytes.HexBytes `json:"data"`
Log string `json:"log"`
Hash cmn.HexBytes `json:"hash"`
Hash bytes.HexBytes `json:"hash"`
}
// CheckTx and DeliverTx results
type ResultBroadcastTxCommit struct {
CheckTx abci.ResponseCheckTx `json:"check_tx"`
DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
Hash cmn.HexBytes `json:"hash"`
Hash bytes.HexBytes `json:"hash"`
Height int64 `json:"height"`
}
// Result of querying for a tx
type ResultTx struct {
Hash cmn.HexBytes `json:"hash"`
Hash bytes.HexBytes `json:"hash"`
Height int64 `json:"height"`
Index uint32 `json:"index"`
TxResult abci.ResponseDeliverTx `json:"tx_result"`


+ 5
- 5
rpc/lib/rpc_test.go View File

@ -17,7 +17,7 @@ import (
"github.com/stretchr/testify/require"
amino "github.com/tendermint/go-amino"
cmn "github.com/tendermint/tendermint/libs/common"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/rand"
@ -51,7 +51,7 @@ type ResultEchoBytes struct {
}
type ResultEchoDataBytes struct {
Value cmn.HexBytes `json:"value"`
Value tmbytes.HexBytes `json:"value"`
}
// Define some routes
@ -82,7 +82,7 @@ func EchoBytesResult(ctx *types.Context, v []byte) (*ResultEchoBytes, error) {
return &ResultEchoBytes{v}, nil
}
func EchoDataBytesResult(ctx *types.Context, v cmn.HexBytes) (*ResultEchoDataBytes, error) {
func EchoDataBytesResult(ctx *types.Context, v tmbytes.HexBytes) (*ResultEchoDataBytes, error) {
return &ResultEchoDataBytes{v}, nil
}
@ -180,7 +180,7 @@ func echoBytesViaHTTP(cl client.JSONRPCCaller, bytes []byte) ([]byte, error) {
return result.Value, nil
}
func echoDataBytesViaHTTP(cl client.JSONRPCCaller, bytes cmn.HexBytes) (cmn.HexBytes, error) {
func echoDataBytesViaHTTP(cl client.JSONRPCCaller, bytes tmbytes.HexBytes) (tmbytes.HexBytes, error) {
params := map[string]interface{}{
"arg": bytes,
}
@ -202,7 +202,7 @@ func testWithHTTPClient(t *testing.T, cl client.HTTPClient) {
require.Nil(t, err)
assert.Equal(t, got2, val2)
val3 := cmn.HexBytes(randBytes(t))
val3 := tmbytes.HexBytes(randBytes(t))
got3, err := echoDataBytesViaHTTP(cl, val3)
require.Nil(t, err)
assert.Equal(t, got3, val3)


+ 10
- 10
rpc/lib/server/parse_test.go View File

@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
amino "github.com/tendermint/go-amino"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
types "github.com/tendermint/tendermint/rpc/lib/types"
)
@ -33,7 +33,7 @@ func TestParseJSONMap(t *testing.T) {
// preloading map with values doesn't help
tmp := 0
p2 := map[string]interface{}{
"value": &cmn.HexBytes{},
"value": &bytes.HexBytes{},
"height": &tmp,
}
err = json.Unmarshal(input, &p2)
@ -56,7 +56,7 @@ func TestParseJSONMap(t *testing.T) {
Height interface{} `json:"height"`
}{
Height: &tmp,
Value: &cmn.HexBytes{},
Value: &bytes.HexBytes{},
}
err = json.Unmarshal(input, &p3)
if assert.Nil(t, err) {
@ -64,7 +64,7 @@ func TestParseJSONMap(t *testing.T) {
if assert.True(t, ok, "%#v", p3.Height) {
assert.Equal(t, 22, *h)
}
v, ok := p3.Value.(*cmn.HexBytes)
v, ok := p3.Value.(*bytes.HexBytes)
if assert.True(t, ok, "%#v", p3.Value) {
assert.EqualValues(t, []byte{0x12, 0x34}, *v)
}
@ -72,8 +72,8 @@ func TestParseJSONMap(t *testing.T) {
// simplest solution, but hard-coded
p4 := struct {
Value cmn.HexBytes `json:"value"`
Height int `json:"height"`
Value bytes.HexBytes `json:"value"`
Height int `json:"height"`
}{}
err = json.Unmarshal(input, &p4)
if assert.Nil(t, err) {
@ -92,10 +92,10 @@ func TestParseJSONMap(t *testing.T) {
assert.Equal(t, 22, h)
}
var v cmn.HexBytes
var v bytes.HexBytes
err = json.Unmarshal(*p5["value"], &v)
if assert.Nil(t, err) {
assert.Equal(t, cmn.HexBytes{0x12, 0x34}, v)
assert.Equal(t, bytes.HexBytes{0x12, 0x34}, v)
}
}
}
@ -119,10 +119,10 @@ func TestParseJSONArray(t *testing.T) {
// preloading map with values helps here (unlike map - p2 above)
tmp := 0
p2 := []interface{}{&cmn.HexBytes{}, &tmp}
p2 := []interface{}{&bytes.HexBytes{}, &tmp}
err = json.Unmarshal(input, &p2)
if assert.Nil(t, err) {
v, ok := p2[0].(*cmn.HexBytes)
v, ok := p2[0].(*bytes.HexBytes)
if assert.True(t, ok, "%#v", p2[0]) {
assert.EqualValues(t, []byte{0x12, 0x34}, *v)
}


+ 22
- 21
types/block.go View File

@ -12,6 +12,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/version"
)
@ -156,7 +157,7 @@ func (b *Block) fillHeader() {
// Hash computes and returns the block hash.
// If the block is incomplete, block hash is nil for safety.
func (b *Block) Hash() cmn.HexBytes {
func (b *Block) Hash() tmbytes.HexBytes {
if b == nil {
return nil
}
@ -329,20 +330,20 @@ type Header struct {
LastBlockID BlockID `json:"last_block_id"`
// hashes of block data
LastCommitHash cmn.HexBytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash cmn.HexBytes `json:"data_hash"` // transactions
LastCommitHash tmbytes.HexBytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash tmbytes.HexBytes `json:"data_hash"` // transactions
// hashes from the app output from the prev block
ValidatorsHash cmn.HexBytes `json:"validators_hash"` // validators for the current block
NextValidatorsHash cmn.HexBytes `json:"next_validators_hash"` // validators for the next block
ConsensusHash cmn.HexBytes `json:"consensus_hash"` // consensus params for current block
AppHash cmn.HexBytes `json:"app_hash"` // state after txs from the previous block
ValidatorsHash tmbytes.HexBytes `json:"validators_hash"` // validators for the current block
NextValidatorsHash tmbytes.HexBytes `json:"next_validators_hash"` // validators for the next block
ConsensusHash tmbytes.HexBytes `json:"consensus_hash"` // consensus params for current block
AppHash tmbytes.HexBytes `json:"app_hash"` // state after txs from the previous block
// root hash of all results from the txs from the previous block
LastResultsHash cmn.HexBytes `json:"last_results_hash"`
LastResultsHash tmbytes.HexBytes `json:"last_results_hash"`
// consensus info
EvidenceHash cmn.HexBytes `json:"evidence_hash"` // evidence included in the block
ProposerAddress Address `json:"proposer_address"` // original proposer of the block
EvidenceHash tmbytes.HexBytes `json:"evidence_hash"` // evidence included in the block
ProposerAddress Address `json:"proposer_address"` // original proposer of the block
}
// Populate the Header with state-derived data.
@ -372,7 +373,7 @@ func (h *Header) Populate(
// Returns nil if ValidatorHash is missing,
// since a Header is not valid unless there is
// a ValidatorsHash (corresponding to the validator set).
func (h *Header) Hash() cmn.HexBytes {
func (h *Header) Hash() tmbytes.HexBytes {
if h == nil || len(h.ValidatorsHash) == 0 {
return nil
}
@ -479,8 +480,8 @@ func (cs CommitSig) Absent() bool {
func (cs CommitSig) String() string {
return fmt.Sprintf("CommitSig{%X by %X on %v @ %s}",
cmn.Fingerprint(cs.Signature),
cmn.Fingerprint(cs.ValidatorAddress),
tmbytes.Fingerprint(cs.Signature),
tmbytes.Fingerprint(cs.ValidatorAddress),
cs.BlockIDFlag,
CanonicalTime(cs.Timestamp))
}
@ -559,7 +560,7 @@ type Commit struct {
// Memoized in first call to corresponding method.
// NOTE: can't memoize in constructor because constructor isn't used for
// unmarshaling.
hash cmn.HexBytes
hash tmbytes.HexBytes
bitArray *cmn.BitArray
}
@ -696,7 +697,7 @@ func (commit *Commit) ValidateBasic() error {
}
// Hash returns the hash of the commit
func (commit *Commit) Hash() cmn.HexBytes {
func (commit *Commit) Hash() tmbytes.HexBytes {
if commit == nil {
return nil
}
@ -809,11 +810,11 @@ type Data struct {
Txs Txs `json:"txs"`
// Volatile
hash cmn.HexBytes
hash tmbytes.HexBytes
}
// Hash returns the hash of the data
func (data *Data) Hash() cmn.HexBytes {
func (data *Data) Hash() tmbytes.HexBytes {
if data == nil {
return (Txs{}).Hash()
}
@ -850,11 +851,11 @@ type EvidenceData struct {
Evidence EvidenceList `json:"evidence"`
// Volatile
hash cmn.HexBytes
hash tmbytes.HexBytes
}
// Hash returns the hash of the data.
func (data *EvidenceData) Hash() cmn.HexBytes {
func (data *EvidenceData) Hash() tmbytes.HexBytes {
if data.hash == nil {
data.hash = data.Evidence.Hash()
}
@ -885,8 +886,8 @@ func (data *EvidenceData) StringIndented(indent string) string {
// BlockID defines the unique ID of a block as its Hash and its PartSetHeader
type BlockID struct {
Hash cmn.HexBytes `json:"hash"`
PartsHeader PartSetHeader `json:"parts"`
Hash tmbytes.HexBytes `json:"hash"`
PartsHeader PartSetHeader `json:"parts"`
}
// Equals returns true if the BlockID matches the given BlockID


+ 9
- 8
types/block_test.go View File

@ -17,6 +17,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmtime "github.com/tendermint/tendermint/types/time"
@ -251,7 +252,7 @@ func TestHeaderHash(t *testing.T) {
testCases := []struct {
desc string
header *Header
expectHash cmn.HexBytes
expectHash bytes.HexBytes
}{
{"Generates expected hash", &Header{
Version: version.Consensus{Block: 1, App: 2},
@ -304,7 +305,7 @@ func TestHeaderHash(t *testing.T) {
byteSlices = append(byteSlices, cdcEncode(f.Interface()))
}
assert.Equal(t,
cmn.HexBytes(merkle.SimpleHashFromByteSlices(byteSlices)), tc.header.Hash())
bytes.HexBytes(merkle.SimpleHashFromByteSlices(byteSlices)), tc.header.Hash())
}
})
}
@ -358,12 +359,12 @@ func randCommit() *Commit {
return commit
}
func hexBytesFromString(s string) cmn.HexBytes {
func hexBytesFromString(s string) bytes.HexBytes {
b, err := hex.DecodeString(s)
if err != nil {
panic(err)
}
return cmn.HexBytes(b)
return bytes.HexBytes(b)
}
func TestBlockMaxDataBytes(t *testing.T) {
@ -559,10 +560,10 @@ func TestSignedHeaderValidateBasic(t *testing.T) {
func TestBlockIDValidateBasic(t *testing.T) {
validBlockID := BlockID{
Hash: cmn.HexBytes{},
Hash: bytes.HexBytes{},
PartsHeader: PartSetHeader{
Total: 1,
Hash: cmn.HexBytes{},
Hash: bytes.HexBytes{},
},
}
@ -570,13 +571,13 @@ func TestBlockIDValidateBasic(t *testing.T) {
Hash: []byte{0},
PartsHeader: PartSetHeader{
Total: -1,
Hash: cmn.HexBytes{},
Hash: bytes.HexBytes{},
},
}
testCases := []struct {
testName string
blockIDHash cmn.HexBytes
blockIDHash bytes.HexBytes
blockIDPartsHeader PartSetHeader
expectErr bool
}{


+ 3
- 3
types/canonical.go View File

@ -3,7 +3,7 @@ package types
import (
"time"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -13,12 +13,12 @@ import (
const TimeFormat = time.RFC3339Nano
type CanonicalBlockID struct {
Hash cmn.HexBytes
Hash bytes.HexBytes
PartsHeader CanonicalPartSetHeader
}
type CanonicalPartSetHeader struct {
Hash cmn.HexBytes
Hash bytes.HexBytes
Total int
}


+ 2
- 1
types/genesis.go View File

@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"
"github.com/tendermint/tendermint/crypto"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -39,7 +40,7 @@ type GenesisDoc struct {
ChainID string `json:"chain_id"`
ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"`
Validators []GenesisValidator `json:"validators,omitempty"`
AppHash cmn.HexBytes `json:"app_hash"`
AppHash tmbytes.HexBytes `json:"app_hash"`
AppState json.RawMessage `json:"app_state,omitempty"`
}


+ 6
- 5
types/part_set.go View File

@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/tendermint/tendermint/crypto/merkle"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
cmn "github.com/tendermint/tendermint/libs/common"
)
@ -19,7 +20,7 @@ var (
type Part struct {
Index int `json:"index"`
Bytes cmn.HexBytes `json:"bytes"`
Bytes tmbytes.HexBytes `json:"bytes"`
Proof merkle.SimpleProof `json:"proof"`
}
@ -47,7 +48,7 @@ func (part *Part) StringIndented(indent string) string {
%s Proof: %v
%s}`,
part.Index,
indent, cmn.Fingerprint(part.Bytes),
indent, tmbytes.Fingerprint(part.Bytes),
indent, part.Proof.StringIndented(indent+" "),
indent)
}
@ -55,12 +56,12 @@ func (part *Part) StringIndented(indent string) string {
//-------------------------------------
type PartSetHeader struct {
Total int `json:"total"`
Hash cmn.HexBytes `json:"hash"`
Total int `json:"total"`
Hash tmbytes.HexBytes `json:"hash"`
}
func (psh PartSetHeader) String() string {
return fmt.Sprintf("%v:%X", psh.Total, cmn.Fingerprint(psh.Hash))
return fmt.Sprintf("%v:%X", psh.Total, tmbytes.Fingerprint(psh.Hash))
}
func (psh PartSetHeader) IsZero() bool {


+ 2
- 2
types/proposal.go View File

@ -5,7 +5,7 @@ import (
"fmt"
"time"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
tmtime "github.com/tendermint/tendermint/types/time"
)
@ -83,7 +83,7 @@ func (p *Proposal) String() string {
p.Round,
p.BlockID,
p.POLRound,
cmn.Fingerprint(p.Signature),
bytes.Fingerprint(p.Signature),
CanonicalTime(p.Timestamp))
}


+ 3
- 3
types/results.go View File

@ -3,7 +3,7 @@ package types
import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/bytes"
)
//-----------------------------------------------------------------------------
@ -12,8 +12,8 @@ import (
// TODO: add tags and other fields
// https://github.com/tendermint/tendermint/issues/1007
type ABCIResult struct {
Code uint32 `json:"code"`
Data cmn.HexBytes `json:"data"`
Code uint32 `json:"code"`
Data bytes.HexBytes `json:"data"`
}
// Bytes returns the amino encoded ABCIResult


+ 2
- 2
types/tx.go View File

@ -10,7 +10,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
)
// Tx is an arbitrary byte array.
@ -83,7 +83,7 @@ func (txs Txs) Proof(i int) TxProof {
// TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree.
type TxProof struct {
RootHash cmn.HexBytes `json:"root_hash"`
RootHash tmbytes.HexBytes `json:"root_hash"`
Data Tx `json:"data"`
Proof merkle.SimpleProof `json:"proof"`
}


+ 4
- 4
types/vote.go View File

@ -7,7 +7,7 @@ import (
"time"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
)
const (
@ -110,13 +110,13 @@ func (vote *Vote) String() string {
return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X @ %s}",
vote.ValidatorIndex,
cmn.Fingerprint(vote.ValidatorAddress),
tmbytes.Fingerprint(vote.ValidatorAddress),
vote.Height,
vote.Round,
vote.Type,
typeString,
cmn.Fingerprint(vote.BlockID.Hash),
cmn.Fingerprint(vote.Signature),
tmbytes.Fingerprint(vote.BlockID.Hash),
tmbytes.Fingerprint(vote.Signature),
CanonicalTime(vote.Timestamp),
)
}


Loading…
Cancel
Save