Skip to content

Commit

Permalink
fix sendrawtransaction error response.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Apr 24, 2024
1 parent 652fd07 commit d5a7bfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
8 changes: 1 addition & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions sendtransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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{}
if txBytes, err := hex.DecodeString(txHex); err == nil {
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, ""}
}
}
}
Expand All @@ -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()
Expand All @@ -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
}

0 comments on commit d5a7bfc

Please sign in to comment.