allow multiple-outputs transactions with mktx()

This commit is contained in:
thomasv 2012-12-05 16:41:39 +01:00
parent 12250995cd
commit c763445734
7 changed files with 20 additions and 15 deletions

View File

@ -576,7 +576,7 @@ if __name__ == '__main__':
if change_addr and v == change_addr:
change_addr = k
try:
tx = wallet.mktx( to_address, amount, label, password,
tx = wallet.mktx( [(to_address, amount)], label, password,
fee = options.tx_fee, change_addr = change_addr, from_addr = from_addr )
except:
import traceback

View File

@ -841,7 +841,7 @@ class ElectrumWindow:
password = None
try:
tx = self.wallet.mktx( to_address, amount, label, password, fee )
tx = self.wallet.mktx( [(to_address, amount)], label, password, fee )
except BaseException, e:
self.show_message(str(e))
return

View File

@ -451,7 +451,7 @@ def pay_to(recipient, amount, fee, label):
droid.dialogShow()
try:
tx = wallet.mktx( recipient, amount, label, password, fee)
tx = wallet.mktx( [(recipient, amount)], label, password, fee)
except BaseException, e:
modal_dialog('error', e.message)
droid.dialogDismiss()

View File

@ -760,7 +760,7 @@ class MiniActuator:
fee = bitcoin(1) / 1000
try:
tx = self.wallet.mktx(dest_address, amount, "", password, fee)
tx = self.wallet.mktx([(dest_address, amount)], "", password, fee)
except BaseException as error:
QMessageBox.warning(parent_window, _('Error'), str(error), _('OK'))
return False

View File

@ -768,7 +768,7 @@ class ElectrumWindow(QMainWindow):
password = None
try:
tx = self.wallet.mktx( to_address, amount, label, password, fee)
tx = self.wallet.mktx( [(to_address, amount)], label, password, fee)
except BaseException, e:
self.show_message(str(e))
return

View File

@ -279,7 +279,7 @@ class ElectrumGui:
password = None
try:
tx = self.wallet.mktx( self.str_recipient, amount, self.str_description, password, fee)
tx = self.wallet.mktx( [(self.str_recipient, amount)], self.str_description, password, fee)
except BaseException, e:
self.show_message(str(e))
return

View File

@ -584,8 +584,7 @@ class Wallet:
inputs = []
return inputs, total, fee
def choose_tx_outputs( self, to_addr, amount, fee, total, change_addr=None ):
outputs = [ (to_addr, amount) ]
def add_tx_change( self, outputs, amount, fee, total, change_addr=None ):
change_amount = total - ( amount + fee )
if change_amount != 0:
# normally, the update thread should ensure that the last change address is unused
@ -763,9 +762,12 @@ class Wallet:
return default_label
def mktx(self, to_address, amount, label, password, fee=None, change_addr=None, from_addr= None):
if not self.is_valid(to_address):
raise ValueError("Invalid address")
def mktx(self, outputs, label, password, fee=None, change_addr=None, from_addr= None):
for address, x in outputs:
assert self.is_valid(address)
amount = sum( map(lambda x:x[1], outputs) )
inputs, total, fee = self.choose_tx_inputs( amount, fee, from_addr )
if not inputs:
raise ValueError("Not enough funds")
@ -773,13 +775,16 @@ class Wallet:
if not self.use_change and not change_addr:
change_addr = inputs[-1][0]
print_error( "Sending change to", change_addr )
outputs = self.add_tx_change(outputs, amount, fee, total, change_addr)
outputs = self.choose_tx_outputs( to_address, amount, fee, total, change_addr )
s_inputs = self.sign_inputs( inputs, outputs, password )
tx = filter( raw_tx( s_inputs, outputs ) )
if to_address not in self.addressbook:
self.addressbook.append(to_address)
for address, x in outputs:
if address not in self.addressbook and not self.is_mine(address):
self.addressbook.append(to_address)
if label:
tx_hash = Hash(tx.decode('hex') )[::-1].encode('hex')
self.labels[tx_hash] = label