dust bugfix

This commit is contained in:
2026-02-09 12:10:31 -04:00
parent 2a4eab81fd
commit f7bd09df91
5 changed files with 207 additions and 98 deletions

View File

@@ -29,6 +29,8 @@ from electrum.util import (
from .util import Util
from .willexecutors import Willexecutors
from electrum.util import BitcoinException
from electrum import constants
if TYPE_CHECKING:
from .simple_config import SimpleConfig
@@ -41,6 +43,7 @@ HEIR_ADDRESS = 0
HEIR_AMOUNT = 1
HEIR_LOCKTIME = 2
HEIR_REAL_AMOUNT = 3
HEIR_DUST_AMOUNT = 4
TRANSACTION_LABEL = "inheritance transaction"
@@ -88,6 +91,7 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
txsout = {}
locktime, _ = Util.get_lowest_locktimes(locktimes)
if not locktime:
_logger.info("prepare transactions, no locktime")
return
locktime = locktime[0]
@@ -101,22 +105,27 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
outputs = []
paid_heirs = {}
for name, heir in heirs.items():
try:
if len(heir) > HEIR_REAL_AMOUNT:
if len(heir) > HEIR_REAL_AMOUNT and not "DUST" in str(
heir[HEIR_REAL_AMOUNT]
):
try:
real_amount = heir[HEIR_REAL_AMOUNT]
out_amount += real_amount
description += f"{name}\n"
paid_heirs[name] = heir
outputs.append(
PartialTxOutput.from_address_and_value(
heir[HEIR_ADDRESS], real_amount
)
)
else:
out_amount += real_amount
description += f"{name}\n"
except BitcoinException as e:
_logger.info("exception decoding output{} - {}".format(type(e), e))
heir[HEIR_REAL_AMOUNT] = e
except Exception as e:
heir[HEIR_REAL_AMOUNT] = e
_logger.info(f"error preparing transactions {e}")
pass
except Exception as e:
pass
paid_heirs[name] = heir
in_amount = 0.0
used_utxos = []
@@ -125,12 +134,18 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
value = utxo.value_sats()
in_amount += value
used_utxos.append(utxo)
if in_amount > out_amount:
if in_amount >= out_amount:
break
except IndexError as e:
_logger.info(
f"error preparing transactions index error {e} {in_amount}, {out_amount}"
)
pass
if int(in_amount) < int(out_amount):
_logger.info(
"error preparing transactions in_amount < out_amount ({} < {}) "
)
break
heirsvalue = out_amount
change = get_change_output(wallet, in_amount, out_amount, fee)
@@ -263,9 +278,10 @@ def get_change_output(wallet, in_amount, out_amount, fee):
class Heirs(dict, Logger):
def __init__(self, db: "WalletDB"):
def __init__(self, wallet):
Logger.__init__(self)
self.db = db
self.db = wallet.db
self.wallet = wallet
d = self.db.get("heirs", {})
try:
self.update(d)
@@ -327,6 +343,10 @@ class Heirs(dict, Logger):
if value > wallet.dust_threshold():
heir_list[key].insert(HEIR_REAL_AMOUNT, value)
amount += value
else:
heir_list[key].insert(HEIR_REAL_AMOUNT, f"DUST: {value}")
heir_list[key].insert(HEIR_DUST_AMOUNT, value)
_logger.info(f"{key}, {value} is dust will be ignored")
except Exception as e:
raise e
@@ -449,6 +469,7 @@ class Heirs(dict, Logger):
):
Heirs._validate(self)
if len(self) <= 0:
_logger.info("while building transactions there was no heirs")
return
balance = 0.0
len_utxo_set = 0
@@ -464,6 +485,7 @@ class Heirs(dict, Logger):
len_utxo_set += 1
available_utxos.append(utxo)
if len_utxo_set == 0:
_logger.info("no usable utxos")
return
j = -2
willexecutorsitems = list(willexecutors.items())
@@ -505,6 +527,7 @@ class Heirs(dict, Logger):
if not txs:
return {}
except Exception as e:
_logger.info(f"error preparing transactions{e}")
try:
if "w!ll3x3c" in e.heirname:
Willexecutors.is_selected(willexecutors[w], False)
@@ -632,7 +655,7 @@ class Heirs(dict, Logger):
return None
def validate_address(address):
if not bitcoin.is_address(address):
if not bitcoin.is_address(address, net=constants.net):
raise NotAnAddress(f"not an address,{address}")
return address
@@ -661,12 +684,14 @@ class Heirs(dict, Logger):
return (address, amount, locktime)
def _validate(data, timestamp_to_check=False):
for k, v in list(data.items()):
if k == "heirs":
return Heirs._validate(v)
return Heirs._validate(v, timestamp_to_check)
try:
Heirs.validate_heir(k, v)
Heirs.validate_heir(k, v, timestamp_to_check)
except Exception as e:
_logger.info(f"exception heir removed {e}")
data.pop(k)
return data
@@ -685,3 +710,7 @@ class LocktimeNotValid(ValueError):
class HeirExpiredException(LocktimeNotValid):
pass
class HeirAmountIsDustException(Exception):
pass