Skip to content

Commit

Permalink
wallet: fix nil txid in publishTransaction
Browse files Browse the repository at this point in the history
A nil txid could've been returned from publishTransaction even if it was
successful. This was due to the underlying SendRawTransaction call
"failing", e.g., when the transaction being broadcast has already
confirmed, but publishTranasction interpreting such failure as a
success.
  • Loading branch information
wpaulino authored and cpacia committed Aug 21, 2019
1 parent 1548425 commit aed5511
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions wallet/wallet.go
Expand Up @@ -3385,7 +3385,7 @@ func (w *Wallet) publishTransaction(tx *wire.MsgTx) (*chainhash.Hash, error) {
return nil, err
}

txid, err := chainClient.SendRawTransaction(tx, false)
_, err = chainClient.SendRawTransaction(tx, false)

// Determine if this was an RPC error thrown due to the transaction
// already confirming.
Expand All @@ -3394,9 +3394,10 @@ func (w *Wallet) publishTransaction(tx *wire.MsgTx) (*chainhash.Hash, error) {
rpcTxConfirmed = rpcErr.Code == btcjson.ErrRPCTxAlreadyInChain
}

txid := tx.TxHash()
switch {
case err == nil:
return txid, nil
return &txid, nil

// Since we have different backends that can be used with the wallet,
// we'll need to check specific errors for each one.
Expand All @@ -3415,7 +3416,7 @@ func (w *Wallet) publishTransaction(tx *wire.MsgTx) (*chainhash.Hash, error) {
case strings.Contains(
strings.ToLower(err.Error()), "txn-already-in-mempool",
):
return txid, nil
return &txid, nil

// If the transaction has already confirmed, we can safely remove it
// from the unconfirmed store as it should already exist within the
Expand Down Expand Up @@ -3450,7 +3451,7 @@ func (w *Wallet) publishTransaction(tx *wire.MsgTx) (*chainhash.Hash, error) {
"from unconfirmed store: %v", tx.TxHash(), dbErr)
}

return txid, nil
return &txid, nil

// If the transaction was rejected for whatever other reason, then we'll
// remove it from the transaction store, as otherwise, we'll attempt to
Expand Down

0 comments on commit aed5511

Please sign in to comment.