Skip to content

Commit

Permalink
Return both error and success responses from a broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim-j committed Dec 6, 2023
1 parent 8814607 commit 59b62ef
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions flashbotsrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,11 @@ func (broadcaster *BuilderBroadcastRPC) BroadcastBundle(privKey *ecdsa.PrivateKe
for _, requestResponse := range requestResponses {
if requestResponse.Err != nil {
responses = append(responses, BuilderBroadcastResponse{Err: requestResponse.Err})
} else {
fbResponse := FlashbotsSendBundleResponse{}
err := json.Unmarshal(requestResponse.Msg, &fbResponse)
responses = append(responses, BuilderBroadcastResponse{BundleResponse: fbResponse, Err: err})
}
fbResponse := FlashbotsSendBundleResponse{}
err := json.Unmarshal(requestResponse.Msg, &fbResponse)
responses = append(responses, BuilderBroadcastResponse{BundleResponse: fbResponse, Err: err})
}

return responses
Expand Down Expand Up @@ -872,19 +873,28 @@ func (broadcaster *BuilderBroadcastRPC) broadcastRequest(method string, privKey
errorResp := new(RelayErrorResponse)
if err := json.Unmarshal(data, errorResp); err == nil && errorResp.Error != "" {
// relay returned an error
responseArr := []broadcastRequestResponse{{Msg: nil, Err: fmt.Errorf("%w: %s", ErrRelayErrorResponse, errorResp.Error)}}
return responseArr
responses = append(responses, broadcastRequestResponse{
Msg: nil,
Err: fmt.Errorf("%w: %s", ErrRelayErrorResponse, errorResp.Error),
})
continue
}

resp := new(rpcResponse)
if err := json.Unmarshal(data, resp); err != nil {
responseArr := []broadcastRequestResponse{{Msg: nil, Err: err}}
return responseArr
responses = append(responses, broadcastRequestResponse{
Msg: nil,
Err: err,
})
continue
}

if resp.Error != nil {
responseArr := []broadcastRequestResponse{{Msg: nil, Err: fmt.Errorf("%w: %s", ErrRelayErrorResponse, (*resp).Error.Message)}}
return responseArr
responses = append(responses, broadcastRequestResponse{
Msg: nil,
Err: fmt.Errorf("%w: %s", ErrRelayErrorResponse, (*resp).Error.Message),
})
continue
}

responses = append(responses, broadcastRequestResponse{
Expand Down

0 comments on commit 59b62ef

Please sign in to comment.