Skip to content

Commit

Permalink
add default backup behavior (#2761)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com>
  • Loading branch information
trajan0x and trajan0x authored Jun 21, 2024
1 parent 7ac826a commit b189451
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions services/omnirpc/modules/receiptsbackup/receiptsbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ func (r *receiptsProxyImpl) ProxyRequest(c *gin.Context) (err error) {
}

func (r *receiptsProxyImpl) processRequest(ctx context.Context, rpcRequest rpc.Request, requestID []byte) (resp omniHTTP.Response, err error) {
req := r.client.NewRequest()
body, err := json.Marshal(rpcRequest)

//nolint: exhaustive
switch client.RPCMethod(rpcRequest.Method) {
case client.TransactionReceiptByHashMethod:
req := r.client.NewRequest()
body, err := json.Marshal(rpcRequest)
if err != nil {
return nil, errors.New("could not marshal request")
}
Expand Down Expand Up @@ -172,7 +173,22 @@ func (r *receiptsProxyImpl) processRequest(ctx context.Context, rpcRequest rpc.R
return nil, fmt.Errorf("could not get response from backup RPC %s: %w", r.proxyURL, err)
}
}
return resp, nil
default:
resp, err = req.
SetContext(ctx).
SetRequestURI(r.proxyURL).
SetBody(body).
SetHeaderBytes(omniHTTP.XRequestID, requestID).
SetHeaderBytes(omniHTTP.XForwardedFor, []byte(r.proxyURL)).
SetHeaderBytes(omniHTTP.ContentType, omniHTTP.JSONType).
SetHeaderBytes(omniHTTP.Accept, omniHTTP.JSONType).
Do()

if err != nil {
return nil, fmt.Errorf("could not get response from RPC %s: %w", r.proxyURL, err)
}

return resp, nil
}
return nil, nil
}

0 comments on commit b189451

Please sign in to comment.