Use hex package to convert bytes to string (#6205)

This commit is contained in:
Håvard Anda Estensen 2022-12-05 03:06:16 +01:00 committed by GitHub
parent daf2867194
commit 1398703bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 24 additions and 16 deletions

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/hex"
"fmt"
"os"
"strings"
@ -410,7 +411,7 @@ func kv2kv(ctx context.Context, src, dst kv.RwDB) error {
case <-ctx.Done():
return ctx.Err()
case <-commitEvery.C:
log.Info("Progress", "bucket", name, "progress", fmt.Sprintf("%.1fm/%.1fm", float64(i)/1_000_000, float64(total)/1_000_000), "key", fmt.Sprintf("%x", k))
log.Info("Progress", "bucket", name, "progress", fmt.Sprintf("%.1fm/%.1fm", float64(i)/1_000_000, float64(total)/1_000_000), "key", hex.EncodeToString(k))
if err2 := dstTx.Commit(); err2 != nil {
return err2
}

View File

@ -17,6 +17,7 @@
package asm
import (
"encoding/hex"
"fmt"
"math/big"
"os"
@ -109,9 +110,9 @@ func (c *Compiler) Compile() (string, []error) {
for _, v := range c.binary {
switch v := v.(type) {
case vm.OpCode:
bin += fmt.Sprintf("%x", []byte{byte(v)})
bin += hex.EncodeToString([]byte{byte(v)})
case []byte:
bin += fmt.Sprintf("%x", v)
bin += hex.EncodeToString(v)
}
}
return bin, errors

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"math/bits"
"time"
@ -66,7 +67,7 @@ func Trie(db kv.RoDB, tx kv.Tx, slowChecks bool, ctx context.Context) {
case <-quit:
return
case <-logEvery.C:
log.Info("trie account integrity", "key", fmt.Sprintf("%x", k))
log.Info("trie account integrity", "key", hex.EncodeToString(k))
}
hasState, hasTree, hasHash, hashes, _ := trie.UnmarshalTrieNode(v)
@ -180,7 +181,7 @@ func Trie(db kv.RoDB, tx kv.Tx, slowChecks bool, ctx context.Context) {
case <-quit:
return
case <-logEvery.C:
log.Info("trie storage integrity", "key", fmt.Sprintf("%x", k))
log.Info("trie storage integrity", "key", hex.EncodeToString(k))
}
hasState, hasTree, hasHash, hashes, _ := trie.UnmarshalTrieNode(v)

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"runtime"
"time"
@ -464,7 +465,7 @@ func pruneCallTraces(tx kv.RwTx, logPrefix string, pruneTo uint64, ctx context.C
}
select {
case <-logEvery.C:
log.Info(fmt.Sprintf("[%s]", logPrefix), "table", kv.CallFromIndex, "key", fmt.Sprintf("%x", from))
log.Info(fmt.Sprintf("[%s]", logPrefix), "table", kv.CallFromIndex, "key", hex.EncodeToString(from))
case <-ctx.Done():
return libcommon.ErrStopped
default:
@ -496,7 +497,7 @@ func pruneCallTraces(tx kv.RwTx, logPrefix string, pruneTo uint64, ctx context.C
}
select {
case <-logEvery.C:
log.Info(fmt.Sprintf("[%s]", logPrefix), "table", kv.CallToIndex, "key", fmt.Sprintf("%x", to))
log.Info(fmt.Sprintf("[%s]", logPrefix), "table", kv.CallToIndex, "key", hex.EncodeToString(to))
case <-ctx.Done():
return libcommon.ErrStopped
default:

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"runtime"
@ -446,7 +447,7 @@ func pruneHistoryIndex(tx kv.RwTx, csTable, logPrefix, tmpDir string, pruneTo ui
if err := collector.Load(tx, "", func(addr, _ []byte, table etl.CurrentTableReader, next etl.LoadNextFunc) error {
select {
case <-logEvery.C:
log.Info(fmt.Sprintf("[%s]", logPrefix), "table", changeset.Mapper[csTable].IndexBucket, "key", fmt.Sprintf("%x", addr))
log.Info(fmt.Sprintf("[%s]", logPrefix), "table", changeset.Mapper[csTable].IndexBucket, "key", hex.EncodeToString(addr))
case <-ctx.Done():
return libcommon.ErrStopped
default:

View File

@ -196,7 +196,7 @@ func (n ID) Bytes() []byte {
// ID prints as a long hexadecimal number.
func (n ID) String() string {
return fmt.Sprintf("%x", n[:])
return hex.EncodeToString(n[:])
}
// The Go syntax representation of a ID is a call to HexID.

View File

@ -174,7 +174,7 @@ func (n *Node) URLv4() string {
n.Load((*Secp256k1)(&key))
switch {
case scheme == "v4" || key != ecdsa.PublicKey{}:
nodeid = fmt.Sprintf("%x", crypto.MarshalPubkey(&key))
nodeid = hex.EncodeToString(crypto.MarshalPubkey(&key))
default:
nodeid = fmt.Sprintf("%s.%x", scheme, n.id[:])
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"io"
@ -571,7 +572,7 @@ func (ff *Filters) OnNewTx(reply *txpool.OnAddReply) {
txs[i], decodeErr = types.DecodeTransaction(s)
if decodeErr != nil {
// ignoring what we can't unmarshal
log.Warn("OnNewTx rpc filters, unprocessable payload", "err", decodeErr, "data", fmt.Sprintf("%x", rlpTx))
log.Warn("OnNewTx rpc filters, unprocessable payload", "err", decodeErr, "data", hex.EncodeToString(rlpTx))
break
}
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"os"
@ -1595,7 +1596,7 @@ func DumpBodies(ctx context.Context, db kv.RoDB, segmentFilePath, tmpDir string,
return false, err
}
if dataRLP == nil {
log.Warn("header missed", "block_num", blockNum, "hash", fmt.Sprintf("%x", v))
log.Warn("header missed", "block_num", blockNum, "hash", hex.EncodeToString(v))
return true, nil
}

View File

@ -188,9 +188,9 @@ func TraceTx(
stream.WriteBool(result.Failed())
stream.WriteMore()
// If the result contains a revert reason, return it.
returnVal := fmt.Sprintf("%x", result.Return())
returnVal := hex.EncodeToString(result.Return())
if len(result.Revert()) > 0 {
returnVal = fmt.Sprintf("%x", result.Revert())
returnVal = hex.EncodeToString(result.Revert())
}
stream.WriteObjectField("returnValue")
stream.WriteString(returnVal)

View File

@ -3,6 +3,7 @@ package trie
import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"math/bits"
"time"
@ -1504,9 +1505,9 @@ func makeCurrentKeyStr(k []byte) string {
if k == nil {
currentKeyStr = "final"
} else if len(k) < 4 {
currentKeyStr = fmt.Sprintf("%x", k)
currentKeyStr = hex.EncodeToString(k)
} else {
currentKeyStr = fmt.Sprintf("%x...", k[:4])
currentKeyStr = hex.EncodeToString(k[:4])
}
return currentKeyStr
}