invalidation and locktime

This commit is contained in:
2026-04-05 11:39:17 -04:00
parent e2de4a3afa
commit c8ab85b735
4 changed files with 138 additions and 69 deletions

View File

@@ -341,6 +341,7 @@ class Heirs(dict, Logger):
def normalize_perc(
self, heir_list, total_balance, relative_balance, wallet, real=False
):
print("relative balance", relative_balance)
amount = 0
for key, v in heir_list.items():
try:
@@ -424,6 +425,16 @@ class Heirs(dict, Logger):
def prepare_lists(
self, balance, total_fees, wallet, willexecutor=False, from_locktime=0
):
if balance<total_fees or balance < wallet.dust_threshold():
print("balance < total_fees")
raise BalanceTooLowException(balance,wallet.dust_threshold(),total_fees)
print("prepare lists")
print("balance",balance)
print("total fees",total_fees)
print("willexecutor", willexecutor)
print("from_locktime", from_locktime)
print("wallet",wallet)
print("dust threshold",wallet.dust_threshold())
willexecutors_amount = 0
willexecutors = {}
heir_list = {}
@@ -435,16 +446,15 @@ class Heirs(dict, Logger):
if int(Util.int_locktime(locktime)) > int(from_locktime):
try:
base_fee = int(willexecutor["base_fee"])
if base_fee > dust_threshold:
willexecutors_amount += base_fee
h = [None] * 4
h[HEIR_AMOUNT] = base_fee
h[HEIR_REAL_AMOUNT] = base_fee
h[HEIR_LOCKTIME] = locktime
h[HEIR_ADDRESS] = willexecutor["address"]
willexecutors[
'w!ll3x3c"' + willexecutor["url"] + '"' + str(locktime)
] = h
willexecutors_amount += base_fee
h = [None] * 4
h[HEIR_AMOUNT] = base_fee
h[HEIR_REAL_AMOUNT] = base_fee
h[HEIR_LOCKTIME] = locktime
h[HEIR_ADDRESS] = willexecutor["address"]
willexecutors[
'w!ll3x3c"' + willexecutor["url"] + '"' + str(locktime)
] = h
except Exception:
return [], False
else:
@@ -452,6 +462,8 @@ class Heirs(dict, Logger):
f"heir excluded from will locktime({locktime}){Util.int_locktime(locktime)}<minimum{from_locktime}"
),
heir_list.update(willexecutors)
print("willexecutor amount", willexecutors_amount)
print("heir_list",heir_list)
newbalance -= willexecutors_amount
if newbalance < 0:
raise WillExecutorFeeException(willexecutor)
@@ -462,8 +474,9 @@ class Heirs(dict, Logger):
percent_amount,
fixed_amount_with_dust,
) = self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold())
print("qua non ci arriva 1")
if fixed_amount > newbalance:
print(fixed_heirs,newbalance,fixed_amount)
fixed_amount = self.normalize_perc(
fixed_heirs, newbalance, fixed_amount, wallet
)
@@ -472,14 +485,15 @@ class Heirs(dict, Logger):
heir_list.update(fixed_heirs)
newbalance -= fixed_amount
print("new balance", newbalance)
if newbalance > 0:
perc_amount = self.normalize_perc(
percent_heirs, newbalance, percent_amount, wallet
)
print("normalize perc", perc_amount)
newbalance -= perc_amount
heir_list.update(percent_heirs)
print("newbalance2",newbalance)
if newbalance > 0:
newbalance += fixed_amount
fixed_amount = self.normalize_perc(
@@ -500,6 +514,7 @@ class Heirs(dict, Logger):
locktimes[locktime] = {key: value}
else:
locktimes[locktime][key] = value
print(2)
return locktimes, onlyfixed
def is_perc(self, key):
@@ -567,9 +582,11 @@ class Heirs(dict, Logger):
continue
if locktimes:
try:
print(3)
txs = prepare_transactions(
locktimes, available_utxos[:], fees, wallet
)
print(4)
if not txs:
return {}
except Exception as e:
@@ -783,3 +800,10 @@ class WillExecutorFeeException(Exception):
return "WillExecutorFeeException: {} fee:{}".format(
self.willexecutor["url"], self.willexecutor["base_fee"]
)
class BalanceTooLowException(Exception):
def __init__(self,balance, dust_threshold, fees):
self.balance=balance
self.dust_threshold = dust_threshold
self.fees = fees
def __str__(self):
return f"Balance too low, balance: {self.balance}, dust threshold: {self.dust_threshold}, fees: {self.fees}"