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)
| 59 | |
| 60 | // SafeCopyRootAtIndex takes a copy of an 32-byte slice in a slice of byte slices. Returns error if index out of range. |
| 61 | func 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. |
| 75 | func SafeCopyBytes(cp []byte) []byte { |