|
|
|
|
@ -1,16 +1,17 @@
|
|
|
|
|
from PyQt4.Qt import QMessageBox, QDialog, QVBoxLayout, QLabel |
|
|
|
|
from PyQt4.Qt import QMessageBox, QDialog, QVBoxLayout, QLabel, QThread, SIGNAL, QObject |
|
|
|
|
from binascii import unhexlify |
|
|
|
|
from struct import pack |
|
|
|
|
from sys import stderr |
|
|
|
|
from time import sleep |
|
|
|
|
|
|
|
|
|
from gui.qt.password_dialog import make_password_dialog, run_password_dialog |
|
|
|
|
from gui.qt.util import ok_cancel_buttons |
|
|
|
|
from lib.account import BIP32_Account |
|
|
|
|
from lib.bitcoin import EncodeBase58Check |
|
|
|
|
from lib.i18n import _ |
|
|
|
|
from lib.plugins import BasePlugin |
|
|
|
|
from lib.transaction import deserialize |
|
|
|
|
from lib.wallet import NewWallet |
|
|
|
|
from electrum_gui.qt.password_dialog import make_password_dialog, run_password_dialog |
|
|
|
|
from electrum_gui.qt.util import ok_cancel_buttons |
|
|
|
|
from electrum.account import BIP32_Account |
|
|
|
|
from electrum.bitcoin import EncodeBase58Check |
|
|
|
|
from electrum.i18n import _ |
|
|
|
|
from electrum.plugins import BasePlugin |
|
|
|
|
from electrum.transaction import deserialize |
|
|
|
|
from electrum.wallet import NewWallet |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
@ -27,6 +28,7 @@ def log(msg):
|
|
|
|
|
stderr.write("%s\n" % msg) |
|
|
|
|
stderr.flush() |
|
|
|
|
|
|
|
|
|
gl_emitter = QObject() |
|
|
|
|
|
|
|
|
|
class Plugin(BasePlugin): |
|
|
|
|
|
|
|
|
|
@ -173,7 +175,12 @@ class TrezorWallet(NewWallet):
|
|
|
|
|
|
|
|
|
|
inputs = self.tx_inputs(tx) |
|
|
|
|
outputs = self.tx_outputs(tx) |
|
|
|
|
signed_tx = self.get_client().sign_tx('Bitcoin', inputs, outputs)[1] |
|
|
|
|
try: |
|
|
|
|
signed_tx = self.get_client().sign_tx('Bitcoin', inputs, outputs)[1] |
|
|
|
|
except Exception, e: |
|
|
|
|
raise e |
|
|
|
|
finally: |
|
|
|
|
gl_emitter.emit(SIGNAL('trezor_done')) |
|
|
|
|
values = [i['value'] for i in tx.inputs] |
|
|
|
|
raw = signed_tx.encode('hex') |
|
|
|
|
tx.update(raw) |
|
|
|
|
@ -280,10 +287,14 @@ class TrezorQtGuiMixin(object):
|
|
|
|
|
super(TrezorQtGuiMixin, self).__init__(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
def callback_ButtonRequest(self, msg): |
|
|
|
|
i = QMessageBox.question(None, _('Trezor'), _("Please check request on Trezor's screen"), _('OK'), _('Cancel')) |
|
|
|
|
if i == 0: |
|
|
|
|
return proto.ButtonAck() |
|
|
|
|
return proto.Cancel() |
|
|
|
|
if msg.code == 3: |
|
|
|
|
message = "Confirm transaction outputs on Trezor device to continue" |
|
|
|
|
elif msg.code == 8: |
|
|
|
|
message = "Confirm transaction fee on Trezor device to continue" |
|
|
|
|
else: |
|
|
|
|
message = "Check Trezor device to continue" |
|
|
|
|
twd.start(message) |
|
|
|
|
return proto.ButtonAck() |
|
|
|
|
|
|
|
|
|
def callback_PinMatrixRequest(self, msg): |
|
|
|
|
if msg.type == 1: |
|
|
|
|
@ -339,6 +350,28 @@ class TrezorQtGuiMixin(object):
|
|
|
|
|
if not d.exec_(): return |
|
|
|
|
return str(matrix.get_value()) |
|
|
|
|
|
|
|
|
|
class TrezorWaitingDialog(QThread): |
|
|
|
|
def __init__(self): |
|
|
|
|
QThread.__init__(self) |
|
|
|
|
self.waiting = False |
|
|
|
|
|
|
|
|
|
def start(self, message): |
|
|
|
|
self.d = QDialog() |
|
|
|
|
self.d.setModal(True) |
|
|
|
|
self.d.setWindowTitle('Please Check Trezor Device') |
|
|
|
|
l = QLabel(message) |
|
|
|
|
vbox = QVBoxLayout(self.d) |
|
|
|
|
vbox.addWidget(l) |
|
|
|
|
self.d.show() |
|
|
|
|
if not self.waiting: |
|
|
|
|
self.waiting = True |
|
|
|
|
self.d.connect(gl_emitter, SIGNAL('trezor_done'), self.stop) |
|
|
|
|
|
|
|
|
|
def stop(self): |
|
|
|
|
self.d.hide() |
|
|
|
|
self.waiting = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if TREZOR: |
|
|
|
|
class QtGuiTrezorClient(ProtocolMixin, TrezorQtGuiMixin, BaseClient): |
|
|
|
|
def call_raw(self, msg): |
|
|
|
|
@ -349,3 +382,6 @@ if TREZOR:
|
|
|
|
|
raise |
|
|
|
|
|
|
|
|
|
return resp |
|
|
|
|
|
|
|
|
|
twd = TrezorWaitingDialog() |
|
|
|
|
|
|
|
|
|
|