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.
|
// CalcRequestsHash creates the block requestsHash value for a list of requests.
|
||||||
func CalcRequestsHash(requests [][]byte) common.Hash {
|
func CalcRequestsHash(requests [][]byte) common.Hash {
|
||||||
// compute intermediate hashes
|
h1, h2 := sha256.New(), sha256.New()
|
||||||
hashes := make([][32]byte, len(requests))
|
var buf common.Hash
|
||||||
h := sha256.New()
|
for _, item := range requests {
|
||||||
for i, item := range requests {
|
h1.Reset()
|
||||||
h.Reset()
|
h1.Write(item)
|
||||||
h.Write(item)
|
h2.Write(h1.Sum(buf[:0]))
|
||||||
var sum [32]byte
|
|
||||||
h.Sum(sum[:0])
|
|
||||||
hashes[i] = sum
|
|
||||||
}
|
}
|
||||||
// final hash
|
h2.Sum(buf[:0])
|
||||||
h.Reset()
|
return buf
|
||||||
for _, hash := range hashes {
|
|
||||||
h.Write(hash[:])
|
|
||||||
}
|
|
||||||
var result common.Hash
|
|
||||||
h.Sum(result[:0])
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBlockWithHeader creates a block with the given header data. The
|
// NewBlockWithHeader creates a block with the given header data. The
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue