Update types.go

This commit is contained in:
oxBoni 2025-11-21 21:51:32 +01:00 committed by GitHub
parent f4817b7a53
commit 7cac77ef06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,11 +23,13 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"hash"
"math/big" "math/big"
"math/rand" "math/rand"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"sync"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
@ -50,6 +52,11 @@ var (
// MaxHash represents the maximum possible hash value. // MaxHash represents the maximum possible hash value.
MaxHash = HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") MaxHash = HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
// keccak256Pool is a pool of Keccak256 hashers for address checksum calculation
keccak256Pool = sync.Pool{New: func() any {
return sha3.NewLegacyKeccak256()
}}
) )
// Hash represents the 32 byte Keccak256 hash of arbitrary data. // Hash represents the 32 byte Keccak256 hash of arbitrary data.
@ -271,8 +278,12 @@ func (a *Address) checksumHex() []byte {
buf := a.hex() buf := a.hex()
// compute checksum // compute checksum
sha := sha3.NewLegacyKeccak256() sha, ok := keccak256Pool.Get().(hash.Hash)
sha.Write(buf[2:]) if !ok {
sha = sha3.NewLegacyKeccak256()
}
defer keccak256Pool.Put(sha)
sha.Reset()
hash := sha.Sum(nil) hash := sha.Sum(nil)
for i := 2; i < len(buf); i++ { for i := 2; i < len(buf); i++ {
hashByte := hash[(i-2)/2] hashByte := hash[(i-2)/2]