diff --git a/background/background.go b/background/background.go index 8f5816a..598e4c6 100644 --- a/background/background.go +++ b/background/background.go @@ -94,8 +94,6 @@ func blockConnected() { for _, ticket := range pending { feeTxHash, err := dcrdClient.SendRawTransaction(ticket.FeeTxHex) if err != nil { - // TODO: SendRawTransaction can return a "transcation already - // exists" error, which isnt necessarily a problem here. log.Errorf("SendRawTransaction error: %v", err) continue } diff --git a/rpc/dcrd.go b/rpc/dcrd.go index 5902eaf..4bc6462 100644 --- a/rpc/dcrd.go +++ b/rpc/dcrd.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "errors" "fmt" + "strings" "sync" "github.com/decred/dcrd/blockchain/stake/v3" @@ -100,7 +101,24 @@ func (c *DcrdRPC) SendRawTransaction(txHex string) (string, error) { var txHash string err := c.Call(c.ctx, "sendrawtransaction", &txHash, txHex, allowHighFees) if err != nil { - return "", err + // It's not a problem if the transaction has already been broadcast, + // just need to calculate and return its hash. + if !strings.Contains(err.Error(), "transaction already exists") { + return "", err + } + + msgHex, err := hex.DecodeString(txHex) + if err != nil { + return "", fmt.Errorf("DecodeString error: %v", err) + + } + msgTx := wire.NewMsgTx() + if err = msgTx.FromBytes(msgHex); err != nil { + return "", fmt.Errorf("FromBytes error: %v", err) + + } + + txHash = msgTx.TxHash().String() } return txHash, nil } diff --git a/webapi/payfee.go b/webapi/payfee.go index b56111a..1438c79 100644 --- a/webapi/payfee.go +++ b/webapi/payfee.go @@ -215,8 +215,6 @@ findAddress: if ticket.Confirmed { feeTxHash, err := dcrdClient.SendRawTransaction(payFeeRequest.FeeTx) if err != nil { - // TODO: SendRawTransaction can return a "transcation already - // exists" error, which isnt necessarily a problem here. log.Errorf("SendRawTransaction failed: %v", err) sendErrorResponse("dcrwallet RPC error", http.StatusInternalServerError, c) return