From 53134c6ff353324f721a12a082b20d75b1df4360 Mon Sep 17 00:00:00 2001 From: Kuba Date: Mon, 6 Nov 2023 12:47:27 +0100 Subject: [PATCH] feat(BUX-250): logging and returning more descriptive errors from tx processing --- server/p2p_receive_transaction_request_processor.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/p2p_receive_transaction_request_processor.go b/server/p2p_receive_transaction_request_processor.go index 6de7fda..6a988da 100644 --- a/server/p2p_receive_transaction_request_processor.go +++ b/server/p2p_receive_transaction_request_processor.go @@ -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 { @@ -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