MCPcopy Create free account
hub / github.com/chain/Core / getSnapshotRPC

Method getSnapshotRPC

core/rpc.go:51–71  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

49// This handler doesn't use the httpjson.Handler format so that it can return
50// raw protobuf bytes on the wire.
51func (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}

Callers

nothing calls this directly

Calls 7

alwaysErrorFunction · 0.85
DecodeMethod · 0.80
GetSnapshotMethod · 0.80
HeaderMethod · 0.80
ServeHTTPMethod · 0.45
WriteMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected