mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
detect if wallet can sign tx before showing sign button
This commit is contained in:
parent
b32d0c77a3
commit
2c7bf3ca1a
4 changed files with 72 additions and 34 deletions
|
@ -131,10 +131,13 @@ class TxDialog(QDialog):
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
||||||
is_relevant, is_mine, v, fee = self.wallet.get_tx_value(self.tx)
|
is_relevant, is_mine, v, fee = self.wallet.get_tx_value(self.tx)
|
||||||
|
if self.wallet.can_sign(self.tx):
|
||||||
|
self.sign_button.show()
|
||||||
|
else:
|
||||||
|
self.sign_button.hide()
|
||||||
|
|
||||||
if self.tx.is_complete():
|
if self.tx.is_complete():
|
||||||
status = _("Signed")
|
status = _("Signed")
|
||||||
self.sign_button.hide()
|
|
||||||
tx_hash = self.tx.hash()
|
tx_hash = self.tx.hash()
|
||||||
|
|
||||||
if tx_hash in self.wallet.transactions.keys():
|
if tx_hash in self.wallet.transactions.keys():
|
||||||
|
@ -153,10 +156,6 @@ class TxDialog(QDialog):
|
||||||
s, r = self.tx.signature_count()
|
s, r = self.tx.signature_count()
|
||||||
status = _("Unsigned") if s == 0 else _('Partially signed (%d/%d)'%(s,r))
|
status = _("Unsigned") if s == 0 else _('Partially signed (%d/%d)'%(s,r))
|
||||||
time_str = None
|
time_str = None
|
||||||
if not self.wallet.is_watching_only():
|
|
||||||
self.sign_button.show()
|
|
||||||
else:
|
|
||||||
self.sign_button.hide()
|
|
||||||
self.broadcast_button.hide()
|
self.broadcast_button.hide()
|
||||||
tx_hash = 'unknown'
|
tx_hash = 'unknown'
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,8 @@ class PendingAccount(Account):
|
||||||
def get_name(self, k):
|
def get_name(self, k):
|
||||||
return _('Pending account')
|
return _('Pending account')
|
||||||
|
|
||||||
|
def get_master_pubkeys(self):
|
||||||
|
return []
|
||||||
|
|
||||||
class ImportedAccount(Account):
|
class ImportedAccount(Account):
|
||||||
def __init__(self, d):
|
def __init__(self, d):
|
||||||
|
|
|
@ -618,6 +618,36 @@ class Transaction:
|
||||||
return r == s
|
return r == s
|
||||||
|
|
||||||
|
|
||||||
|
def inputs_to_sign(self):
|
||||||
|
from account import BIP32_Account, OldAccount
|
||||||
|
xpub_list = []
|
||||||
|
addr_list = set()
|
||||||
|
for txin in self.inputs:
|
||||||
|
x_signatures = txin['signatures']
|
||||||
|
signatures = filter(lambda x: x is not None, x_signatures)
|
||||||
|
|
||||||
|
if len(signatures) == txin['num_sig']:
|
||||||
|
# input is complete
|
||||||
|
continue
|
||||||
|
|
||||||
|
for k, x_pubkey in enumerate(txin['x_pubkeys']):
|
||||||
|
|
||||||
|
if x_signatures[k] is not None:
|
||||||
|
# this pubkey already signed
|
||||||
|
continue
|
||||||
|
|
||||||
|
if x_pubkey[0:2] == 'ff':
|
||||||
|
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
|
||||||
|
xpub_list.append((xpub,sequence))
|
||||||
|
elif x_pubkey[0:2] == 'fe':
|
||||||
|
xpub, sequence = OldAccount.parse_xpubkey(x_pubkey)
|
||||||
|
xpub_list.add((xpub,sequence))
|
||||||
|
else:
|
||||||
|
addr_list.add(txin['address'])
|
||||||
|
|
||||||
|
return addr_list, xpub_list
|
||||||
|
|
||||||
|
|
||||||
def sign(self, keypairs):
|
def sign(self, keypairs):
|
||||||
print_error("tx.sign(), keypairs:", keypairs)
|
print_error("tx.sign(), keypairs:", keypairs)
|
||||||
|
|
||||||
|
|
|
@ -392,33 +392,42 @@ class Abstract_Wallet:
|
||||||
return self.accounts[account_id].get_pubkeys(sequence)
|
return self.accounts[account_id].get_pubkeys(sequence)
|
||||||
|
|
||||||
|
|
||||||
|
def can_sign(self, tx):
|
||||||
|
|
||||||
|
if self.is_watching_only():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if tx.is_complete():
|
||||||
|
return False
|
||||||
|
|
||||||
|
addr_list, xpub_list = tx.inputs_to_sign()
|
||||||
|
for addr in addr_list:
|
||||||
|
if self.is_mine(addr):
|
||||||
|
return True
|
||||||
|
|
||||||
|
mpk = [ self.master_public_keys[k] for k in self.master_private_keys.keys() ]
|
||||||
|
for xpub, sequence in xpub_list:
|
||||||
|
if xpub in mpk:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_keypairs(self, tx, keypairs, password):
|
def add_keypairs(self, tx, keypairs, password):
|
||||||
# first check the provided password
|
# first check the provided password
|
||||||
seed = self.get_seed(password)
|
seed = self.get_seed(password)
|
||||||
|
|
||||||
for txin in tx.inputs:
|
addr_list, xpub_list = tx.inputs_to_sign()
|
||||||
x_pubkeys = txin['x_pubkeys']
|
|
||||||
address = txin['address']
|
|
||||||
|
|
||||||
if self.is_mine(address):
|
|
||||||
|
|
||||||
|
for addr in addr_list:
|
||||||
|
if self.is_mine(addr):
|
||||||
private_keys = self.get_private_key(address, password)
|
private_keys = self.get_private_key(address, password)
|
||||||
for sec in private_keys:
|
for sec in private_keys:
|
||||||
pubkey = public_key_from_private_key(sec)
|
pubkey = public_key_from_private_key(sec)
|
||||||
keypairs[ pubkey ] = sec
|
keypairs[ pubkey ] = sec
|
||||||
|
|
||||||
else:
|
for xpub, sequence in xpub_list:
|
||||||
|
|
||||||
from account import BIP32_Account, OldAccount
|
|
||||||
for x_pubkey in x_pubkeys:
|
|
||||||
if not is_extended_pubkey(x_pubkey):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if x_pubkey[0:2] == 'ff':
|
|
||||||
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
|
|
||||||
elif x_pubkey[0:2] == 'fe':
|
|
||||||
xpub, sequence = OldAccount.parse_xpubkey(x_pubkey)
|
|
||||||
|
|
||||||
# look for account that can sign
|
# look for account that can sign
|
||||||
for k, account in self.accounts.items():
|
for k, account in self.accounts.items():
|
||||||
if xpub in account.get_master_pubkeys():
|
if xpub in account.get_master_pubkeys():
|
||||||
|
@ -427,7 +436,6 @@ class Abstract_Wallet:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
addr = account.get_address(*sequence)
|
addr = account.get_address(*sequence)
|
||||||
assert txin['address'] == addr
|
|
||||||
pk = self.get_private_key(addr, password)
|
pk = self.get_private_key(addr, password)
|
||||||
for sec in pk:
|
for sec in pk:
|
||||||
pubkey = public_key_from_private_key(sec)
|
pubkey = public_key_from_private_key(sec)
|
||||||
|
@ -435,7 +443,6 @@ class Abstract_Wallet:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def signrawtransaction(self, tx, private_keys, password):
|
def signrawtransaction(self, tx, private_keys, password):
|
||||||
|
|
||||||
# check that the password is correct
|
# check that the password is correct
|
||||||
|
|
Loading…
Add table
Reference in a new issue