mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
30 lines
865 B
Go
30 lines
865 B
Go
package light_client
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
fieldparams "github.com/OffchainLabs/prysm/v7/config/fieldparams"
|
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
|
)
|
|
|
|
type branchConstraint interface {
|
|
[4][fieldparams.RootLength]byte | [5][fieldparams.RootLength]byte | [6][fieldparams.RootLength]byte | [7][fieldparams.RootLength]byte
|
|
}
|
|
|
|
func createBranch[T branchConstraint](name string, input [][]byte, depth int) (T, error) {
|
|
var zero T
|
|
|
|
if len(input) != depth {
|
|
return zero, fmt.Errorf("%s branch has %d leaves instead of expected %d", name, len(input), depth)
|
|
}
|
|
var branch T
|
|
for i, leaf := range input {
|
|
if len(leaf) != fieldparams.RootLength {
|
|
return zero, fmt.Errorf("%s branch leaf at index %d has length %d instead of expected %d", name, i, len(leaf), fieldparams.RootLength)
|
|
}
|
|
branch[i] = bytesutil.ToBytes32(leaf)
|
|
}
|
|
|
|
return branch, nil
|
|
}
|