electrum

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

commit 5cd3bfedb6c55477e386e3f59608cd91cc7d1d5b
parent 0531f00c80c507cd7f1feea64597b9a0ae7b1e74
Author: ThomasV <thomasv@gitorious>
Date:   Sun, 31 May 2015 11:31:41 +0200

always pass coins to wallet.make_unsigned_transactions. fix \! shortcut in commands

Diffstat:
Mgui/gtk.py | 4+++-
Mgui/qt/main_window.py | 4++--
Mlib/commands.py | 33++++++++++++++++++---------------
Mlib/wallet.py | 11++++-------
4 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/gui/gtk.py b/gui/gtk.py @@ -26,6 +26,7 @@ from gi.repository import Gtk, Gdk, GObject, cairo from decimal import Decimal from electrum.util import print_error, InvalidPassword from electrum.bitcoin import is_valid +from electrum.wallet import NotEnoughFunds from electrum import WalletStorage, Wallet Gdk.threads_init() @@ -687,8 +688,9 @@ class ElectrumWindow: if not is_fee: fee = None if amount is None: return + coins = self.wallet.get_spendable_coins() try: - tx = self.wallet.make_unsigned_transaction([('op_return', 'dummy_tx', amount)], fee) + tx = self.wallet.make_unsigned_transaction(coins, [('op_return', 'dummy_tx', amount)], fee) self.funds_error = False except NotEnoughFunds: self.funds_error = True diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -1006,7 +1006,7 @@ class ElectrumWindow(QMainWindow): addr = self.payto_e.payto_address if self.payto_e.payto_address else self.dummy_address outputs = [('address', addr, amount)] try: - tx = self.wallet.make_unsigned_transaction(outputs, fee, coins = self.get_coins()) + tx = self.wallet.make_unsigned_transaction(self.get_coins(), outputs, fee) self.not_enough_funds = False except NotEnoughFunds: self.not_enough_funds = True @@ -1111,7 +1111,7 @@ class ElectrumWindow(QMainWindow): return outputs, fee, label, coins = r try: - tx = self.wallet.make_unsigned_transaction(outputs, fee, None, coins = coins) + tx = self.wallet.make_unsigned_transaction(coins, outputs, fee) if not tx: raise BaseException(_("Insufficient funds")) except Exception as e: diff --git a/lib/commands.py b/lib/commands.py @@ -424,7 +424,7 @@ class Commands: def verifymessage(self, address, signature, message): return bitcoin.verify_message(address, signature, message) - def _mktx(self, outputs, fee = None, change_addr = None, domain = None): + def _mktx(self, outputs, fee=None, change_addr=None, domain=None): for to_address, amount in outputs: if not is_valid(to_address): raise Exception("Invalid Bitcoin address", to_address) @@ -445,6 +445,9 @@ class Commands: if change_addr and v == change_addr: change_addr = k + if fee is not None: + fee = int(100000000*fee) + final_outputs = [] for to_address, amount in outputs: for k, v in self.wallet.labels.items(): @@ -453,11 +456,22 @@ class Commands: print_msg("alias", to_address) break - amount = int(100000000*amount) + if amount == '!': + assert len(outputs) == 1 + inputs = self.wallet.get_spendable_coins(domain) + amount = sum(map(lambda x:x['value'], inputs)) + if fee is None: + for i in inputs: + self.wallet.add_input_info(i) + output = ('address', to_address, amount) + dummy_tx = Transaction.from_io(inputs, [output]) + fee = self.wallet.estimated_fee(dummy_tx) + amount -= fee + else: + amount = int(100000000*amount) final_outputs.append(('address', to_address, amount)) - if fee is not None: fee = int(100000000*fee) - return self.wallet.mktx(final_outputs, self.password, fee , change_addr, domain) + return self.wallet.mktx(final_outputs, self.password, fee, change_addr, domain) def _read_csv(self, csvpath): import csv @@ -473,17 +487,6 @@ class Commands: def mktx(self, to_address, amount, fee=None, from_addr=None, change_addr=None): domain = [from_addr] if from_addr else None - if amount == '!': - inputs = self.wallet.get_spendable_coins(domain) - amount = sum(map(lambda x:x['value'], inputs)) - for i in inputs: - self.wallet.add_input_info(i) - output = ('address', to_address, amount) - dummy_tx = Transaction.from_io(inputs, [output]) - fee = self.wallet.estimated_fee(dummy_tx) - amount -= fee - amount /= Decimal(100000000) - fee /= Decimal(100000000) tx = self._mktx([(to_address, amount)], fee, change_addr, domain) return tx diff --git a/lib/wallet.py b/lib/wallet.py @@ -840,16 +840,12 @@ class Abstract_Wallet(object): fee = MIN_RELAY_TX_FEE return fee - def make_unsigned_transaction(self, outputs, fixed_fee=None, change_addr=None, domain=None, coins=None ): + def make_unsigned_transaction(self, coins, outputs, fixed_fee=None, change_addr=None): # check outputs for type, data, value in outputs: if type == 'address': assert is_address(data), "Address " + data + " is invalid!" - # get coins - if not coins: - coins = self.get_spendable_coins(domain) - amount = sum(map(lambda x:x[2], outputs)) total = fee = 0 inputs = [] @@ -923,8 +919,9 @@ class Abstract_Wallet(object): run_hook('make_unsigned_transaction', tx) return tx - def mktx(self, outputs, password, fee=None, change_addr=None, domain= None, coins = None ): - tx = self.make_unsigned_transaction(outputs, fee, change_addr, domain, coins) + def mktx(self, outputs, password, fee=None, change_addr=None, domain=None): + coins = self.get_spendable_coins(domain) + tx = self.make_unsigned_transaction(coins, outputs, fee, change_addr) self.sign_transaction(tx, password) return tx