Files
evm/utils/bytes.go
T
zeekay 1d04d6d04f Update copyright headers to Lux Industries Inc 2025
Updated all copyright headers from "Lux Partners Limited" to "Lux Industries Inc" and updated the year to 2025 to reflect the new holding company structure.
2025-07-03 23:49:31 -04:00

45 lines
1.0 KiB
Go

// (c) 2021-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import "github.com/ethereum/go-ethereum/common"
// IncrOne increments bytes value by one
func IncrOne(bytes []byte) {
index := len(bytes) - 1
for index >= 0 {
if bytes[index] < 255 {
bytes[index]++
break
} else {
bytes[index] = 0
index--
}
}
}
// HashSliceToBytes serializes a []common.Hash into a tightly packed byte array.
func HashSliceToBytes(hashes []common.Hash) []byte {
bytes := make([]byte, common.HashLength*len(hashes))
for i, hash := range hashes {
copy(bytes[i*common.HashLength:], hash[:])
}
return bytes
}
// BytesToHashSlice packs [b] into a slice of hash values with zero padding
// to the right if the length of b is not a multiple of 32.
func BytesToHashSlice(b []byte) []common.Hash {
var (
numHashes = (len(b) + 31) / 32
hashes = make([]common.Hash, numHashes)
)
for i := range hashes {
start := i * common.HashLength
copy(hashes[i][:], b[start:])
}
return hashes
}