Browse Source

wallet_showutxos: use O(1) check for frozen instead of O(n)

utxo_d = []
	for k, v in disabled.items():
		utxo_d.append(k)

	{'frozen': True if u in utxo_d else False}

The above was inefficient. Replace with:

	{'frozen': u in disabled}

Checking for existence of a key in a dict takes time proportional to
O(1), whereas checking for existence of an element in a list takes time
proportional to O(n).
master
Matt Whitlock 2 years ago
parent
commit
fc1e00058b
  1. 5
      src/jmclient/wallet_utils.py

5
src/jmclient/wallet_utils.py

@ -431,9 +431,6 @@ def wallet_showutxos(wallet_service, showprivkey):
includeconfs=True)
for md in utxos:
(enabled, disabled) = get_utxos_enabled_disabled(wallet_service, md)
utxo_d = []
for k, v in disabled.items():
utxo_d.append(k)
for u, av in utxos[md].items():
success, us = utxo_to_utxostr(u)
assert success
@ -453,7 +450,7 @@ def wallet_showutxos(wallet_service, showprivkey):
'external': False,
'mixdepth': mixdepth,
'confirmations': av['confs'],
'frozen': True if u in utxo_d else False}
'frozen': u in disabled}
if showprivkey:
unsp[us]['privkey'] = wallet_service.get_wif_path(av['path'])
if locktime:

Loading…
Cancel
Save