willexecutor manager improved

This commit is contained in:
2026-03-17 02:34:01 -04:00
parent 716d4dd5c5
commit a022c413cc
10 changed files with 329 additions and 258 deletions

86
will.py
View File

@@ -12,11 +12,7 @@ from electrum.transaction import (
tx_from_any,
)
from electrum.util import (
FileImportFailed,
bfh,
decimal_point_to_base_unit_name,
read_json_file,
write_json_file,
)
from .util import Util
@@ -85,7 +81,7 @@ class Will:
txin._trusted_value_sats = change.value
try:
txin.script_descriptor = change.script_descriptor
except:
except Exception:
pass
txin.is_mine = True
txin._TxInput__address = change.address
@@ -132,8 +128,8 @@ class Will:
to_delete.append(wid)
to_add[ow.tx.txid()] = ow.to_dict()
for eid, err in errors.items():
new_txid = err.tx.txid()
# for eid, err in errors.items():
# new_txid = err.tx.txid()
for k, w in to_add.items():
will[k] = w
@@ -201,7 +197,7 @@ class Will:
outputs = w.tx.outputs()
found = False
old_txid = w.tx.txid()
ntx = None
# ntx = None
for i in range(0, len(inputs)):
if (
inputs[i].prevout.txid.hex() == otxid
@@ -212,7 +208,7 @@ class Will:
will[wid].tx.set_rbf(True)
will[wid].tx._inputs[i] = Will.new_input(wid, idx, change)
found = True
if found == True:
if found:
pass
new_txid = will[wid].tx.txid()
@@ -239,7 +235,7 @@ class Will:
for i in inputs:
prevout_str = i.prevout.to_str()
inp = [w, will[w], i]
if not prevout_str in all_inputs:
if prevout_str not in all_inputs:
all_inputs[prevout_str] = [inp]
else:
all_inputs[prevout_str].append(inp)
@@ -252,7 +248,7 @@ class Will:
min_locktime = min(values, key=lambda x: x[1].tx.locktime)[1].tx.locktime
for w in values:
if w[1].tx.locktime == min_locktime:
if not i in all_inputs_min_locktime:
if i not in all_inputs_min_locktime:
all_inputs_min_locktime[i] = [w]
else:
all_inputs_min_locktime[i].append(w)
@@ -290,7 +286,7 @@ class Will:
for w in to_delete:
try:
del will[w]
except:
except Exception:
pass
for k, w in to_append.items():
will[k] = w
@@ -300,8 +296,8 @@ class Will:
def update_will(old_will, new_will):
all_old_inputs = Will.get_all_inputs(old_will, only_valid=True)
all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_old_inputs)
all_new_inputs = Will.get_all_inputs(new_will)
# all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_old_inputs)
# all_new_inputs = Will.get_all_inputs(new_will)
# check if the new input is already spent by other transaction
# if it is use the same locktime, or anticipate.
Will.search_anticipate_rec(new_will, all_old_inputs)
@@ -345,9 +341,9 @@ class Will:
prevout_to_spend = []
for prevout_str, ws in inputs.items():
for w in ws:
if not w[0] in filtered_inputs:
if w[0] not in filtered_inputs:
filtered_inputs.append(w[0])
if not prevout_str in prevout_to_spend:
if prevout_str not in prevout_to_spend:
prevout_to_spend.append(prevout_str)
balance = 0
utxo_to_spend = []
@@ -391,7 +387,7 @@ class Will:
return True
def search_rai(all_inputs, all_utxos, will, wallet):
will_only_valid = Will.only_valid_or_replaced_list(will)
# will_only_valid = Will.only_valid_or_replaced_list(will)
for inp, ws in all_inputs.items():
inutxo = Util.in_utxo(inp, all_utxos)
for w in ws:
@@ -429,7 +425,7 @@ class Will:
def set_invalidate(wid, will=[]):
will[wid].set_status("INVALIDATED", True)
if will[wid].children:
for c in self.children.items():
for c in will[wid].children.items():
Will.set_invalidate(c[0], will)
def check_tx_height(tx, wallet):
@@ -446,7 +442,7 @@ class Will:
):
for inp in w.tx.inputs():
inp_str = Util.utxo_to_str(inp)
if not inp_str in utxos_list:
if inp_str not in utxos_list:
if wallet:
height = Will.check_tx_height(w.tx, wallet)
if height < 0:
@@ -456,18 +452,18 @@ class Will:
else:
w.set_status("CONFIRMED", True)
def reflect_to_children(treeitem):
if not treeitem.get_status("VALID"):
_logger.debug(f"{tree:item._id} status not valid looking for children")
for child in treeitem.children:
wc = willtree[child]
if wc.get_status("VALID"):
if treeitem.get_status("INVALIDATED"):
wc.set_status("INVALIDATED", True)
if treeitem.get_status("REPLACED"):
wc.set_status("REPLACED", True)
if wc.children:
Will.reflect_to_children(wc)
# def reflect_to_children(treeitem):
# if not treeitem.get_status("VALID"):
# _logger.debug(f"{tree:item._id} status not valid looking for children")
# for child in treeitem.children:
# wc = willtree[child]
# if wc.get_status("VALID"):
# if treeitem.get_status("INVALIDATED"):
# wc.set_status("INVALIDATED", True)
# if treeitem.get_status("REPLACED"):
# wc.set_status("REPLACED", True)
# if wc.children:
# Will.reflect_to_children(wc)
def check_amounts(heirs, willexecutors, all_utxos, timestamp_to_check, dust):
fixed_heirs, fixed_amount, perc_heirs, perc_amount, fixed_amount_with_dust = (
@@ -565,16 +561,16 @@ class Will:
f"Will Expired {wid[0][0]}: {locktime}<{timestamp_to_check}"
)
def check_all_input_spent_are_in_wallet():
_logger.info("check all input spent are in wallet or valid txs")
for inp, ws in all_inputs.items():
if not Util.in_utxo(inp, all_utxos):
for w in ws:
if w[1].get_status("VALID"):
prevout_id = w[2].prevout.txid.hex()
parentwill = will.get(prevout_id, False)
if not parentwill or not parentwill.get_status("VALID"):
w[1].set_status("INVALIDATED", True)
# def check_all_input_spent_are_in_wallet():
# _logger.info("check all input spent are in wallet or valid txs")
# for inp, ws in all_inputs.items():
# if not Util.in_utxo(inp, all_utxos):
# for w in ws:
# if w[1].get_status("VALID"):
# prevout_id = w[2].prevout.txid.hex()
# parentwill = will.get(prevout_id, False)
# if not parentwill or not parentwill.get_status("VALID"):
# w[1].set_status("INVALIDATED", True)
def only_valid_list(will):
out = {}
@@ -637,7 +633,7 @@ class Will:
if Util.parse_locktime_string(heirs[h][2]) >= check_date:
count_heirs += 1
if not h in heirs_found:
if h not in heirs_found:
_logger.debug(f"heir: {h} not found")
raise HeirNotFoundException(h)
if not count_heirs:
@@ -646,7 +642,7 @@ class Will:
raise NoWillExecutorNotPresent("Backup tx")
for url, we in willexecutors.items():
if Willexecutors.is_selected(we):
if not url in willexecutors_found:
if url not in willexecutors_found:
_logger.debug(f"will-executor: {url} not fount")
raise WillExecutorNotPresent(url)
_logger.info("will is coherent with heirs and will-executors")
@@ -888,7 +884,3 @@ class PercAmountException(AmountException):
class FixedAmountException(AmountException):
pass
def test_check_invalidated():
Will.check_invalidated(will, utxos_list, wallet)