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

82
util.py
View File

@@ -1,12 +1,10 @@
import bisect
import urllib.parse
import urllib.request
from datetime import datetime, timedelta
from electrum.gui.qt.util import getSaveFileName
from electrum.i18n import _
from electrum.transaction import PartialTxOutput
from electrum.util import FileExportFailed, FileImportFailed, write_json_file
from electrum.util import FileExportFailed
LOCKTIME_THRESHOLD = 500000000
@@ -19,7 +17,7 @@ class Util:
dt = datetime.fromtimestamp(locktime).isoformat()
return dt
except Exception as e:
except Exception:
pass
return str(locktime)
@@ -29,7 +27,7 @@ class Util:
return locktime
else:
return int(locktime)
except Exception as e:
except Exception:
pass
dt_object = datetime.fromisoformat(locktime)
timestamp = dt_object.timestamp()
@@ -39,7 +37,7 @@ class Util:
try:
return int(locktime)
except Exception as e:
except Exception:
pass
try:
now = datetime.now()
@@ -58,7 +56,7 @@ class Util:
height = Util.get_current_height(w.network)
locktime += int(height)
return int(locktime)
except Exception as e:
except Exception:
pass
return 0
@@ -77,7 +75,7 @@ class Util:
else:
try:
return int(float(amount) * pow(10, decimal_point))
except:
except Exception:
return 0
def decode_amount(amount, decimal_point):
@@ -87,24 +85,24 @@ class Util:
basestr = "{{:0.{}f}}".format(decimal_point)
try:
return basestr.format(float(amount) / pow(10, decimal_point))
except:
except Exception:
return str(amount)
def is_perc(value):
try:
return value[-1] == "%"
except:
except Exception:
return False
def cmp_array(heira, heirb):
try:
if not len(heira) == len(heirb):
if len(heira) != len(heirb):
return False
for h in range(0, len(heira)):
if not heira[h] == heirb[h]:
if heira[h] != heirb[h]:
return False
return True
except:
except Exception:
return False
def cmp_heir(heira, heirb):
@@ -122,7 +120,7 @@ class Util:
and willexecutora["base_fee"] == willexecutorb["base_fee"]
):
return True
except:
except Exception:
return False
return False
@@ -148,7 +146,7 @@ class Util:
):
for heira in heirsa:
if (
exclude_willexecutors and not 'w!ll3x3c"' in heira
exclude_willexecutors and 'w!ll3x3c"' not in heira
) or not exclude_willexecutors:
found = False
for heirb in heirsb:
@@ -175,8 +173,8 @@ class Util:
):
try:
for heir in heirsa:
if not 'w!ll3x3c"' in heir:
if not heir in heirsb or not cmp_function(
if 'w!ll3x3c"' not in heir:
if heir not in heirsb or not cmp_function(
heirsa[heir], heirsb[heir]
):
if not Util.search_heir_by_values(heirsb, heirsa[heir], [0, 3]):
@@ -215,7 +213,7 @@ class Util:
def get_value_amount(txa, txb):
outputsa = txa.outputs()
outputsb = txb.outputs()
# outputsb = txb.outputs()
value_amount = 0
for outa in outputsa:
@@ -260,10 +258,10 @@ class Util:
def cmp_locktime(locktimea, locktimeb):
if locktimea == locktimeb:
return 0
strlocktime = str(locktimea)
strlocktimea = str(locktimea)
strlocktimeb = str(locktimeb)
intlocktimea = Util.str_to_locktime(strlocktimea)
intlocktimeb = Util.str_to_locktime(strlocktimeb)
# intlocktimea = Util.str_to_locktime(strlocktimea)
# intlocktimeb = Util.str_to_locktime(strlocktimeb)
if locktimea[-1] in "ydb":
if locktimeb[-1] == locktimea[-1]:
return int(strlocktimea[-1]) - int(strlocktimeb[-1])
@@ -284,12 +282,12 @@ class Util:
def get_lowest_locktimes(locktimes):
sorted_timestamp = []
sorted_block = []
for l in locktimes:
l = Util.parse_locktime_string(l)
if l < LOCKTIME_THRESHOLD:
bisect.insort(sorted_block, l)
for locktime in locktimes:
locktime = Util.parse_locktime_string(locktime)
if locktime < LOCKTIME_THRESHOLD:
bisect.insort(sorted_block, locktime)
else:
bisect.insort(sorted_timestamp, l)
bisect.insort(sorted_timestamp, locktime)
return sorted(sorted_timestamp), sorted(sorted_block)
@@ -315,11 +313,11 @@ class Util:
def utxo_to_str(utxo):
try:
return utxo.to_str()
except Exception as e:
except Exception:
pass
try:
return utxo.prevout.to_str()
except Exception as e:
except Exception:
pass
return str(utxo)
@@ -382,7 +380,7 @@ class Util:
out.is_change = True
return out
def get_current_height(network: "Network"):
def get_current_height(network):
# if no network or not up to date, just set locktime to zero
if not network:
return 0
@@ -405,38 +403,34 @@ class Util:
def print_var(var, name="", veryverbose=False):
print(f"---{name}---")
if not var is None:
try:
print("doc:", doc(var))
except:
pass
if var is not None:
try:
print("str:", str(var))
except:
except Exception:
pass
try:
print("repr", repr(var))
except:
except Exception:
pass
try:
print("dict", dict(var))
except:
except Exception:
pass
try:
print("dir", dir(var))
except:
except Exception:
pass
try:
print("type", type(var))
except:
except Exception:
pass
try:
print("to_json", var.to_json())
except:
except Exception:
pass
try:
print("__slotnames__", var.__slotnames__)
except:
except Exception:
pass
print(f"---end {name}---")
@@ -458,11 +452,11 @@ class Util:
Util.print_var(prevout._asdict())
print(f"---prevout-end {name}---")
def export_meta_gui(electrum_window: "ElectrumWindow", title, exporter):
def export_meta_gui(electrum_window, title, exporter):
filter_ = "All files (*)"
filename = getSaveFileName(
parent=electrum_window,
title=_("Select file to save your {}").format(title),
title=_("Select file to save your {}".format(title)),
filename="BALplugin_{}".format(title),
filter=filter_,
config=electrum_window.config,
@@ -475,7 +469,7 @@ class Util:
electrum_window.show_critical(str(e))
else:
electrum_window.show_message(
_("Your {0} were exported to '{1}'").format(title, str(filename))
_("Your {0} were exported to '{1}'".format(title, str(filename)))
)
def copy(dicto, dictfrom):