MCPcopy Create free account
hub / github.com/ethstorage/es-node / parseIndices

Function parseIndices

ethstorage/archiver/utils.go:101–131  ·  view source on GitHub ↗

parseIndices filters out invalid and duplicate blob indices

(r *http.Request, max int)

Source from the content-addressed store, hash-verified

99
100// parseIndices filters out invalid and duplicate blob indices
101func parseIndices(r *http.Request, max int) ([]uint64, *httpError) {
102 query := r.URL.Query()
103 normalizeQueryValues(query)
104 r.URL.RawQuery = query.Encode()
105 rawIndices := r.URL.Query()["indices"]
106 indices := make([]uint64, 0, max)
107 invalidIndices := make([]string, 0)
108loop:
109 for _, raw := range rawIndices {
110 ix, err := strconv.ParseUint(raw, 10, 64)
111 if err != nil {
112 invalidIndices = append(invalidIndices, raw)
113 continue
114 }
115 if max > 0 && ix >= uint64(max) {
116 invalidIndices = append(invalidIndices, raw)
117 continue
118 }
119 for i := range indices {
120 if ix == indices[i] {
121 continue loop
122 }
123 }
124 indices = append(indices, ix)
125 }
126
127 if len(invalidIndices) > 0 {
128 return nil, newBadRequestError(fmt.Sprintf("requested blob indices %v are invalid", invalidIndices))
129 }
130 return indices, nil
131}
132
133// normalizeQueryValues replaces comma-separated values with individual values
134func normalizeQueryValues(queryParams url.Values) {

Callers 2

Test_parseIndicesFunction · 0.85
blobSidecarHandlerMethod · 0.85

Calls 2

normalizeQueryValuesFunction · 0.85
newBadRequestErrorFunction · 0.85

Tested by 1

Test_parseIndicesFunction · 0.68