Proxies the incoming request to the target URL, and tries to parse JSON-RPC response (and check for specific)
()
| 118 | |
| 119 | // Proxies the incoming request to the target URL, and tries to parse JSON-RPC response (and check for specific) |
| 120 | func (r *RPCRequest) proxyRequestRead() (readJSONRpsResponseSuccess bool) { |
| 121 | timeProxyStart := Now() // for measuring execution time |
| 122 | body, err := json.Marshal(r.jsonReq) |
| 123 | if err != nil { |
| 124 | r.logger.Error("[proxyRequestRead] Failed to marshal request before making proxy request", zap.Error(err)) |
| 125 | return false |
| 126 | } |
| 127 | |
| 128 | // Proxy request |
| 129 | proxyResp, err := r.client.ProxyRequest(body) |
| 130 | if err != nil { |
| 131 | r.logger.Error("[proxyRequestRead] Failed to make proxy request", zap.Error(err)) |
| 132 | if proxyResp == nil { |
| 133 | return false |
| 134 | } else { |
| 135 | return false |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // Afterwards, check time and result |
| 140 | timeProxyNeeded := time.Since(timeProxyStart) |
| 141 | r.logger.Info("[proxyRequestRead] proxied response", zap.Int("secNeeded", int(timeProxyNeeded.Seconds()))) |
| 142 | |
| 143 | // Read body |
| 144 | defer proxyResp.Body.Close() |
| 145 | proxyRespBody, err := io.ReadAll(proxyResp.Body) |
| 146 | if err != nil { |
| 147 | r.logger.Error("[proxyRequestRead] Failed to read proxy request body", zap.Error(err)) |
| 148 | return false |
| 149 | } |
| 150 | |
| 151 | // Unmarshall JSON-RPC response and check for error inside |
| 152 | jsonRPCResp := new(types.JSONRPCResponse) |
| 153 | if err = json.Unmarshal(proxyRespBody, jsonRPCResp); err != nil { |
| 154 | r.logger.Error("[proxyRequestRead] Failed decoding proxy json-rpc response", zap.Error(err)) |
| 155 | return false |
| 156 | } |
| 157 | r.jsonRes = jsonRPCResp |
| 158 | return true |
| 159 | } |
| 160 | |
| 161 | // Check whether to block resending this tx. Send only if (a) not sent before, (b) sent and status=failed, (c) sent, status=unknown and sent at least 5 min ago |
| 162 | func (r *RPCRequest) blockResendingTxToRelay(txHash string) bool { |
no test coverage detected