getSnapshotRPC returns the raw protobuf snapshot at the provided height. Non-generators can call this endpoint to get raw data that they can use to populate their own snapshot table. This handler doesn't use the httpjson.Handler format so that it can return raw protobuf bytes on the wire.
(rw http.ResponseWriter, req *http.Request)
| 49 | // This handler doesn't use the httpjson.Handler format so that it can return |
| 50 | // raw protobuf bytes on the wire. |
| 51 | func (a *API) getSnapshotRPC(rw http.ResponseWriter, req *http.Request) { |
| 52 | if a.config == nil { |
| 53 | alwaysError(errUnconfigured).ServeHTTP(rw, req) |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | var height uint64 |
| 58 | err := json.NewDecoder(req.Body).Decode(&height) |
| 59 | if err != nil { |
| 60 | errorFormatter.Write(req.Context(), rw, httpjson.ErrBadRequest) |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | data, err := a.store.GetSnapshot(req.Context(), height) |
| 65 | if err != nil { |
| 66 | errorFormatter.Write(req.Context(), rw, err) |
| 67 | return |
| 68 | } |
| 69 | rw.Header().Set("Content-Type", "application/x-protobuf") |
| 70 | rw.Write(data) |
| 71 | } |
nothing calls this directly
no test coverage detected