Avoid index-out-of-range
Also add sanity assertion
This commit is contained in:
@@ -67,6 +67,7 @@ class CoinChooserBase(PrintError):
|
|||||||
amounts = self.change_amounts(tx, len(change_addrs), fee_estimator,
|
amounts = self.change_amounts(tx, len(change_addrs), fee_estimator,
|
||||||
dust_threshold)
|
dust_threshold)
|
||||||
assert min(amounts) >= 0
|
assert min(amounts) >= 0
|
||||||
|
assert len(change_addrs) >= len(amounts)
|
||||||
# If change is above dust threshold after accounting for the
|
# If change is above dust threshold after accounting for the
|
||||||
# size of the change output, add it to the transaction.
|
# size of the change output, add it to the transaction.
|
||||||
dust = sum(amount for amount in amounts if amount < dust_threshold)
|
dust = sum(amount for amount in amounts if amount < dust_threshold)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import json
|
|||||||
import copy
|
import copy
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from util import PrintError, profiler
|
from util import NotEnoughFunds, PrintError, profiler
|
||||||
|
|
||||||
from bitcoin import *
|
from bitcoin import *
|
||||||
from account import *
|
from account import *
|
||||||
@@ -897,6 +897,10 @@ class Abstract_Wallet(PrintError):
|
|||||||
if type == 'address':
|
if type == 'address':
|
||||||
assert is_address(data), "Address " + data + " is invalid!"
|
assert is_address(data), "Address " + data + " is invalid!"
|
||||||
|
|
||||||
|
# Avoid index-out-of-range with coins[0] below
|
||||||
|
if not coins:
|
||||||
|
raise NotEnoughFunds()
|
||||||
|
|
||||||
for item in coins:
|
for item in coins:
|
||||||
self.add_input_info(item)
|
self.add_input_info(item)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user