mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
29513c804c
* bytesutil * gaz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
36 lines
804 B
Go
36 lines
804 B
Go
package stateutil
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
)
|
|
|
|
// HandleByteArrays computes and returns byte arrays in a slice of root format.
|
|
func HandleByteArrays(val [][]byte, indices []uint64, convertAll bool) ([][32]byte, error) {
|
|
length := len(indices)
|
|
if convertAll {
|
|
length = len(val)
|
|
}
|
|
roots := make([][32]byte, 0, length)
|
|
rootCreator := func(input []byte) {
|
|
newRoot := bytesutil.ToBytes32(input)
|
|
roots = append(roots, newRoot)
|
|
}
|
|
if convertAll {
|
|
for i := range val {
|
|
rootCreator(val[i])
|
|
}
|
|
return roots, nil
|
|
}
|
|
if len(val) > 0 {
|
|
for _, idx := range indices {
|
|
if idx > uint64(len(val))-1 {
|
|
return nil, fmt.Errorf("index %d greater than number of byte arrays %d", idx, len(val))
|
|
}
|
|
rootCreator(val[idx])
|
|
}
|
|
}
|
|
return roots, nil
|
|
}
|