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):
# first check the provided password
seed = self.get_seed(password)
- for txin in tx.inputs:
- x_pubkeys = txin['x_pubkeys']
- address = txin['address']
-
- if self.is_mine(address):
+ addr_list, xpub_list = tx.inputs_to_sign()
+ for addr in addr_list:
+ if self.is_mine(addr):
private_keys = self.get_private_key(address, password)
for sec in private_keys:
pubkey = public_key_from_private_key(sec)
keypairs[ pubkey ] = sec
+ for xpub, sequence in xpub_list:
+ # look for account that can sign
+ for k, account in self.accounts.items():
+ if xpub in account.get_master_pubkeys():
+ break
else:
+ continue
- from account import BIP32_Account
- print "scanning", x_pubkeys
-
- for x_pubkey in x_pubkeys:
- if not is_extended_pubkey(x_pubkey):
- continue
-
- xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
- print "xpub", xpub
-
- # look for account that can sign
- for k, account in self.accounts.items():
- if xpub in account.get_master_pubkeys():
- break
- else:
- continue
- print "found xpub", xpub, sequence
-
- addr = account.get_address(*sequence)
- print addr, txin['address']
- assert txin['address'] == addr
- pk = self.get_private_key(addr, password)
- for sec in pk:
- pubkey = public_key_from_private_key(sec)
- keypairs[pubkey] = sec
-
+ addr = account.get_address(*sequence)
+ pk = self.get_private_key(addr, password)
+ for sec in pk:
+ pubkey = public_key_from_private_key(sec)
+ keypairs[pubkey] = sec
account = self.accounts[account_id]
redeemScript = account.redeem_script(sequence)
txin['x_pubkeys'] = account.get_xpubkeys(sequence)
- txin['pubkeys'] = account.get_pubkeys(sequence)
+ txin['pubkeys'] = pubkeys = account.get_pubkeys(sequence)
+ txin['signatures'] = [None] * len(pubkeys)
+
if redeemScript:
txin['redeemScript'] = redeemScript
txin['num_sig'] = 2