Skip to content

Commit 4263f16

Browse files
wallet: properly calculate confirmations in GetTransaction
Fix bug where GetTransaction was setting confirmations to the block height instead of calculating them correctly. The formula should be: `confirmations = currentHeight - txBlockHeight + 1`
1 parent 3da75f7 commit 4263f16

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

wallet/wallet.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2597,14 +2597,18 @@ func (w *Wallet) GetTransaction(txHash chainhash.Hash) (*GetTransactionResult,
25972597
res = GetTransactionResult{
25982598
Summary: makeTxSummary(dbtx, w, txDetail),
25992599
Timestamp: txDetail.Block.Time.Unix(),
2600-
Confirmations: txDetail.Block.Height,
2600+
Confirmations: 0,
26012601
}
26022602

26032603
// If it is a confirmed transaction we set the corresponding
26042604
// block height and hash.
26052605
if txDetail.Block.Height != -1 {
26062606
res.Height = txDetail.Block.Height
26072607
res.BlockHash = &txDetail.Block.Hash
2608+
2609+
bestBlock := w.SyncedTo()
2610+
blockHeight := txDetail.Block.Height
2611+
res.Confirmations = bestBlock.Height - blockHeight + 1
26082612
}
26092613

26102614
return nil

0 commit comments

Comments
 (0)