Browse Source

gettransaction called once per txid in monitor

See #772. This is likely a partial fix but that issue
may be more complex.
More generally, while we may have to process multiple
entries in the return of `listtransactions`, with the
same txid, because they may have different wallet labels,
we do not want to call `gettransaction` repeatedly on
the same txid in the same monitor loop call. Note however,
that we *do* need to call `gettransaction` again in
the next monitor loop, since the state (confirmations)
updates, so we cannot permanently cache those results.
Additionally removed redundant old_txs entries with set().
master
Adam Gibson 5 years ago
parent
commit
4c44932dee
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 14
      jmclient/jmclient/wallet_service.py

14
jmclient/jmclient/wallet_service.py

@ -309,11 +309,19 @@ class WalletService(Service):
if x['txid'] in self.active_txids or x['txid'] not in self.old_txs:
new_txs.append(x)
# reset for next polling event:
self.old_txs = [x['txid'] for x in txlist if "txid" in x]
self.old_txs = set(x['txid'] for x in txlist if "txid" in x)
# for this invocation of transaction_monitor, we *don't* want
# to call `gettransaction` more than once per txid, even if the
# `listtransactions` result has multiple instances for different
# wallet labels; so we use a temporary variable to cache.
gettx_results = {}
for tx in new_txs:
txid = tx["txid"]
res = self.bci.get_transaction(hextobin(txid))
if txid not in gettx_results:
res = self.bci.get_transaction(hextobin(txid))
gettx_results[txid] = res
else:
res = gettx_results[txid]
if not res:
continue
confs = res["confirmations"]

Loading…
Cancel
Save