Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnboundLocalError in select_coins #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kyurais
Copy link

@kyurais kyurais commented Feb 16, 2024

bit/bit/transaction.py

Lines 316 to 329 in d351d1d

while unspents:
selected_coins.append(unspents.pop(0))
estimated_fee = estimate_tx_fee(
sum(u.vsize for u in selected_coins), len(selected_coins), sum(output_size), len(output_size), fee, any(u.segwit for u in selected_coins)
)
estimated_fee = fee if absolute_fee else estimated_fee
remaining = sum(u.amount for u in selected_coins) - target - estimated_fee
if remaining >= min_change and (not consolidate or len(unspents) == 0):
break
else:
raise InsufficientFunds(
'Balance {} is less than {} (including '
'fee).'.format(sum(u.amount for u in selected_coins), target + min_change + estimated_fee)
)

estimated_fee integer is initialized within the while block of select_coins, resulting in UnboundLocalError in the case when an empty container is provided for the unspents argument.

from bit.transaction import select_coins

# Should raise InsufficientFunds
s = select_coins(10000, 1, [42], 100, unspents=[])

UnboundLocalError: cannot access local variable 'estimated_fee' where it is not associated with a value

The PR proposes to initialize the estimated_fee integer right before the while condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant