Browse Source

allow multiple-outputs transactions with mktx()

283
thomasv 12 years ago
parent
commit
c763445734
  1. 2
      electrum
  2. 2
      lib/gui.py
  3. 2
      lib/gui_android.py
  4. 2
      lib/gui_lite.py
  5. 2
      lib/gui_qt.py
  6. 2
      lib/gui_text.py
  7. 19
      lib/wallet.py

2
electrum

@ -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

2
lib/gui.py

@ -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

2
lib/gui_android.py

@ -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()

2
lib/gui_lite.py

@ -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

2
lib/gui_qt.py

@ -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

2
lib/gui_text.py

@ -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

19
lib/wallet.py

@ -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:
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

Loading…
Cancel
Save