Avoid showing already confirmed txs as mempool txs

This commit is contained in:
Martin Boehm 2019-01-13 23:32:28 +01:00
parent c2a581ea72
commit 210652328f
2 changed files with 14 additions and 11 deletions

View File

@ -678,9 +678,11 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
for _, txid := range txm { for _, txid := range txm {
tx, err := w.GetTransaction(txid, false, false) tx, err := w.GetTransaction(txid, false, false)
// mempool transaction may fail // mempool transaction may fail
if err != nil { if err != nil || tx == nil {
glog.Error("GetTransaction in mempool ", tx, ": ", err) glog.Warning("GetTransaction in mempool: ", err)
} else { } else {
// skip already confirmed txs, mempool may be out of sync
if tx.Confirmations == 0 {
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 {
@ -693,6 +695,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
} }
} }
} }
}
// get confirmed transactions // get confirmed transactions
for i := from; i < to; i++ { for i := from; i < to; i++ {
txid := txc[i] txid := txc[i]

View File

@ -519,7 +519,7 @@ func (b *EthereumRPC) GetBlockInfo(hash string) (*bchain.BlockInfo, error) {
// It could be optimized for mempool, i.e. without block time and confirmations // It could be optimized for mempool, i.e. without block time and confirmations
func (b *EthereumRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) { func (b *EthereumRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) {
tx, err := b.GetTransaction(txid) tx, err := b.GetTransaction(txid)
// it there is an error getting the tx or the tx is confirmed, remove it from pending transactions // if there is an error getting the tx or the tx is confirmed, remove it from pending transactions
if err == bchain.ErrTxNotFound || (tx != nil && tx.Confirmations > 0) { if err == bchain.ErrTxNotFound || (tx != nil && tx.Confirmations > 0) {
b.pendingTransactionsLock.Lock() b.pendingTransactionsLock.Lock()
delete(b.pendingTransactions, txid) delete(b.pendingTransactions, txid)