1
0

Remove need for self.wallet for h/w wallets

This commit is contained in:
Neil Booth
2015-12-30 17:03:26 +09:00
parent 84450b9189
commit 1d51335827
9 changed files with 38 additions and 71 deletions

View File

@@ -27,8 +27,8 @@ class Plugin(TrezorPlugin):
@hook
def cmdline_load_wallet(self, wallet):
self.wallet = wallet
self.wallet.plugin = self
if type(wallet) != self.wallet_class:
return
wallet.plugin = self
if self.handler is None:
self.handler = TrezorCmdLineHandler()

View File

@@ -113,7 +113,7 @@ class TrezorCompatibleWallet(BIP44_Wallet):
acc_id = re.match("x/(\d+)'", k).group(1)
xpub_path[xpub] = self.account_derivation(acc_id)
self.plugin.sign_transaction(tx, prev_tx, xpub_path)
self.plugin.sign_transaction(self, tx, prev_tx, xpub_path)
def is_proper_device(self):
self.get_client().ping('t')
@@ -154,7 +154,6 @@ class TrezorCompatiblePlugin(BasePlugin):
def __init__(self, parent, config, name):
BasePlugin.__init__(self, parent, config, name)
self.device = self.wallet_class.device
self.wallet = None
self.handler = None
self.client = None
@@ -166,16 +165,7 @@ class TrezorCompatiblePlugin(BasePlugin):
raise Exception(message)
def is_enabled(self):
if not self.libraries_available:
return False
if not self.wallet:
return False
wallet_type = self.wallet_class.wallet_type
if self.wallet.storage.get('wallet_type') != wallet_type:
return False
if self.wallet.has_seed():
return False
return True
return self.libraries_available
def create_client(self):
if not self.libraries_available:
@@ -212,14 +202,13 @@ class TrezorCompatiblePlugin(BasePlugin):
self.client.clear_session()
self.client.transport.close()
self.client = None
self.wallet = None
def sign_transaction(self, tx, prev_tx, xpub_path):
def sign_transaction(self, wallet, tx, prev_tx, xpub_path):
self.prev_tx = prev_tx
self.xpub_path = xpub_path
client = self.get_client()
inputs = self.tx_inputs(tx, True)
outputs = self.tx_outputs(tx)
outputs = self.tx_outputs(wallet, tx)
try:
signed_tx = client.sign_tx('Bitcoin', inputs, outputs)[1]
except Exception as e:
@@ -229,11 +218,11 @@ class TrezorCompatiblePlugin(BasePlugin):
raw = signed_tx.encode('hex')
tx.update_signatures(raw)
def show_address(self, address):
def show_address(self, wallet, address):
client = self.get_client()
self.wallet.check_proper_device()
wallet.check_proper_device()
try:
address_path = self.wallet.address_id(address)
address_path = wallet.address_id(address)
address_n = client.expand_path(address_path)
except Exception as e:
self.give_error(e)
@@ -306,15 +295,15 @@ class TrezorCompatiblePlugin(BasePlugin):
return inputs
def tx_outputs(self, tx):
def tx_outputs(self, wallet, tx):
client = self.get_client()
outputs = []
for type, address, amount in tx.outputs:
assert type == 'address'
txoutputtype = self.types.TxOutputType()
if self.wallet.is_change(address):
address_path = self.wallet.address_id(address)
if wallet.is_change(address):
address_path = wallet.address_id(address)
address_n = client.expand_path(address_path)
txoutputtype.address_n.extend(address_n)
else:

View File

@@ -108,16 +108,17 @@ class QtPlugin(TrezorPlugin):
@hook
def load_wallet(self, wallet, window):
if type(wallet) != self.wallet_class:
return
self.print_error("load_wallet")
self.wallet = wallet
self.wallet.plugin = self
wallet.plugin = self
self.button = StatusBarButton(QIcon(self.icon_file), self.device,
partial(self.settings_dialog, window))
if type(window) is ElectrumWindow:
window.statusBar().addPermanentWidget(self.button)
if self.handler is None:
self.handler = self.create_handler(window)
msg = self.wallet.sanity_check()
msg = wallet.sanity_check()
if msg:
window.show_error(msg)
@@ -139,7 +140,7 @@ class QtPlugin(TrezorPlugin):
# Restored wallets are not hardware wallets
wallet_class = self.wallet_class.restore_wallet_class
storage.put('wallet_type', wallet_class.wallet_type)
self.wallet = wallet = wallet_class(storage)
wallet = wallet_class(storage)
handler = self.create_handler(wizard)
msg = "\n".join([_("Please enter your %s passphrase.") % self.device,
@@ -154,11 +155,13 @@ class QtPlugin(TrezorPlugin):
return wallet
@hook
def receive_menu(self, menu, addrs):
if (not self.wallet.is_watching_only() and
def receive_menu(self, menu, addrs, wallet):
if type(wallet) != self.wallet_class:
return
if (not wallet.is_watching_only() and
self.atleast_version(1, 3) and len(addrs) == 1):
menu.addAction(_("Show on %s") % self.device,
lambda: self.show_address(addrs[0]))
lambda: self.show_address(wallet, addrs[0]))
def settings_dialog(self, window):