tFixes for TrustedCoin plugin: - reset billing_info after broadcast - when bumping tx fee, do not use Trustedcoin output - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 777a3aa8bfe751c13873a272cea2c95215c9234d DIR parent 6b872b68bd322d71326600a1df70035b80da99ff HTML Author: ThomasV <thomasv@electrum.org> Date: Thu, 6 Jul 2017 16:03:21 +0200 Fixes for TrustedCoin plugin: - reset billing_info after broadcast - when bumping tx fee, do not use Trustedcoin output Diffstat: M gui/qt/main_window.py | 7 ++++--- M lib/wallet.py | 5 +++++ M plugins/trustedcoin/qt.py | 15 +++++---------- M plugins/trustedcoin/trustedcoin.py | 21 +++++++++++++++++++-- 4 files changed, 33 insertions(+), 15 deletions(-) --- DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py t@@ -1340,9 +1340,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): _("Mining fee") + ": " + self.format_amount_and_units(fee), ] - extra_fee = run_hook('get_additional_fee', self.wallet, tx) - if extra_fee: - msg.append( _("Additional fees") + ": " + self.format_amount_and_units(extra_fee) ) + x_fee = run_hook('get_tx_extra_fee', self.wallet, tx) + if x_fee: + x_fee_address, x_fee_amount = x_fee + msg.append( _("Additional fees") + ": " + self.format_amount_and_units(x_fee_amount) ) confirm_rate = 2 * self.config.max_fee_rate() if fee > confirm_rate * tx.estimated_size() / 1000: DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -1030,6 +1030,11 @@ class Abstract_Wallet(PrintError): # ... unless there is none if not s: s = outputs + x_fee = run_hook('get_tx_extra_fee', self, tx) + if x_fee: + x_fee_address, x_fee_amount = x_fee + s = filter(lambda x: x[1]!=x_fee_address, s) + # prioritize low value outputs, to get rid of dust s = sorted(s, key=lambda x: x[2]) for o in s: DIR diff --git a/plugins/trustedcoin/qt.py b/plugins/trustedcoin/qt.py t@@ -58,9 +58,7 @@ class Plugin(TrustedCoinPlugin): button = StatusBarButton(QIcon(":icons/trustedcoin-status.png"), _("TrustedCoin"), action) window.statusBar().addPermanentWidget(button) - t = Thread(target=self.request_billing_info, args=(wallet,)) - t.setDaemon(True) - t.start() + self.start_request_thread(window.wallet) def auth_dialog(self, window): d = WindowModalDialog(window, _("Authorization")) t@@ -102,13 +100,10 @@ class Plugin(TrustedCoinPlugin): wallet = window.wallet if not isinstance(wallet, self.wallet_class): return - if not wallet.can_sign_without_server(): - if wallet.billing_info is None: - # request billing info before forming the transaction - waiting_dialog(self, window).wait() - if wallet.billing_info is None: - window.show_message('Could not contact server') - return True + if wallet.can_sign_without_server(): + return + if wallet.billing_info is None: + return True return False DIR diff --git a/plugins/trustedcoin/trustedcoin.py b/plugins/trustedcoin/trustedcoin.py t@@ -237,6 +237,9 @@ class Wallet_2fa(Multisig_Wallet): def extra_fee(self, config): if self.can_sign_without_server(): return 0 + if self.billing_info is None: + self.plugin.start_request_thread(self) + return 0 if self.billing_info.get('tx_remaining'): return 0 if self.is_billing: t@@ -282,6 +285,8 @@ class Wallet_2fa(Multisig_Wallet): raw_tx = r.get('transaction') tx.update(raw_tx) self.print_error("twofactor: is complete", tx.is_complete()) + # reset billing_info + self.billing_info = None # Utility functions t@@ -314,6 +319,7 @@ class TrustedCoinPlugin(BasePlugin): def __init__(self, parent, config, name): BasePlugin.__init__(self, parent, config, name) self.wallet_class.plugin = self + self.requesting = False @staticmethod def is_valid_seed(seed): t@@ -326,23 +332,34 @@ class TrustedCoinPlugin(BasePlugin): return True @hook - def get_additional_fee(self, wallet, tx): + def get_tx_extra_fee(self, wallet, tx): if type(wallet) != Wallet_2fa: return address = wallet.billing_info['billing_address'] for _type, addr, amount in tx.outputs(): if _type == TYPE_ADDRESS and addr == address: - return amount + return address, amount def request_billing_info(self, wallet): + self.print_error("request billing info") billing_info = server.get(wallet.get_user_id()[1]) billing_address = make_billing_address(wallet, billing_info['billing_index']) assert billing_address == billing_info['billing_address'] wallet.billing_info = billing_info wallet.price_per_tx = dict(billing_info['price_per_tx']) wallet.price_per_tx.pop(1) + self.requesting = False return True + def start_request_thread(self, wallet): + from threading import Thread + if self.requesting is False: + self.requesting = True + t = Thread(target=self.request_billing_info, args=(wallet,)) + t.setDaemon(True) + t.start() + return t + def make_seed(self): return Mnemonic('english').make_seed(seed_type='2fa', num_bits=128)