MCPcopy Create free account
hub / github.com/cairoeth/preconfirmations / process

Method process

rpc/server/request_handler.go:50–112  ·  view source on GitHub ↗

nolint

()

Source from the content-addressed store, hash-verified

48
49// nolint
50func (r *RPCRequestHandler) process() {
51 // r.logger = r.logger.With("uid", r.uid)
52 r.logger.Info("[process] POST request received")
53
54 defer r.finishRequest()
55 r.requestRecord.requestEntry.ReceivedAt = r.timeStarted
56 r.requestRecord.requestEntry.ID = r.uid
57 r.requestRecord.UpdateRequestEntry(r.req, http.StatusOK, "")
58
59 whitehatBundleID := r.req.URL.Query().Get("bundle")
60 isWhitehatBundleCollection := whitehatBundleID != ""
61
62 origin := r.req.Header.Get("Origin")
63 referer := r.req.Header.Get("Referer")
64
65 // If users specify a proxy url in their rpc endpoint they can have their requests proxied to that endpoint instead of Infura
66 // e.g. https://rpc.flashbots.net?url=http://RPC-ENDPOINT.COM
67 customProxyURL, ok := r.req.URL.Query()["url"]
68 if ok && len(customProxyURL[0]) > 1 {
69 r.defaultProxyURL = customProxyURL[0]
70 r.logger.Info("[process] Using custom url", zap.String("url", r.defaultProxyURL))
71 }
72
73 // Decode request JSON RPC
74 defer r.req.Body.Close()
75 body, err := io.ReadAll(r.req.Body)
76 if err != nil {
77 r.requestRecord.UpdateRequestEntry(r.req, http.StatusBadRequest, err.Error())
78 r.logger.Error("[process] Failed to read request body", zap.Error(err))
79 (*r.respw).WriteHeader(http.StatusBadRequest)
80 return
81 }
82
83 if len(body) == 0 {
84 r.requestRecord.UpdateRequestEntry(r.req, http.StatusBadRequest, "empty request body")
85 (*r.respw).WriteHeader(http.StatusBadRequest)
86 return
87 }
88
89 // create rpc proxy client for making proxy request
90 client := NewRPCProxyClient(r.logger, r.defaultProxyURL, r.proxyTimeoutSeconds)
91
92 r.requestRecord.UpdateRequestEntry(r.req, http.StatusOK, "") // Data analytics
93
94 // Parse JSON RPC payload
95 var jsonReq *types.JSONRPCRequest
96 if err = json.Unmarshal(body, &jsonReq); err != nil {
97 r.logger.Warn("[process] Parse payload", zap.Error(err))
98 (*r.respw).WriteHeader(http.StatusBadRequest)
99 return
100 }
101
102 // mev-share parameters
103 urlParams, err := ExtractParametersFromURL(r.req.URL, r.builderNames)
104 if err != nil {
105 r.logger.Warn("[process] Invalid auction preference", zap.Error(err))
106 res := AuctionPreferenceErrorToJSONRPCResponse(jsonReq, err)
107 r._writeRPCResponse(res)

Callers 1

HandleHTTPRequestMethod · 0.95

Calls 10

finishRequestMethod · 0.95
_writeRPCResponseMethod · 0.95
processRequestMethod · 0.95
NewRPCProxyClientFunction · 0.85
ExtractParametersFromURLFunction · 0.85
UpdateRequestEntryMethod · 0.80
StringMethod · 0.80
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected