Skip to content

Commit d5a7bfc

Browse files
committed
fix sendrawtransaction error response.
1 parent 652fd07 commit d5a7bfc

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

main.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,7 @@ func main() {
144144
func(p *plugin.Plugin, params plugin.Params) (resp interface{}, errCode int, err error) {
145145
hex := params.Get("tx").String()
146146

147-
srtresp, err := sendRawTransaction(hex)
148-
if err != nil {
149-
p.Logf("failed to publish transaction %s: %s", hex, err.Error())
150-
return nil, 21, err
151-
}
152-
153-
return srtresp, 0, nil
147+
return sendRawTransaction(hex), 0, nil
154148
},
155149
}, {
156150
"getutxout",

sendtransaction.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ type RawTransactionResponse struct {
1414
ErrMsg string `json:"errmsg"`
1515
}
1616

17-
func sendRawTransaction(txHex string) (resp RawTransactionResponse, err error) {
17+
func sendRawTransaction(txHex string) (resp RawTransactionResponse) {
1818
// try bitcoind first
1919
if bitcoind != nil {
2020
tx := &wire.MsgTx{}
2121
if txBytes, err := hex.DecodeString(txHex); err == nil {
2222
txBuf := bytes.NewBuffer(txBytes)
2323
if err := tx.BtcDecode(txBuf, wire.ProtocolVersion, wire.WitnessEncoding); err == nil {
2424
if _, err := bitcoind.SendRawTransaction(tx, true); err == nil {
25-
return RawTransactionResponse{true, ""}, nil
25+
return RawTransactionResponse{true, ""}
2626
}
2727
}
2828
}
@@ -31,9 +31,9 @@ func sendRawTransaction(txHex string) (resp RawTransactionResponse, err error) {
3131
// then try explorers
3232
tx := bytes.NewBufferString(txHex)
3333
for _, endpoint := range esploras(network) {
34-
w, errW := http.Post(endpoint+"/tx", "text/plain", tx)
35-
if errW != nil {
36-
err = errW
34+
w, err := http.Post(endpoint+"/tx", "text/plain", tx)
35+
if err != nil {
36+
resp = RawTransactionResponse{false, err.Error()}
3737
continue
3838
}
3939
defer w.Body.Close()
@@ -45,8 +45,8 @@ func sendRawTransaction(txHex string) (resp RawTransactionResponse, err error) {
4545
continue
4646
}
4747

48-
return RawTransactionResponse{true, ""}, nil
48+
return RawTransactionResponse{true, ""}
4949
}
5050

51-
return resp, err
51+
return resp
5252
}

0 commit comments

Comments
 (0)