Correctly count unconfirmed txs in api GetAddress and GetXpub

pull/133/head
Martin Boehm 2019-03-06 17:23:06 +01:00
parent 3d10d9c2c5
commit 3df1cc81ed
2 changed files with 15 additions and 11 deletions

View File

@ -657,6 +657,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco
uBalSat big.Int
totalReceived, totalSent *big.Int
nonce string
unconfirmedTxs int
nonTokenTxs int
totalResults int
)
@ -705,6 +706,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco
} else {
// skip already confirmed txs, mempool may be out of sync
if tx.Confirmations == 0 {
unconfirmedTxs++
uBalSat.Add(&uBalSat, tx.getAddrVoutValue(addrDesc))
uBalSat.Sub(&uBalSat, tx.getAddrVinValue(addrDesc))
if page == 0 {
@ -763,7 +765,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco
Txs: int(ba.Txs),
NonTokenTxs: nonTokenTxs,
UnconfirmedBalanceSat: (*Amount)(&uBalSat),
UnconfirmedTxs: len(txm),
UnconfirmedTxs: unconfirmedTxs,
Transactions: txs,
Txids: txids,
Tokens: tokens,

View File

@ -367,15 +367,16 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
inputOutput byte
}
var (
txc xpubTxids
txmMap map[string]*Tx
txCount int
txs []*Tx
txids []string
pg Paging
filtered bool
err error
uBalSat big.Int
txc xpubTxids
txmMap map[string]*Tx
txCount int
txs []*Tx
txids []string
pg Paging
filtered bool
err error
uBalSat big.Int
unconfirmedTxs int
)
data, bestheight, err := w.getXpubData(xpub, page, txsOnPage, option, filter, gap)
if err != nil {
@ -426,6 +427,7 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
}
// skip already confirmed txs, mempool may be out of sync
if tx.Confirmations == 0 {
unconfirmedTxs++
uBalSat.Add(&uBalSat, tx.getAddrVoutValue(ad.addrDesc))
uBalSat.Sub(&uBalSat, tx.getAddrVinValue(ad.addrDesc))
if page == 0 && !foundTx && (useTxids == nil || useTxids(&txid, ad)) {
@ -529,7 +531,7 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
TotalSentSat: (*Amount)(&data.sentSat),
Txs: txCount,
UnconfirmedBalanceSat: (*Amount)(&uBalSat),
UnconfirmedTxs: len(txmMap),
UnconfirmedTxs: unconfirmedTxs,
Transactions: txs,
Txids: txids,
TotalTokens: totalTokens,