electrum

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

commit 3333db56c1e841122fd2ff3381a2c714966cb78f
parent f84b7eb3a89c05e8e5503df32a7fc0d0df426d0d
Author: thomasv <thomasv@gitorious>
Date:   Fri, 16 Dec 2011 10:46:25 +0100

coin selection: use old coins first

Diffstat:
Mclient/electrum.py | 19+++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/client/electrum.py b/client/electrum.py @@ -546,16 +546,23 @@ See the release notes for more information.""",1) """ todo: minimize tx size """ total = 0 fee = self.fee if fixed_fee is None else fixed_fee - inputs = [] + + coins = [] for addr in self.all_addresses(): h = self.history.get(addr) + if h is None: continue for item in h: if item.get('raw_scriptPubKey'): - v = item.get('value') - total += v - inputs.append((addr, v, item['tx_hash'], item['pos'], item['raw_scriptPubKey'], None, None) ) - fee = self.fee*len(inputs) if fixed_fee is None else fixed_fee - if total >= amount + fee: break + coins.append( (addr,item)) + + coins = sorted( coins, key = lambda x: x[1]['nTime'] ) + inputs = [] + for c in coins: + addr, item = c + v = item.get('value') + total += v + inputs.append((addr, v, item['tx_hash'], item['pos'], item['raw_scriptPubKey'], None, None) ) + fee = self.fee*len(inputs) if fixed_fee is None else fixed_fee if total >= amount + fee: break else: #print "not enough funds: %d %d"%(total, fee)