fix input_info for signrawtransaction
This commit is contained in:
parent
0c100c1480
commit
5a02836933
|
@ -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',{})
|
||||||
|
|
|
@ -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:
|
|
||||||
# an exception may be raised is the wallet is not synchronized
|
|
||||||
unspent_coins = []
|
|
||||||
|
|
||||||
for txin in tx.inputs:
|
for txin in tx.inputs:
|
||||||
for item in unspent_coins:
|
for item in unspent_coins:
|
||||||
if txin['prevout_hash'] == item['prevout_hash'] and txin['prevout_n'] == item['prevout_n']:
|
if txin['prevout_hash'] == item['prevout_hash'] and txin['prevout_n'] == item['prevout_n']:
|
||||||
print_error( "tx input is in unspent coins" )
|
info = { 'address':item['address'], 'scriptPubKey':item['scriptPubKey'] }
|
||||||
txin['scriptPubKey'] = item['scriptPubKey']
|
self.add_input_info(info)
|
||||||
account, sequence = self.get_address_index(item['address'])
|
input_info.append(info)
|
||||||
if account != -1:
|
|
||||||
txin['redeemScript'] = self.accounts[account].redeem_script(sequence)
|
|
||||||
print_error("added redeemScript", txin['redeemScript'])
|
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
print_error( "input not in UTXOs" )
|
||||||
|
input_info.append(None)
|
||||||
|
|
||||||
|
# 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,11 +1240,10 @@ 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():
|
||||||
continue
|
return
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue