ofek / bit

Bitcoin made easy.
https://ofek.dev/bit/
MIT License
1.25k stars 216 forks source link

Fix UnboundLocalError in select_coins #185

Open kyurais opened 9 months ago

kyurais commented 9 months ago

https://github.com/ofek/bit/blob/d351d1d819abfdb973411b4c8855d784ab58046c/bit/transaction.py#L316-L329 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.