wallet.make_unsigned_transaction()

This commit is contained in:
thomasv 2013-09-04 10:33:14 +02:00
parent 6696e9643c
commit 903e70566c
2 changed files with 14 additions and 17 deletions

View File

@ -1013,6 +1013,10 @@ class ElectrumWindow(QMainWindow):
except: except:
QMessageBox.warning(self, _('Error'), _('Could not write transaction to file'), _('OK')) QMessageBox.warning(self, _('Error'), _('Could not write transaction to file'), _('OK'))
# add recipient to addressbook
if to_address not in self.wallet.addressbook and not self.wallet.is_mine(to_address):
self.wallet.addressbook.append(to_address)

View File

@ -1110,46 +1110,39 @@ class Wallet:
return default_label return default_label
def mktx(self, outputs, password, fee=None, change_addr=None, account=None ): def make_unsigned_transaction(self, outputs, fee=None, change_addr=None, account=None ):
for address, x in outputs: for address, x in outputs:
assert is_valid(address) assert is_valid(address)
amount = sum( map(lambda x:x[1], outputs) ) amount = sum( map(lambda x:x[1], outputs) )
inputs, total, fee = self.choose_tx_inputs( amount, fee, account ) inputs, total, fee = self.choose_tx_inputs( amount, fee, account )
if not inputs: if not inputs:
raise ValueError("Not enough funds") raise ValueError("Not enough funds")
outputs = self.add_tx_change(inputs, outputs, amount, fee, total, change_addr, account) outputs = self.add_tx_change(inputs, outputs, amount, fee, total, change_addr, account)
tx = Transaction.from_io(inputs, outputs) return Transaction.from_io(inputs, outputs)
def mktx(self, outputs, password, fee=None, change_addr=None, account=None ):
tx = self.make_unsigned_transaction(outputs, fee, change_addr, account)
self.sign_transaction(tx, password)
return tx
def sign_transaction(self, tx, password):
keypairs = {} keypairs = {}
for i, txin in enumerate(tx.inputs): for i, txin in enumerate(tx.inputs):
address = txin['address'] address = txin['address']
account, sequence = self.get_address_index(address) account, sequence = self.get_address_index(address)
txin['KeyID'] = self.get_keyID(account, sequence) txin['KeyID'] = self.get_keyID(account, sequence)
redeemScript = self.accounts[account].redeem_script(sequence) redeemScript = self.accounts[account].redeem_script(sequence)
if redeemScript: if redeemScript:
txin['redeemScript'] = redeemScript txin['redeemScript'] = redeemScript
else: else:
txin['redeemPubkey'] = self.accounts[account].get_pubkey(*sequence) txin['redeemPubkey'] = self.accounts[account].get_pubkey(*sequence)
private_keys = self.get_private_key(address, password) private_keys = self.get_private_key(address, password)
for sec in private_keys: for sec in private_keys:
pubkey = public_key_from_private_key(sec) pubkey = public_key_from_private_key(sec)
keypairs[ pubkey ] = sec keypairs[ pubkey ] = sec
tx.sign(keypairs) tx.sign(keypairs)
for address, x in outputs:
if address not in self.addressbook and not self.is_mine(address):
self.addressbook.append(address)
return tx
def sendtx(self, tx): def sendtx(self, tx):