electrum

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

commit 69e68e9203af2c8c2d756eb1e9bc4ad7055db55b
parent 52211180ed5b0ea0aa056f4cdd3bff99df704338
Author: ThomasV <thomasv@gitorious>
Date:   Sun, 14 Oct 2012 08:25:09 +0200

show waiting dialog during transaction broadcast

Diffstat:
Mlib/gui_qt.py | 58+++++++++++++++++++++++++++++++---------------------------
Mlib/wallet.py | 13+++++++++++--
2 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/lib/gui_qt.py b/lib/gui_qt.py @@ -168,6 +168,26 @@ class QRCodeWidget(QWidget): qp.end() +def waiting_dialog(f): + + s = Timer() + s.start() + w = QDialog() + w.resize(200, 70) + w.setWindowTitle('Electrum') + l = QLabel('') + vbox = QVBoxLayout() + vbox.addWidget(l) + w.setLayout(vbox) + w.show() + def ff(): + s = f() + if s: l.setText(s) + else: w.close() + w.connect(s, QtCore.SIGNAL('timersignal'), ff) + w.exec_() + w.destroy() + def ok_cancel_buttons(dialog): hbox = QHBoxLayout() @@ -598,7 +618,10 @@ class ElectrumWindow(QMainWindow): self.show_message(str(e)) return - status, msg = self.wallet.sendtx( tx ) + h = self.wallet.send_tx(tx) + waiting_dialog(lambda: False if self.wallet.tx_event.isSet() else _("Please wait...")) + status, msg = self.wallet.receive_tx( h ) + if status: QMessageBox.information(self, '', _('Payment sent.')+'\n'+msg, _('OK')) self.do_clear() @@ -1506,30 +1529,6 @@ class ElectrumGui: def server_list_changed(self): pass - def waiting_dialog(self): - - s = Timer() - s.start() - w = QDialog() - w.resize(200, 70) - w.setWindowTitle('Electrum') - l = QLabel('') - vbox = QVBoxLayout() - vbox.addWidget(l) - w.setLayout(vbox) - w.show() - def f(): - if self.wallet.up_to_date: - w.close() - else: - l.setText("Please wait...\nAddresses generated: %d\nKilobytes received: %.1f"\ - %(len(self.wallet.all_addresses()), self.wallet.interface.bytes_received/1024.)) - - w.connect(s, QtCore.SIGNAL('timersignal'), f) - self.wallet.interface.poke() - w.exec_() - w.destroy() - def restore_or_create(self): @@ -1542,12 +1541,16 @@ class ElectrumGui: # ask for the server. if not ElectrumWindow.network_dialog( wallet, parent=None ): return False + waiting = lambda: False if wallet.up_to_date else "Please wait...\nAddresses generated: %d\nKilobytes received: %.1f"\ + %(len(wallet.all_addresses()), wallet.interface.bytes_received/1024.) + if not is_recovery: wallet.new_seed(None) wallet.init_mpk( wallet.seed ) wallet.up_to_date_event.clear() wallet.up_to_date = False - self.waiting_dialog() + wallet.interface.poke() + waiting_dialog(waiting) # run a dialog indicating the seed, ask the user to remember it ElectrumWindow.show_seed_dialog(wallet) #ask for password @@ -1558,7 +1561,8 @@ class ElectrumGui: wallet.init_mpk( wallet.seed ) wallet.up_to_date_event.clear() wallet.up_to_date = False - self.waiting_dialog() + wallet.interface.poke() + waiting_dialog(waiting) if wallet.is_found(): # history and addressbook wallet.update_tx_history() diff --git a/lib/wallet.py b/lib/wallet.py @@ -795,10 +795,19 @@ class Wallet: return tx def sendtx(self, tx): - tx_hash = Hash(tx.decode('hex') )[::-1].encode('hex') + # synchronous + h = self.send_tx(tx) + self.tx_event.wait() + self.receive_tx(h) + + def send_tx(self, tx): + # asynchronous self.tx_event.clear() + tx_hash = Hash(tx.decode('hex') )[::-1].encode('hex') self.interface.send([('blockchain.transaction.broadcast', [tx])]) - self.tx_event.wait() + return tx_hash + + def receive_tx(self,tx_hash): out = self.tx_result if out != tx_hash: return False, "error: " + out