Correctly count unconfirmed txs in api GetAddress and GetXpub

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

View File

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