electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 11f54aee60d6de3413812318b8cc826365a43051
parent 216d9e3c4db091ccccb0919b67022c65a9e55962
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu, 21 Nov 2019 17:21:54 +0100

qt utxo list: spend_list is now a set (and renamed)

this is a small performance improvement ("if x in spend_list" was linear)
and the "order" of selected coins does not matter anyway

Diffstat:
Melectrum/gui/qt/utxo_list.py | 20++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/electrum/gui/qt/utxo_list.py b/electrum/gui/qt/utxo_list.py @@ -23,7 +23,7 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from typing import Optional, List, Dict, Sequence +from typing import Optional, List, Dict, Sequence, Set from enum import IntEnum from PyQt5.QtCore import Qt @@ -58,7 +58,7 @@ class UTXOList(MyTreeView): super().__init__(parent, self.create_menu, stretch_column=self.Columns.LABEL, editable_columns=[]) - self.spend_list = [] # type: Sequence[str] + self._spend_set = set() # type: Set[str] # coins selected by the user to spend from self.setModel(QStandardItemModel(self)) self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSortingEnabled(True) @@ -75,12 +75,12 @@ class UTXOList(MyTreeView): self.insert_utxo(idx, utxo) self.filter() # update coincontrol status bar - coins = [self.utxo_dict[x] for x in self.spend_list] or utxos + coins = [self.utxo_dict[x] for x in self._spend_set] or utxos coins = self._filter_frozen_coins(coins) amount = sum(x.value_sats() for x in coins) amount_str = self.parent.format_amount_and_units(amount) num_outputs_str = _("{} outputs available ({} total)").format(len(coins), len(utxos)) - if self.spend_list: + if self._spend_set: self.parent.set_coincontrol_msg(_("Coin control active") + f': {num_outputs_str}, {amount_str}') else: self.parent.set_coincontrol_msg(None) @@ -101,7 +101,7 @@ class UTXOList(MyTreeView): utxo_item[self.Columns.OUTPOINT].setFont(QFont(MONOSPACE_FONT)) utxo_item[self.Columns.ADDRESS].setData(name, Qt.UserRole) SELECTED_TO_SPEND_TOOLTIP = _('Coin selected to be spent') - if name in self.spend_list: + if name in self._spend_set: for col in utxo_item: col.setBackground(ColorScheme.GREEN.as_color(True)) if col != self.Columns.OUTPOINT: @@ -113,7 +113,7 @@ class UTXOList(MyTreeView): utxo_item[self.Columns.OUTPOINT].setBackground(ColorScheme.BLUE.as_color(True)) utxo_item[self.Columns.OUTPOINT].setToolTip(f"{name}\n{_('Coin is frozen')}") else: - tooltip = ("\n" + SELECTED_TO_SPEND_TOOLTIP) if name in self.spend_list else "" + tooltip = ("\n" + SELECTED_TO_SPEND_TOOLTIP) if name in self._spend_set else "" utxo_item[self.Columns.OUTPOINT].setToolTip(name + tooltip) self.model().insertRow(idx, utxo_item) @@ -133,17 +133,17 @@ class UTXOList(MyTreeView): def set_spend_list(self, coins: List[PartialTxInput]): coins = self._filter_frozen_coins(coins) - self.spend_list = [utxo.prevout.to_str() for utxo in coins] + self._spend_set = {utxo.prevout.to_str() for utxo in coins} self.update() def get_spend_list(self) -> Sequence[PartialTxInput]: - return [self.utxo_dict[x] for x in self.spend_list] + return [self.utxo_dict[x] for x in self._spend_set] def _maybe_reset_spend_list(self, current_wallet_utxos: Sequence[PartialTxInput]) -> None: # if we spent one of the selected UTXOs, just reset selection utxo_set = {utxo.prevout.to_str() for utxo in current_wallet_utxos} - if not all([prevout_str in utxo_set for prevout_str in self.spend_list]): - self.spend_list = [] + if not all([prevout_str in utxo_set for prevout_str in self._spend_set]): + self._spend_set = set() def create_menu(self, position): selected = self.get_selected_outpoints()