Skip to content

Commit

Permalink
common: remove usage of deprecated function (ethereum#21610)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Dec 19, 2024
1 parent ee0def0 commit cc9c918
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 29 deletions.
6 changes: 3 additions & 3 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"fmt"
"log"
"math/big"
"reflect"
"strings"
"testing"

"reflect"

"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/common/math"
"github.com/XinFinOrg/XDPoSChain/crypto"
)
Expand Down Expand Up @@ -712,7 +712,7 @@ func TestABI_MethodById(t *testing.T) {
}
b := fmt.Sprintf("%v", m2)
if a != b {
t.Errorf("Method %v (id %v) not 'findable' by id in ABI", name, common.ToHex(m.Id()))
t.Errorf("Method %v (id %v) not 'findable' by id in ABI", name, hexutil.Encode(m.Id()))
}
}

Expand Down
16 changes: 3 additions & 13 deletions common/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@
// Package common contains various helper functions.
package common

import "encoding/hex"

// ToHex returns the hex representation of b, prefixed with '0x'.
// For empty slices, the return value is "0x0".
//
// Deprecated: use hexutil.Encode instead.
func ToHex(b []byte) string {
hex := Bytes2Hex(b)
if len(hex) == 0 {
hex = "0"
}
return "0x" + hex
}
import (
"encoding/hex"
)

// FromHex returns the bytes represented by the hexadecimal string s.
// s may be prefixed with "0x".
Expand Down
3 changes: 2 additions & 1 deletion consensus/XDPoS/engines/engine_v2/verifyHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/consensus"
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
"github.com/XinFinOrg/XDPoSChain/consensus/misc"
Expand Down Expand Up @@ -171,7 +172,7 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
for index, mn := range masterNodes {
log.Error("[verifyHeader] masternode list during validator verification", "Masternode Address", mn.Hex(), "index", index)
}
log.Error("[verifyHeader] Error while verifying header validator signature", "BlockNumber", header.Number, "Hash", header.Hash().Hex(), "validator in hex", common.ToHex(header.Validator))
log.Error("[verifyHeader] Error while verifying header validator signature", "BlockNumber", header.Number, "Hash", header.Hash().Hex(), "validator in hex", hexutil.Encode(header.Validator))
return err
}
if !verified {
Expand Down
6 changes: 3 additions & 3 deletions contracts/blocksigner/blocksigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package blocksigner
import (
"context"
"math/big"
"math/rand"
"testing"
"time"

"math/rand"

"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind"
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/params"
Expand All @@ -50,7 +50,7 @@ func TestBlockSigner(t *testing.T) {
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, blockSignerAddress, nil)
t.Log("contract code", common.ToHex(code))
t.Log("contract code", hexutil.Encode(code))
f := func(key, val common.Hash) bool {
t.Log(key.Hex(), val.Hex())
return true
Expand Down
3 changes: 2 additions & 1 deletion contracts/randomize/randomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind"
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/contracts"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/core/types"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestRandomize(t *testing.T) {
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, randomizeAddress, nil)
t.Log("contract code", common.ToHex(code))
t.Log("contract code", hexutil.Encode(code))
f := func(key, val common.Hash) bool {
t.Log(key.Hex(), val.Hex())
return true
Expand Down
3 changes: 2 additions & 1 deletion contracts/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind"
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
contractValidator "github.com/XinFinOrg/XDPoSChain/contracts/validator/contract"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/core/state"
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestValidator(t *testing.T) {
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil)
t.Log("contract code", common.ToHex(code))
t.Log("contract code", hexutil.Encode(code))
f := func(key, val common.Hash) bool {
t.Log(key.Hex(), val.Hex())
return true
Expand Down
9 changes: 5 additions & 4 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/common/math"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/rlp"
Expand Down Expand Up @@ -513,7 +514,7 @@ func (tx *Transaction) IsSigningTransaction() bool {
if len(data) != (32*2 + 4) {
return false
}
method := common.ToHex(data[0:4])
method := hexutil.Encode(data[0:4])
return method == common.SignMethod
}

Expand All @@ -524,7 +525,7 @@ func (tx *Transaction) IsVotingTransaction() (bool, *common.Address) {
}
var end int
data := tx.Data()
method := common.ToHex(data[0:4])
method := hexutil.Encode(data[0:4])
if method == common.VoteMethod || method == common.ProposeMethod || method == common.ResignMethod {
end = len(data)
} else if method == common.UnvoteMethod {
Expand Down Expand Up @@ -558,7 +559,7 @@ func (tx *Transaction) IsXDCXApplyTransaction() bool {
if len(data) != (32 + 4) {
return false
}
method := common.ToHex(data[0:4])
method := hexutil.Encode(data[0:4])
return method == common.XDCXApplyMethod
}

Expand All @@ -581,7 +582,7 @@ func (tx *Transaction) IsXDCZApplyTransaction() bool {
if len(data) != (32 + 4) {
return false
}
method := common.ToHex(data[0:4])
method := hexutil.Encode(data[0:4])
return method == common.XDCZApplyMethod
}

Expand Down
6 changes: 3 additions & 3 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) er
if err != nil {
return err
}
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", common.ToHex(data))
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
}

func toBlockNumArg(number *big.Int) string {
Expand All @@ -550,7 +550,7 @@ func (ec *Client) SendOrderTransaction(ctx context.Context, tx *types.OrderTrans
if err != nil {
return err
}
return ec.c.CallContext(ctx, nil, "XDCx_sendOrderRawTransaction", common.ToHex(data))
return ec.c.CallContext(ctx, nil, "XDCx_sendOrderRawTransaction", hexutil.Encode(data))
}

// SendLendingTransaction send lending to pool
Expand All @@ -559,7 +559,7 @@ func (ec *Client) SendLendingTransaction(ctx context.Context, tx *types.LendingT
if err != nil {
return err
}
return ec.c.CallContext(ctx, nil, "XDCx_sendLendingRawTransaction", common.ToHex(data))
return ec.c.CallContext(ctx, nil, "XDCx_sendLendingRawTransaction", hexutil.Encode(data))
}

func toCallArg(msg ethereum.CallMsg) interface{} {
Expand Down

0 comments on commit cc9c918

Please sign in to comment.