electrum

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

commit df540cb24145b0dea505c3045bcffec88ba3fe99
parent 5c31263848b23dbcf95de12f829fb4195f883cd6
Author: ThomasV <thomasv@gitorious>
Date:   Tue,  1 Apr 2014 23:53:07 +0200

move get_keyID to accounts

Diffstat:
Mlib/account.py | 12++++++++++--
Mlib/transaction.py | 3+++
Mlib/wallet.py | 45+++++++++++++++++----------------------------
3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/lib/account.py b/lib/account.py @@ -122,6 +122,10 @@ class OldAccount(Account): def get_type(self): return _('Old Electrum format') + def get_keyID(self, sequence): + a, b = sequence + return 'old(%s,%d,%d)'%(self.mpk,a,b) + class BIP32_Account(Account): @@ -160,7 +164,10 @@ class BIP32_Account(Account): def get_type(self): return _('Standard 1 of 1') - #acctype = 'multisig 2 of 2' if len(roots) == 2 else 'multisig 2 of 3' if len(roots) == 3 else 'standard 1 of 1' + + def get_keyID(self, sequence): + s = '/' + '/'.join( map(lambda x:str(x), sequence) ) + return '&'.join( map(lambda x: 'bip32(%s,%s)'%(x, s), self.get_master_pubkeys() ) ) class BIP32_Account_2of2(BIP32_Account): @@ -182,7 +189,7 @@ class BIP32_Account_2of2(BIP32_Account): def redeem_script(self, sequence): pubkeys = self.get_pubkeys(sequence) - return Transaction.multisig_script(pubkeys, len(pubkeys)) + return Transaction.multisig_script(pubkeys, 2) def get_address(self, for_change, n): address = hash_160_to_bc_address(hash_160(self.redeem_script((for_change, n)).decode('hex')), 5) @@ -226,3 +233,4 @@ class BIP32_Account_2of3(BIP32_Account_2of2): + diff --git a/lib/transaction.py b/lib/transaction.py @@ -517,6 +517,8 @@ class Transaction: continue tx_for_sig = self.serialize( self.inputs, self.outputs, for_sig = i ) + + print_error("redeem pubkeys input %d"%i, redeem_pubkeys) for pubkey in redeem_pubkeys: # check if we have the corresponding private key if pubkey in keypairs.keys(): @@ -535,6 +537,7 @@ class Transaction: txin["signatures"] = signatures is_complete = is_complete and len(signatures) == num + print_error("is_complete", is_complete) self.is_complete = is_complete self.raw = self.serialize( self.inputs, self.outputs ) diff --git a/lib/wallet.py b/lib/wallet.py @@ -570,14 +570,6 @@ class NewWallet: - def get_keyID(self, account, sequence): - rs = self.rebase_sequence(account, sequence) - dd = [] - for root, public_sequence in rs: - xpub = self.master_public_keys[root] - s = '/' + '/'.join( map(lambda x:str(x), public_sequence) ) - dd.append( 'bip32(%s,%s)'%(xpub, s) ) - return '&'.join(dd) def get_seed(self, password): @@ -596,19 +588,21 @@ class NewWallet: # first check the provided password seed = self.get_seed(password) - + out = [] if address in self.imported_keys.keys(): out.append( pw_decode( self.imported_keys[address], password ) ) else: account_id, sequence = self.get_address_index(address) - #rs = self.rebase_sequence( account, sequence) - rs = [(account_id, sequence)] - for root, public_sequence in rs: + account = self.accounts[account_id] + xpubs = account.get_master_pubkeys() + roots = [k for k, v in self.master_public_keys.iteritems() if v in xpubs] + for root in roots: xpriv = self.get_master_private_key(root, password) - if not xpriv: continue + if not xpriv: + continue _, _, _, c, k = deserialize_xkey(xpriv) - pk = bip32_private_key( public_sequence, k, c ) + pk = bip32_private_key( sequence, k, c ) out.append(pk) return out @@ -636,12 +630,11 @@ class NewWallet: if keyid: roots = [] for s in keyid.split('&'): - m = re.match("bip32\(([0-9a-f]+),([0-9a-f]+),(/\d+/\d+/\d+)", s) + m = re.match("bip32\((.*),(/\d+/\d+)\)", s) if not m: continue - c = m.group(1) - K = m.group(2) - sequence = m.group(3) - root = self.find_root_by_master_key(c,K) + xpub = m.group(1) + sequence = m.group(2) + root = self.find_root_by_master_key(xpub) if not root: continue sequence = map(lambda x:int(x), sequence.strip('/').split('/')) root = root + '%d'%sequence[0] @@ -1236,13 +1229,14 @@ class NewWallet: address = txin['address'] if address in self.imported_keys.keys(): continue - account, sequence = self.get_address_index(address) - txin['KeyID'] = self.get_keyID(account, sequence) - redeemScript = self.accounts[account].redeem_script(sequence) + account_id, sequence = self.get_address_index(address) + account = self.accounts[account_id] + txin['KeyID'] = account.get_keyID(sequence) + redeemScript = account.redeem_script(sequence) if redeemScript: txin['redeemScript'] = redeemScript else: - txin['redeemPubkey'] = self.accounts[account].get_pubkey(*sequence) + txin['redeemPubkey'] = account.get_pubkey(*sequence) def sign_transaction(self, tx, keypairs, password): @@ -1746,11 +1740,6 @@ class OldWallet(NewWallet): out.append(pk) return out - def get_keyID(self, account, sequence): - a, b = sequence - mpk = self.storage.get('master_public_key') - return 'old(%s,%d,%d)'%(mpk,a,b) - def check_pending_accounts(self): pass