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 """ """ todo: minimize tx size """
total = 0 total = 0
fee = self.fee if fixed_fee is None else fixed_fee fee = self.fee if fixed_fee is None else fixed_fee
inputs = []
coins = []
for addr in self.all_addresses(): for addr in self.all_addresses():
h = self.history.get(addr) h = self.history.get(addr)
if h is None: continue
for item in h: for item in h:
if item.get('raw_scriptPubKey'): if item.get('raw_scriptPubKey'):
v = item.get('value') coins.append( (addr,item))
total += v
inputs.append((addr, v, item['tx_hash'], item['pos'], item['raw_scriptPubKey'], None, None) ) coins = sorted( coins, key = lambda x: x[1]['nTime'] )
fee = self.fee*len(inputs) if fixed_fee is None else fixed_fee inputs = []
if total >= amount + fee: break 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 if total >= amount + fee: break
else: else:
#print "not enough funds: %d %d"%(total, fee) #print "not enough funds: %d %d"%(total, fee)