electrum

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

commit 58ab37d056c5f6d5561586d308d7fd934d8d29b7
parent 7fb406cc0538494b2d6abaa97e037f2d79df85c6
Author: thomasv <thomasv@gitorious>
Date:   Sun, 15 Sep 2013 14:51:46 +0200

send from domain in mktx (fix #294)

Diffstat:
Mgui/gui_classic/main_window.py | 2+-
Mlib/wallet.py | 31+++++++++++++++++++------------
2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/gui/gui_classic/main_window.py b/gui/gui_classic/main_window.py @@ -886,7 +886,7 @@ class ElectrumWindow(QMainWindow): def send_tx(self, to_address, amount, fee, label, password): try: - tx = self.wallet.mktx( [(to_address, amount)], password, fee, account=self.current_account) + tx = self.wallet.mktx_from_account( [(to_address, amount)], password, fee, self.current_account) except BaseException, e: traceback.print_exc(file=sys.stdout) self.show_message(str(e)) diff --git a/lib/wallet.py b/lib/wallet.py @@ -951,11 +951,12 @@ class Wallet: - def choose_tx_inputs( self, amount, fixed_fee, account = None ): + def choose_tx_inputs( self, amount, fixed_fee, domain = None ): """ todo: minimize tx size """ total = 0 fee = self.fee if fixed_fee is None else fixed_fee - domain = self.get_account_addresses(account) + if domain is None: + domain.self.addresses() coins = [] prioritized_coins = [] for i in self.frozen_addresses: @@ -995,15 +996,15 @@ class Wallet: return fee - def add_tx_change( self, inputs, outputs, amount, fee, total, change_addr=None, account=0 ): + def add_tx_change( self, inputs, outputs, amount, fee, total, change_addr=None): "add change to a transaction" change_amount = total - ( amount + fee ) if change_amount != 0: if not change_addr: - if account is None: - # send change to one of the accounts involved in the tx - address = inputs[0].get('address') - account, _ = self.get_address_index(address) + + # send change to one of the accounts involved in the tx + address = inputs[0].get('address') + account, _ = self.get_address_index(address) if not self.use_change or account == -1: change_addr = inputs[-1]['address'] @@ -1144,19 +1145,25 @@ class Wallet: return default_label - def make_unsigned_transaction(self, outputs, fee=None, change_addr=None, account=None ): + def make_unsigned_transaction(self, outputs, fee=None, change_addr=None, domain=None ): for address, x in outputs: assert is_valid(address) 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, domain ) if not inputs: 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) 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) + def mktx_from_account(self, outputs, password, fee=None, change_addr=None, account=None): + if account: + domain = self.get_account_addresses(account) + self.mktx(outputs, password, fee, change_addr, domain) + + + def mktx(self, outputs, password, fee=None, change_addr=None, domain= None ): + tx = self.make_unsigned_transaction(outputs, fee, change_addr, domain) self.sign_transaction(tx, password) return tx