fixed refresh and some minor bug about dust amounts and empty wallet

This commit is contained in:
2026-03-05 10:46:38 -04:00
parent c5ad5a61bb
commit ef0ab56de4
4 changed files with 127 additions and 76 deletions

126
heirs.py
View File

@@ -96,9 +96,9 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
locktime = locktime[0]
heirs = locktimes[locktime]
vero = True
while vero:
vero = False
true = True
while true:
true = False
fee = fees.get(locktime, 0)
out_amount = fee
description = ""
@@ -118,12 +118,12 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
out_amount += real_amount
description += f"{name}\n"
except BitcoinException as e:
_logger.info("exception decoding output{} - {}".format(type(e), 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}")
_logger.error(f"error preparing transactions: {e}")
pass
paid_heirs[name] = heir
@@ -138,15 +138,15 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
break
except IndexError as e:
_logger.info(
_logger.error(
f"error preparing transactions index error {e} {in_amount}, {out_amount}"
)
pass
if int(in_amount) < int(out_amount):
_logger.info(
_logger.error(
"error preparing transactions in_amount < out_amount ({} < {}) "
)
break
continue
heirsvalue = out_amount
change = get_change_output(wallet, in_amount, out_amount, fee)
if change:
@@ -319,7 +319,7 @@ class Heirs(dict, Logger):
locktime = Util.parse_locktime_string(self[key][HEIR_LOCKTIME])
if locktime > from_locktime and not a or locktime <= from_locktime and a:
locktimes[int(locktime)] = None
return locktimes.keys()
return list(locktimes.keys())
def check_locktime(self):
return False
@@ -333,6 +333,8 @@ class Heirs(dict, Logger):
column = HEIR_AMOUNT
if real:
column = HEIR_REAL_AMOUNT
if "DUST" in str(v[column]):
column = HEIR_DUST_AMOUNT
value = int(
math.floor(
total_balance
@@ -366,27 +368,32 @@ class Heirs(dict, Logger):
fixed_amount = 0.0
percent_heirs = {}
percent_amount = 0.0
fixed_amount_with_dust =0.0
for key in self.keys():
try:
cmp = (
Util.parse_locktime_string(self[key][HEIR_LOCKTIME]) - from_locktime
)
if cmp <= 0:
_logger.debug("cmp < 0 {} {} {} ".format(cmp, key, self[key][HEIR_LOCKTIME], from_locktime))
continue
if Util.is_perc(self[key][HEIR_AMOUNT]):
percent_amount += float(self[key][HEIR_AMOUNT][:-1])
percent_heirs[key] = list(self[key])
else:
heir_amount = int(math.floor(float(self[key][HEIR_AMOUNT])))
fixed_amount_with_dust += heir_amount
fixed_heirs[key] = list(self[key])
if heir_amount > dust_threshold:
fixed_amount += heir_amount
fixed_heirs[key] = list(self[key])
fixed_heirs[key].insert(HEIR_REAL_AMOUNT, heir_amount)
else:
pass
fixed_heirs[key] = list(self[key])
fixed_heirs[key].insert(HEIR_REAL_AMOUNT, f"DUST: {heir_amount}")
fixed_heirs[key].insert(HEIR_DUST_AMOUNT, heir_amount)
except Exception as e:
_logger.error(e)
return fixed_heirs, fixed_amount, percent_heirs, percent_amount
return fixed_heirs, fixed_amount, percent_heirs, percent_amount, fixed_amount_with_dust
def prepare_lists(
self, balance, total_fees, wallet, willexecutor=False, from_locktime=0
@@ -419,9 +426,13 @@ class Heirs(dict, Logger):
),
heir_list.update(willexecutors)
newbalance -= willexecutors_amount
fixed_heirs, fixed_amount, percent_heirs, percent_amount = (
if newbalance<0:
raise WillExecutorFeeException(willexecutor)
a=list(self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold()))
fixed_heirs, fixed_amount, percent_heirs, percent_amount,fixed_amount_with_dust = (
self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold())
)
if fixed_amount > newbalance:
fixed_amount = self.normalize_perc(
fixed_heirs, newbalance, fixed_amount, wallet
@@ -442,7 +453,7 @@ class Heirs(dict, Logger):
if newbalance > 0:
newbalance += fixed_amount
fixed_amount = self.normalize_perc(
fixed_heirs, newbalance, fixed_amount, wallet, real=True
fixed_heirs, newbalance, fixed_amount_with_dust, wallet, real=True
)
newbalance -= fixed_amount
heir_list.update(fixed_heirs)
@@ -509,7 +520,7 @@ class Heirs(dict, Logger):
break
fees = {}
i = 0
while True:
while i<10:
txs = {}
redo = False
i += 1
@@ -517,47 +528,55 @@ class Heirs(dict, Logger):
for fee in fees:
total_fees += int(fees[fee])
newbalance = balance
locktimes, onlyfixed = self.prepare_lists(
balance, total_fees, wallet, willexecutor, from_locktime
)
try:
txs = prepare_transactions(
locktimes, available_utxos[:], fees, wallet
locktimes, onlyfixed = self.prepare_lists(
balance, total_fees, wallet, willexecutor, from_locktime
)
if not txs:
return {}
except Exception as e:
_logger.info(f"error preparing transactions{e}")
except WillExecutorFeeException as e:
i=10
continue
if locktimes:
try:
if "w!ll3x3c" in e.heirname:
Willexecutors.is_selected(willexecutors[w], False)
break
except:
raise e
total_fees = 0
total_fees_real = 0
total_in = 0
for txid, tx in txs.items():
tx.willexecutor = willexecutor
fee = tx.estimated_size() * tx_fees
txs[txid].tx_fees = tx_fees
total_fees += fee
total_fees_real += tx.get_fee()
total_in += tx.input_value()
rfee = tx.input_value() - tx.output_value()
if rfee < fee or rfee > fee + wallet.dust_threshold():
redo = True
oldfees = fees.get(tx.my_locktime, 0)
fees[tx.my_locktime] = fee
txs = prepare_transactions(
locktimes, available_utxos[:], fees, wallet
)
if not txs:
return {}
except Exception as e:
_logger.error(f"build transactions: error preparing transactions: {e}")
try:
if "w!ll3x3c" in e.heirname:
Willexecutors.is_selected(willexecutors[w], False)
break
except:
raise e
total_fees = 0
total_fees_real = 0
total_in = 0
for txid, tx in txs.items():
tx.willexecutor = willexecutor
fee = tx.estimated_size() * tx_fees
txs[txid].tx_fees = tx_fees
total_fees += fee
total_fees_real += tx.get_fee()
total_in += tx.input_value()
rfee = tx.input_value() - tx.output_value()
if rfee < fee or rfee > fee + wallet.dust_threshold():
redo = True
oldfees = fees.get(tx.my_locktime, 0)
fees[tx.my_locktime] = fee
if balance - total_in > wallet.dust_threshold():
redo = True
if not redo:
break
if i >= 10:
if balance - total_in > wallet.dust_threshold():
redo = True
if not redo:
break
if i >= 10:
break
else:
_logger.info(f"no locktimes for willexecutor {willexecutor} skipped")
break
alltxs.update(txs)
return alltxs
def get_transactions(
@@ -714,3 +733,10 @@ class HeirExpiredException(LocktimeNotValid):
class HeirAmountIsDustException(Exception):
pass
class NoHeirsException(Exception):
pass
class WillExecutorFeeException(Exception):
def __init__(self,willexecutor):
self.willexecutor=willexecutor
def __str__(self):
return "WillExecutorFeeException: {} fee:{}".format(self.willexecutor['url'],self.willexecutor['base_fee'])