mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
Update types.go
This commit is contained in:
parent
f4817b7a53
commit
7cac77ef06
1 changed files with 13 additions and 2 deletions
|
|
@ -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]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue