coin selection: use old coins first

This commit is contained in:
thomasv 2011-12-16 10:46:25 +01:00
parent f84b7eb3a8
commit 3333db56c1
1 changed files with 13 additions and 6 deletions

View File

@ -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)