MCPcopy
hub / github.com/OffchainLabs/prysm / SafeCopyRootAtIndex

Function SafeCopyRootAtIndex

encoding/bytesutil/bytes.go:61–72  ·  view source on GitHub ↗

SafeCopyRootAtIndex takes a copy of an 32-byte slice in a slice of byte slices. Returns error if index out of range.

(input [][]byte, idx uint64)

Source from the content-addressed store, hash-verified

59
60// SafeCopyRootAtIndex takes a copy of an 32-byte slice in a slice of byte slices. Returns error if index out of range.
61func SafeCopyRootAtIndex(input [][]byte, idx uint64) ([]byte, error) {
62 if input == nil {
63 return nil, nil
64 }
65
66 if uint64(len(input)) <= idx {
67 return nil, fmt.Errorf("index %d out of range", idx)
68 }
69 item := make([]byte, 32)
70 copy(item, input[idx])
71 return item, nil
72}
73
74// SafeCopyBytes will copy and return a non-nil byte slice, otherwise it returns nil.
75func SafeCopyBytes(cp []byte) []byte {

Callers 1

TestSafeCopyRootAtIndexFunction · 0.92

Calls 2

lenStruct · 0.85
ErrorfMethod · 0.65

Tested by 1

TestSafeCopyRootAtIndexFunction · 0.74