mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
core/types: simplify CalcRequestsHash
Co-authored-by: Shude Li <islishude@gmail.com>
This commit is contained in:
parent
f27902e05c
commit
b87d53679f
1 changed files with 8 additions and 17 deletions
|
|
@ -459,24 +459,15 @@ func CalcUncleHash(uncles []*Header) common.Hash {
|
|||
|
||||
// CalcRequestsHash creates the block requestsHash value for a list of requests.
|
||||
func CalcRequestsHash(requests [][]byte) common.Hash {
|
||||
// compute intermediate hashes
|
||||
hashes := make([][32]byte, len(requests))
|
||||
h := sha256.New()
|
||||
for i, item := range requests {
|
||||
h.Reset()
|
||||
h.Write(item)
|
||||
var sum [32]byte
|
||||
h.Sum(sum[:0])
|
||||
hashes[i] = sum
|
||||
h1, h2 := sha256.New(), sha256.New()
|
||||
var buf common.Hash
|
||||
for _, item := range requests {
|
||||
h1.Reset()
|
||||
h1.Write(item)
|
||||
h2.Write(h1.Sum(buf[:0]))
|
||||
}
|
||||
// final hash
|
||||
h.Reset()
|
||||
for _, hash := range hashes {
|
||||
h.Write(hash[:])
|
||||
}
|
||||
var result common.Hash
|
||||
h.Sum(result[:0])
|
||||
return result
|
||||
h2.Sum(buf[:0])
|
||||
return buf
|
||||
}
|
||||
|
||||
// NewBlockWithHeader creates a block with the given header data. The
|
||||
|
|
|
|||
Loading…
Reference in a new issue