From 0424d5eb857c2e225bf590bd4730c8a6a64e2dc0 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 17 Aug 2013 09:53:46 +0200 Subject: [PATCH] update signrawtransaction --- lib/commands.py | 4 +++- lib/wallet.py | 37 +++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/commands.py b/lib/commands.py index c30b0841c..250f08775 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -131,7 +131,9 @@ class Commands: def createmultisig(self, num, pubkeys): assert isinstance(pubkeys, list) - return Transaction.multisig_script(pubkeys, num) + redeem_script = Transaction.multisig_script(pubkeys, num) + address = hash_160_to_bc_address(hash_160(redeem_script.decode('hex')), 5) + return {'address':address, 'redeemScript':redeem_script} def freeze(self,addr): return self.wallet.freeze(addr) diff --git a/lib/wallet.py b/lib/wallet.py index 685a929a3..36ddb3ccf 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -366,15 +366,20 @@ class Wallet: def signrawtransaction(self, tx, input_info, private_keys, password): + import deserialize unspent_coins = self.get_unspent_coins() seed = self.decode_seed(password) - # convert private_keys to dict - pk = {} + # build a list of public/private keys + keypairs = {} for sec in private_keys: - address = address_from_private_key(sec) - pk[address] = sec - private_keys = pk + compressed = is_compressed(sec) + pkey = regenerate_key(sec) + pubkey = GetPubKey(pkey.pubkey, compressed) + keypairs[ pubkey.encode('hex') ] = sec + + # will be filled for each input + private_keys = {} for txin in tx.inputs: # convert to own format @@ -396,26 +401,34 @@ class Wallet: # if neither, we might want to get it from the server.. raise - # find the address: + # find the address and fill private_keys if txin.get('KeyID'): account, name, sequence = txin.get('KeyID') - if name != 'Electrum': continue + if name != 'BIP32': continue sec = self.accounts[account].get_private_key(sequence, seed) addr = self.accounts[account].get_address(sequence) txin['address'] = addr - private_keys[addr] = sec + private_keys[addr] = [sec] - elif txin.get("redeemScript"): - txin['address'] = hash_160_to_bc_address(hash_160(txin.get("redeemScript").decode('hex')), 5) + redeem_script = txin.get("redeemScript") + if redeem_script: + num, redeem_pubkeys = deserialize.parse_redeemScript(redeem_script) + addr = hash_160_to_bc_address(hash_160(redeem_script.decode('hex')), 5) + txin['address'] = addr + private_keys[addr] = [] + for pubkey in redeem_pubkeys: + if pubkey in keypairs: + private_keys[addr].append( keypairs[pubkey] ) elif txin.get("raw_output_script"): - import deserialize addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode('hex')) sec = self.get_private_key(addr, password) if sec: - private_keys[addr] = sec + private_keys[addr] = [sec] txin['address'] = addr + print txin + tx.sign( private_keys ) def sign_message(self, address, message, password):