Skip to content

Commit

Permalink
feat(BUX-250): logging and returning more descriptive errors from tx …
Browse files Browse the repository at this point in the history
…processing
  • Loading branch information
kuba-4chain committed Nov 6, 2023
1 parent 8fb5e63 commit 53134c6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server/p2p_receive_transaction_request_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package server

import (
"context"
"fmt"
"log"
"net/http"

"github.com/bitcoin-sv/go-paymail"
"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/julienschmidt/httprouter"
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"

"github.com/bitcoin-sv/go-paymail"
)

type p2pReceiveTxReqPayload struct {
Expand Down Expand Up @@ -67,13 +70,17 @@ func getProcessedTxData(payload *p2pReceiveTxReqPayload, format p2pPayloadFormat
case basicP2pPayload:
processedTx, err = bitcoin.TxFromHex(payload.Hex)
if err != nil {
return nil, nil, &processingError{&parseError{ErrorInvalidParameter, "invalid parameter: hex"}, http.StatusBadRequest}
errorMsg := fmt.Sprintf("error while parsing hex: %s", err.Error())
log.Println(errorMsg)
return nil, nil, &processingError{&parseError{ErrorInvalidParameter, errorMsg}, http.StatusBadRequest}
}

case beefP2pPayload:
beefData, err = paymail.DecodeBEEF(payload.Beef)
if err != nil {
return nil, nil, &processingError{&parseError{ErrorInvalidParameter, "invalid parameter: beef"}, http.StatusBadRequest}
errorMsg := fmt.Sprintf("error while parsing beef: %s", err.Error())
log.Println(errorMsg)
return nil, nil, &processingError{&parseError{ErrorInvalidParameter, errorMsg}, http.StatusBadRequest}
}

processedTx = beefData.ProcessedTxData.Transaction
Expand Down

0 comments on commit 53134c6

Please sign in to comment.