diff --git a/db/dcrpg/pgblockchain.go b/db/dcrpg/pgblockchain.go index cad3cd3a96..cdd4504787 100644 --- a/db/dcrpg/pgblockchain.go +++ b/db/dcrpg/pgblockchain.go @@ -610,8 +610,12 @@ func (pgb *ChainDB) AddressHistory(address string, N, offset int64, return addressRows, nil, fmt.Errorf("ReduceAddressHistory failed. len(addressRows) = %d", len(addressRows)) } - // N is a limit on NumFundingTxns, so this checks if we have them all. - if addrInfo.NumFundingTxns < N && offset == 0 && txnType == dbtypes.AddrTxnAll { + // You've got all transactions only when the number of funding transactions + // fetched is equivalent to the number of spending transactions fetched too. + // Or When the total number of fetched transactions is less than the limit + // txtype is AddrTxnAll. Offset ought to be zero for all cases. + if offset == 0 && (addrInfo.NumFundingTxns == addrInfo.NumSpendingTxns || + (addrInfo.NumTransactions < N && txnType == dbtypes.AddrTxnAll)) { balanceInfo = explorer.AddressBalance{ Address: address, NumSpent: addrInfo.NumSpendingTxns, diff --git a/explorer/explorertypes.go b/explorer/explorertypes.go index 78f9144151..b725795990 100644 --- a/explorer/explorertypes.go +++ b/explorer/explorertypes.go @@ -389,14 +389,16 @@ func ReduceAddressHistory(addrHist []*dbtypes.AddressRow) *AddressInfo { transactions = append(transactions, &tx) } + var fundingTxs, spendingTxs = int64(len(creditTxns)), int64(len(debitTxns)) return &AddressInfo{ Address: addrHist[0].Address, Transactions: transactions, TxnsFunding: creditTxns, TxnsSpending: debitTxns, - NumFundingTxns: int64(len(creditTxns)), - NumSpendingTxns: int64(len(debitTxns)), + NumTransactions: fundingTxs +spendingTxs, + NumFundingTxns: fundingTxs, + NumSpendingTxns: spendingTxs, AmountReceived: dcrutil.Amount(received), AmountSent: dcrutil.Amount(sent), AmountUnspent: dcrutil.Amount(received - sent),