mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-29 16:31:29 +00:00
make_transaction: remove unneeded inputs
This commit is contained in:
parent
7becb28ec8
commit
ae957f3736
1 changed files with 12 additions and 0 deletions
|
@ -26,6 +26,7 @@ import time
|
||||||
import math
|
import math
|
||||||
import json
|
import json
|
||||||
import copy
|
import copy
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
from util import print_msg, print_error, NotEnoughFunds
|
from util import print_msg, print_error, NotEnoughFunds
|
||||||
from util import profiler
|
from util import profiler
|
||||||
|
@ -856,6 +857,7 @@ class Abstract_Wallet(object):
|
||||||
total = fee = 0
|
total = fee = 0
|
||||||
inputs = []
|
inputs = []
|
||||||
tx = Transaction.from_io(inputs, outputs)
|
tx = Transaction.from_io(inputs, outputs)
|
||||||
|
# add old inputs first
|
||||||
for item in coins:
|
for item in coins:
|
||||||
v = item.get('value')
|
v = item.get('value')
|
||||||
total += v
|
total += v
|
||||||
|
@ -865,6 +867,16 @@ class Abstract_Wallet(object):
|
||||||
if total >= amount + fee: break
|
if total >= amount + fee: break
|
||||||
else:
|
else:
|
||||||
raise NotEnoughFunds()
|
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
|
# change address
|
||||||
if not change_addr:
|
if not change_addr:
|
||||||
|
|
Loading…
Add table
Reference in a new issue