From 2642fa0f7d74e59231564ffa9ae27e3e60e9328d Mon Sep 17 00:00:00 2001 From: thomasv Date: Sat, 23 Feb 2013 13:18:15 +0100 Subject: [PATCH] fix listunspent, add method wallet.get_unspent_coins --- electrum | 3 +-- lib/wallet.py | 43 +++++++++++++++++++------------------------ 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/electrum b/electrum index 7d5bcce5f..12cdb1428 100755 --- a/electrum +++ b/electrum @@ -792,8 +792,7 @@ if __name__ == '__main__': elif cmd == 'listunspent': - unspent = map(lambda x: {"txid":x[0].split(':')[0],"vout":x[0].split(':')[1],"amount":x[1]*1.e-8}, wallet.prevout_values.items() ) - print_json(unspent) + print_json(wallet.get_unspent_coins()) if cmd not in offline_commands and not options.offline: diff --git a/lib/wallet.py b/lib/wallet.py index 296e51b9e..c64922830 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -465,20 +465,9 @@ class Wallet: return conf, unconf - def choose_tx_inputs( self, amount, fixed_fee, from_addr = None ): - """ todo: minimize tx size """ - total = 0 - fee = self.fee if fixed_fee is None else fixed_fee - + def get_unspent_coins(self, domain=None): coins = [] - prioritized_coins = [] - domain = [from_addr] if from_addr else self.all_addresses() - for i in self.frozen_addresses: - if i in domain: domain.remove(i) - - for i in self.prioritized_addresses: - if i in domain: domain.remove(i) - + if domain is None: domain = self.all_addresses() for addr in domain: h = self.history.get(addr, []) if h == ['*']: continue @@ -490,20 +479,26 @@ class Wallet: if key in self.spent_outputs: continue output['tx_hash'] = tx_hash coins.append(output) + return coins - for addr in self.prioritized_addresses: - h = self.history.get(addr, []) - if h == ['*']: continue - for tx_hash, tx_height in h: - tx = self.transactions.get(tx_hash) - for output in tx.d.get('outputs'): - if output.get('address') != addr: continue - key = tx_hash + ":%d" % output.get('index') - if key in self.spent_outputs: continue - output['tx_hash'] = tx_hash - prioritized_coins.append(output) + def choose_tx_inputs( self, amount, fixed_fee, from_addr = None ): + """ todo: minimize tx size """ + total = 0 + fee = self.fee if fixed_fee is None else fixed_fee + + coins = [] + prioritized_coins = [] + domain = [from_addr] if from_addr else self.all_addresses() + for i in self.frozen_addresses: + if i in domain: domain.remove(i) + + for i in self.prioritized_addresses: + if i in domain: domain.remove(i) + + coins = self.get_unspent_coins(domain) + prioritized_coins = self.get_unspent_coins(self.prioritized_addresses) inputs = [] coins = prioritized_coins + coins