diff --git a/wallet/wallet.go b/wallet/wallet.go index ff95d1d1be..861585e2a6 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -2441,7 +2441,7 @@ func (w *Wallet) GetTransaction(txHash *chainhash.Hash) (*GetTransactionResult, // because not all block headers are saved but when they are for SPV the // db can be queried directly without this. var blockHash *chainhash.Hash - var height int32 = -1 + var endHeight int32 = -1 if txResult != nil && txResult.BlockHash != "" { blockHash, err = chainhash.NewHashFromStr(txResult.BlockHash) if err != nil { @@ -2455,9 +2455,9 @@ func (w *Wallet) GetTransaction(txHash *chainhash.Hash) (*GetTransactionResult, if err != nil { return nil, false, err } - height = header.Height + bestHeight = header.Height case *chain.BitcoindClient: - height, err = client.GetBlockHeight(blockHash) + bestHeight, err = client.GetBlockHeight(blockHash) if err != nil { return nil, false, err } @@ -2465,7 +2465,7 @@ func (w *Wallet) GetTransaction(txHash *chainhash.Hash) (*GetTransactionResult, // We know that the transaction definitively is in a specific // block height and set both start and end height to it. - bestHeight = height + endHeight = bestHeight } // Populate with additional data if this transaction exists in the @@ -2489,8 +2489,10 @@ func (w *Wallet) GetTransaction(txHash *chainhash.Hash) (*GetTransactionResult, // transaction and can return early. if txHash.IsEqual(dbTx.Hash) { summary, inDB = &dbTx, true - height = details[i].Block.Height - blockHash = &details[i].Block.Hash + if details[i].Block.Height != -1 { + bestHeight = details[i].Block.Height + blockHash = &details[i].Block.Hash + } return true, nil } } @@ -2498,7 +2500,7 @@ func (w *Wallet) GetTransaction(txHash *chainhash.Hash) (*GetTransactionResult, } return w.TxStore.RangeTransactions( - txmgrNs, bestHeight, height, rangeFn, + txmgrNs, bestHeight, endHeight, rangeFn, ) }) if err != nil { @@ -2535,7 +2537,7 @@ func (w *Wallet) GetTransaction(txHash *chainhash.Hash) (*GetTransactionResult, default: res.MinedTransaction = &Block{ Hash: blockHash, - Height: height, + Height: bestHeight, Timestamp: summary.Timestamp, Transactions: []TransactionSummary{*summary}, }