From d5a7bfc9bc792d3b98c3bea9dae57f8d7a3d4d99 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 23 Apr 2024 23:51:13 -0300 Subject: [PATCH] fix sendrawtransaction error response. --- main.go | 8 +------- sendtransaction.go | 14 +++++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index a2a6ac9..210c7e6 100644 --- a/main.go +++ b/main.go @@ -144,13 +144,7 @@ func main() { func(p *plugin.Plugin, params plugin.Params) (resp interface{}, errCode int, err error) { hex := params.Get("tx").String() - srtresp, err := sendRawTransaction(hex) - if err != nil { - p.Logf("failed to publish transaction %s: %s", hex, err.Error()) - return nil, 21, err - } - - return srtresp, 0, nil + return sendRawTransaction(hex), 0, nil }, }, { "getutxout", diff --git a/sendtransaction.go b/sendtransaction.go index f91e2d7..248ca61 100644 --- a/sendtransaction.go +++ b/sendtransaction.go @@ -14,7 +14,7 @@ type RawTransactionResponse struct { ErrMsg string `json:"errmsg"` } -func sendRawTransaction(txHex string) (resp RawTransactionResponse, err error) { +func sendRawTransaction(txHex string) (resp RawTransactionResponse) { // try bitcoind first if bitcoind != nil { tx := &wire.MsgTx{} @@ -22,7 +22,7 @@ func sendRawTransaction(txHex string) (resp RawTransactionResponse, err error) { txBuf := bytes.NewBuffer(txBytes) if err := tx.BtcDecode(txBuf, wire.ProtocolVersion, wire.WitnessEncoding); err == nil { if _, err := bitcoind.SendRawTransaction(tx, true); err == nil { - return RawTransactionResponse{true, ""}, nil + return RawTransactionResponse{true, ""} } } } @@ -31,9 +31,9 @@ func sendRawTransaction(txHex string) (resp RawTransactionResponse, err error) { // then try explorers tx := bytes.NewBufferString(txHex) for _, endpoint := range esploras(network) { - w, errW := http.Post(endpoint+"/tx", "text/plain", tx) - if errW != nil { - err = errW + w, err := http.Post(endpoint+"/tx", "text/plain", tx) + if err != nil { + resp = RawTransactionResponse{false, err.Error()} continue } defer w.Body.Close() @@ -45,8 +45,8 @@ func sendRawTransaction(txHex string) (resp RawTransactionResponse, err error) { continue } - return RawTransactionResponse{true, ""}, nil + return RawTransactionResponse{true, ""} } - return resp, err + return resp }