electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit c763445734bf3a79a9b27c46a84a20fe96e34748
parent 12250995cde077877e4827a8e59225b2e5415c31
Author: thomasv <thomasv@gitorious>
Date:   Wed,  5 Dec 2012 16:41:39 +0100

allow multiple-outputs transactions with mktx()

Diffstat:
Melectrum | 2+-
Mlib/gui.py | 2+-
Mlib/gui_android.py | 2+-
Mlib/gui_lite.py | 2+-
Mlib/gui_qt.py | 2+-
Mlib/gui_text.py | 2+-
Mlib/wallet.py | 23++++++++++++++---------
7 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/electrum b/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 diff --git a/lib/gui.py b/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 diff --git a/lib/gui_android.py b/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() diff --git a/lib/gui_lite.py b/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 diff --git a/lib/gui_qt.py b/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 diff --git a/lib/gui_text.py b/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 diff --git a/lib/wallet.py b/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.choose_tx_outputs( to_address, amount, fee, total, change_addr ) + outputs = self.add_tx_change(outputs, 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