fix input_info for signrawtransaction

This commit is contained in:
ThomasV 2014-04-26 18:44:45 +02:00
parent 0c100c1480
commit 5a02836933
2 changed files with 32 additions and 37 deletions

View File

@ -755,8 +755,8 @@ class Transaction:
for i, txin in enumerate(self.inputs): for i, txin in enumerate(self.inputs):
item = input_info[i] item = input_info[i]
txin['address'] = item['address'] txin['address'] = item['address']
txin['signatures'] = item['signatures']
txin['scriptPubKey'] = item['scriptPubKey'] txin['scriptPubKey'] = item['scriptPubKey']
txin['redeemScript'] = item.get('redeemScript') txin['redeemScript'] = item.get('redeemScript')
txin['redeemPubkey'] = item.get('redeemPubkey') txin['redeemPubkey'] = item.get('redeemPubkey')
txin['KeyID'] = item.get('KeyID') txin['KeyID'] = item.get('KeyID')
txin['signatures'] = item.get('signatures',{})

View File

@ -678,29 +678,24 @@ class NewWallet:
# check that the password is correct # check that the password is correct
seed = self.get_seed(password) seed = self.get_seed(password)
# add input info # if input_info is not known, build it using wallet UTXOs
tx.add_input_info(input_info) if not input_info:
input_info = []
# add redeem script for coins that are in the wallet
# FIXME: add redeemPubkey too!
try:
unspent_coins = self.get_unspent_coins() unspent_coins = self.get_unspent_coins()
except: for txin in tx.inputs:
# an exception may be raised is the wallet is not synchronized for item in unspent_coins:
unspent_coins = [] if txin['prevout_hash'] == item['prevout_hash'] and txin['prevout_n'] == item['prevout_n']:
info = { 'address':item['address'], 'scriptPubKey':item['scriptPubKey'] }
for txin in tx.inputs: self.add_input_info(info)
for item in unspent_coins: input_info.append(info)
if txin['prevout_hash'] == item['prevout_hash'] and txin['prevout_n'] == item['prevout_n']: break
print_error( "tx input is in unspent coins" ) else:
txin['scriptPubKey'] = item['scriptPubKey'] print_error( "input not in UTXOs" )
account, sequence = self.get_address_index(item['address']) input_info.append(None)
if account != -1:
txin['redeemScript'] = self.accounts[account].redeem_script(sequence)
print_error("added redeemScript", txin['redeemScript'])
break
# add input_info to the transaction
print_error("input_info", input_info)
tx.add_input_info(input_info)
# build a list of public/private keys # build a list of public/private keys
keypairs = {} keypairs = {}
@ -712,9 +707,9 @@ class NewWallet:
# add private_keys from KeyID # add private_keys from KeyID
self.add_keypairs_from_KeyID(tx, keypairs, password) self.add_keypairs_from_KeyID(tx, keypairs, password)
# add private keys from wallet # add private keys from wallet
self.add_keypairs_from_wallet(tx, keypairs, password) self.add_keypairs_from_wallet(tx, keypairs, password)
# sign the transaction
self.sign_transaction(tx, keypairs, password) self.sign_transaction(tx, keypairs, password)
@ -1230,7 +1225,8 @@ class NewWallet:
inputs, total, fee = self.choose_tx_inputs( amount, fee, len(outputs), domain ) inputs, total, fee = self.choose_tx_inputs( amount, fee, len(outputs), domain )
if not inputs: if not inputs:
raise ValueError("Not enough funds") raise ValueError("Not enough funds")
self.add_input_info(inputs) for txin in inputs:
self.add_input_info(txin)
outputs = self.add_tx_change(inputs, outputs, amount, fee, total, change_addr) outputs = self.add_tx_change(inputs, outputs, amount, fee, total, change_addr)
return Transaction.from_io(inputs, outputs) return Transaction.from_io(inputs, outputs)
@ -1244,19 +1240,18 @@ class NewWallet:
return tx return tx
def add_input_info(self, inputs): def add_input_info(self, txin):
for txin in inputs: address = txin['address']
address = txin['address'] if address in self.imported_keys.keys():
if address in self.imported_keys.keys(): return
continue account_id, sequence = self.get_address_index(address)
account_id, sequence = self.get_address_index(address) account = self.accounts[account_id]
account = self.accounts[account_id] txin['KeyID'] = account.get_keyID(sequence)
txin['KeyID'] = account.get_keyID(sequence) redeemScript = account.redeem_script(sequence)
redeemScript = account.redeem_script(sequence) if redeemScript:
if redeemScript: txin['redeemScript'] = redeemScript
txin['redeemScript'] = redeemScript else:
else: txin['redeemPubkey'] = account.get_pubkey(*sequence)
txin['redeemPubkey'] = account.get_pubkey(*sequence)
def sign_transaction(self, tx, keypairs, password): def sign_transaction(self, tx, keypairs, password):