commit ae957f37364d0c61f6658c6b877d5efbc5e3c5a4
parent 7becb28ec8a550f8749b0b1e80233c12b2498644
Author: ThomasV <thomasv@gitorious>
Date: Tue, 26 May 2015 09:05:44 +0200
make_transaction: remove unneeded inputs
Diffstat:
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -26,6 +26,7 @@ import time
import math
import json
import copy
+from operator import itemgetter
from util import print_msg, print_error, NotEnoughFunds
from util import profiler
@@ -856,6 +857,7 @@ class Abstract_Wallet(object):
total = fee = 0
inputs = []
tx = Transaction.from_io(inputs, outputs)
+ # add old inputs first
for item in coins:
v = item.get('value')
total += v
@@ -865,6 +867,16 @@ class Abstract_Wallet(object):
if total >= amount + fee: break
else:
raise NotEnoughFunds()
+ # remove unneeded inputs
+ for item in sorted(tx.inputs, key=itemgetter('value')):
+ v = item.get('value')
+ if total - v >= amount + fee:
+ tx.inputs.remove(item)
+ total -= v
+ fee = fixed_fee if fixed_fee is not None else self.estimated_fee(tx)
+ else:
+ break
+ print_error("using %d inputs"%len(tx.inputs))
# change address
if not change_addr: