mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 22:13:47 +00:00
Cleanup, lint, and enable linters for consenssus/bor module. Disabled linter "gomnd" and "tagliatelle" because they are not easy to fix and the return on the time investment is very low. Disabled linter "prealloc" because it is not easy to guess and pre-allocate the slice accurately in many cases.
52 lines
797 B
Go
52 lines
797 B
Go
package bor
|
|
|
|
func appendBytes32(data ...[]byte) []byte {
|
|
var result []byte
|
|
|
|
for _, v := range data {
|
|
paddedV := convertTo32(v)
|
|
result = append(result, paddedV[:]...)
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func nextPowerOfTwo(n uint64) uint64 {
|
|
if n == 0 {
|
|
return 1
|
|
}
|
|
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
|
n--
|
|
n |= n >> 1
|
|
n |= n >> 2
|
|
n |= n >> 4
|
|
n |= n >> 8
|
|
n |= n >> 16
|
|
n |= n >> 32
|
|
n++
|
|
|
|
return n
|
|
}
|
|
|
|
func convertTo32(input []byte) (output [32]byte) {
|
|
l := len(input)
|
|
if l > 32 || l == 0 {
|
|
return
|
|
}
|
|
|
|
copy(output[32-l:], input[:])
|
|
|
|
return
|
|
}
|
|
|
|
func convert(input []([32]byte)) [][]byte {
|
|
var output [][]byte
|
|
|
|
for _, in := range input {
|
|
newInput := make([]byte, len(in[:]))
|
|
copy(newInput, in[:])
|
|
output = append(output, newInput)
|
|
}
|
|
|
|
return output
|
|
}
|