coin selection: use old coins first
This commit is contained in:
parent
f84b7eb3a8
commit
3333db56c1
|
@ -546,17 +546,24 @@ 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'):
|
||||
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
|
||||
if total >= amount + fee: break
|
||||
else:
|
||||
#print "not enough funds: %d %d"%(total, fee)
|
||||
inputs = []
|
||||
|
|
Loading…
Reference in New Issue