forked from bitcoinafterlife/bal-electrum-plugin
feat(bal): Group A (timestamps + statuses + anticipate docs) and Group B (auto-sign) v0.3.4
Bump plugin version to 0.3.4 (manifest, __init__, plugin_base, VERSION). GROUP A - A1: remove block-height locktimes; the plugin now uses UNIX timestamps only. The NLOCKTIME_BLOCKHEIGHT_MAX guard is kept on purpose (it forces every locktime to be a timestamp). chk_locktime is now 2-arg; int_locktime and anticipate_locktime no longer accept blocks; RAW input only accepts d/y. Two now-dormant configs (LOCKTIME_BLOCKS, LOCKTIMEDELTA_BLOCKS) are kept with comments to avoid touching persisted keys. - A2: rename PENDING -> MEMPOOL everywhere (label 'Mempool', yellow #ffce30); add new UPDATED status; ANTICIPATED & UPDATED keep VALID; documented set_status rules; backward-compat migration (old PENDING -> MEMPOOL). - A3: clarify that anticipating to a future date only rebuilds (never invalidates), while only a past locktime invalidates (WillExpired). Code was already correct; only the comment and docs were fixed. Colour follow-up: UPDATED lightened from #800080 to #b266b2 (more readable), updated in theme.py, docs and the theme test. GROUP B - B1: verified the 'Create your will' button already opens the guided wizard (no code change needed). - B2: new persisted AUTO_SIGN setting (default ON) with an 'Auto-sign on Check' checkbox in the settings dialog. When enabled, Check signs and broadcasts automatically; the wallet password is requested only for encrypted wallets. B2 follow-up (fixes reported after testing): - Remove the duplicate sign/broadcast cycle in lists.check(); build_will_task() already signs and broadcasts. - Suppress the manual 'press Sign/Broadcast' hint and its popup when AUTO_SIGN is ON (kept when OFF). - Make broadcast one-shot: removed the retry flag and the Exception('retry'); failed will-executors stay PUSH_FAIL and are skipped (no endless retry). PUSHED transactions are already excluded from re-collection. Docs: inheritance-options.md/.html and inheritance-flow.svg updated to v0.3.4. Tests: 206 passing (new test_anticipate_manual_locktime, test_anticipate_past_locktime, test_group_b_auto_sign; updated core/util, core/will_extra, gui/theme, gui/widgets). CHANGELOG.md added with one numbered entry per task.
This commit is contained in:
@@ -720,10 +720,18 @@ class BalBuildWillDialog(BalDialog):
|
||||
self.msg_set_invalidating(self.msg_error(e))
|
||||
|
||||
def loop_push(self):
|
||||
# Broadcast is "one-shot" (Group B / B2 follow-up): each selected
|
||||
# will-executor is contacted ONCE. Transactions that are broadcast
|
||||
# successfully become PUSHED; transactions whose server fails or times
|
||||
# out are left as PUSH_FAIL and simply skipped - they are NOT retried
|
||||
# automatically. A dead will-executor could otherwise never answer and
|
||||
# make the plugin retry forever. The user can broadcast a failed
|
||||
# transaction manually later with the "Broadcast" button. Note that
|
||||
# get_willexecutor_transactions already excludes PUSHED transactions, so
|
||||
# the successful ones are never re-sent on a subsequent run.
|
||||
if self._stopping:
|
||||
return
|
||||
self.msg_set_pushing(_("Broadcasting"))
|
||||
retry = False
|
||||
try:
|
||||
|
||||
willexecutors = Willexecutors.get_willexecutor_transactions(
|
||||
@@ -744,7 +752,6 @@ class BalBuildWillDialog(BalDialog):
|
||||
# them sequentially after the parallel push, keeping the original
|
||||
# check logic untouched.
|
||||
already_present = []
|
||||
retry_flag = {"value": False}
|
||||
total = len(selected)
|
||||
done = {"count": 0}
|
||||
|
||||
@@ -770,9 +777,10 @@ class BalBuildWillDialog(BalDialog):
|
||||
for wid in willexecutor["txsids"]:
|
||||
self.bal_window.willitems[wid].set_status("PUSHED", True)
|
||||
else:
|
||||
# One-shot: mark the failed transactions and move on. They
|
||||
# are left as PUSH_FAIL (no automatic retry).
|
||||
for wid in willexecutor["txsids"]:
|
||||
self.bal_window.willitems[wid].set_status("PUSH_FAIL", True)
|
||||
retry_flag["value"] = True
|
||||
done["count"] += 1
|
||||
# Show the per-server result (Ok/Ko) in bold + color so the
|
||||
# outcome stands out, keeping the server URL in normal weight.
|
||||
@@ -781,11 +789,11 @@ class BalBuildWillDialog(BalDialog):
|
||||
self.msg_set_pushing(_status_line())
|
||||
|
||||
def on_timeout(url, willexecutor):
|
||||
# The global deadline elapsed before this server answered. Mark
|
||||
# its txs as failed (so the user can retry later) and show it.
|
||||
# The global deadline elapsed before this server answered. Mark
|
||||
# its txs as failed and move on (one-shot: no automatic retry).
|
||||
# The user can broadcast them manually later if desired.
|
||||
for wid in willexecutor.get("txsids", []):
|
||||
self.bal_window.willitems[wid].set_status("PUSH_FAIL", True)
|
||||
retry_flag["value"] = True
|
||||
self.msg_edit_row(
|
||||
"{} : {}".format(url, self.msg_error(_("Timeout - no answer")))
|
||||
)
|
||||
@@ -820,7 +828,6 @@ class BalBuildWillDialog(BalDialog):
|
||||
"{}/{} ({}s)".format(done["count"], total,
|
||||
int(time.time() - push_start))
|
||||
)
|
||||
retry = retry_flag["value"]
|
||||
|
||||
# Verify the "already present" servers (sequential, original logic).
|
||||
self.bal_plugin = self.bal_window.bal_plugin
|
||||
@@ -851,15 +858,18 @@ class BalBuildWillDialog(BalDialog):
|
||||
row,
|
||||
)
|
||||
|
||||
if retry:
|
||||
raise Exception("retry")
|
||||
# One-shot broadcast: we deliberately do NOT raise/retry when some
|
||||
# will-executors failed. Their transactions stay PUSH_FAIL and are
|
||||
# left for the user to broadcast manually. This prevents an endless
|
||||
# retry loop against a will-executor that may never answer.
|
||||
|
||||
except Exception as e:
|
||||
# Only genuine, unexpected errors reach here now (not the old
|
||||
# "retry" signal). Report the error; do not loop.
|
||||
self.msg_set_pushing(self.msg_error(e))
|
||||
self.wait(10)
|
||||
if not self._stopping:
|
||||
pass
|
||||
# self.loop_push()
|
||||
|
||||
def invalidate_task(self, password, bal_window, tx):
|
||||
if self._stopping:
|
||||
@@ -1038,6 +1048,18 @@ class BalBuildWillDialog(BalDialog):
|
||||
short to be sure the user noticed the in-dialog line).
|
||||
"""
|
||||
self._next_steps_hint = None
|
||||
# Group B / B2: when AUTO_SIGN is ON the dialog has already signed and
|
||||
# broadcast the will automatically, so the manual "press Sign/Broadcast"
|
||||
# hints (and the follow-up popup) would be wrong/confusing. Suppress
|
||||
# them in that case. When AUTO_SIGN is OFF, keep the previous behaviour
|
||||
# and guide the user through the remaining manual steps.
|
||||
try:
|
||||
if self.bal_window.bal_plugin.AUTO_SIGN.get():
|
||||
return
|
||||
except Exception:
|
||||
# If the setting cannot be read for any reason, fall back to the
|
||||
# original behaviour (show the manual hints).
|
||||
pass
|
||||
try:
|
||||
need_sign = False
|
||||
need_push = False
|
||||
|
||||
@@ -551,6 +551,12 @@ class PreviewList(MyTreeView, MessageBoxMixin):
|
||||
if will:
|
||||
self.bal_window.check_transactions(will)
|
||||
self.update()
|
||||
# NOTE (Group B / B2): signing + broadcasting is already performed
|
||||
# automatically by BalBuildWillDialog.build_will_task() above (called at
|
||||
# the start of check()). We must NOT trigger a second sign/broadcast
|
||||
# cycle here, otherwise the will would be broadcast twice. Whether the
|
||||
# automatic sign/broadcast runs silently or shows the manual "next step"
|
||||
# hints is controlled by the AUTO_SIGN setting inside that dialog.
|
||||
|
||||
def invalidate_will(self):
|
||||
self.bal_window.invalidate_will()
|
||||
|
||||
@@ -389,6 +389,13 @@ class Plugin(BalPlugin):
|
||||
heir_hide_replaced = BalCheckBox(self.HIDE_REPLACED, on_multiverse_change)
|
||||
|
||||
heir_hide_invalidated = BalCheckBox(self.HIDE_INVALIDATED, on_multiverse_change)
|
||||
|
||||
# Auto-sign checkbox (Group B / B2). When ticked, the "Check" action
|
||||
# automatically signs and broadcasts the will after querying the
|
||||
# will-executor servers. Bound to the persisted AUTO_SIGN config; the
|
||||
# default is ON (see plugin_base.py).
|
||||
heir_auto_sign = BalCheckBox(self.AUTO_SIGN)
|
||||
|
||||
heir_repush = QPushButton("Rebroadcast transactions")
|
||||
heir_repush.clicked.connect(partial(self.broadcast_transactions, True))
|
||||
bal_mode = QComboBox()
|
||||
@@ -410,18 +417,30 @@ class Plugin(BalPlugin):
|
||||
2,
|
||||
"Hide invalidated transactions from will detail and list",
|
||||
)
|
||||
add_widget(
|
||||
grid,
|
||||
"Auto-sign on Check",
|
||||
heir_auto_sign,
|
||||
3,
|
||||
(
|
||||
"When checking, automatically sign and broadcast the will "
|
||||
"transactions to their will-executors.\n"
|
||||
"The wallet password is requested only if the wallet is "
|
||||
"encrypted."
|
||||
),
|
||||
)
|
||||
add_widget(
|
||||
grid,
|
||||
"Calendar App",
|
||||
BalLineEdit(self.CALENDAR_APP),
|
||||
3,
|
||||
4,
|
||||
"Default app used to open calendar",
|
||||
)
|
||||
add_widget(
|
||||
grid,
|
||||
"Event summary",
|
||||
BalLineEdit(self.EVENT_SUMMARY),
|
||||
4,
|
||||
5,
|
||||
(
|
||||
"Default message to be used in event summary\n"
|
||||
"Variables:\n"
|
||||
@@ -432,9 +451,9 @@ class Plugin(BalPlugin):
|
||||
)
|
||||
add_widget(
|
||||
grid,
|
||||
"Event sescription",
|
||||
"Event description",
|
||||
BalTextEdit(self.EVENT_DESCRIPTION),
|
||||
5,
|
||||
6,
|
||||
(
|
||||
"Default message to be used in event description\n"
|
||||
"Variables:\n"
|
||||
|
||||
@@ -22,8 +22,9 @@ status into a colour for the transaction list / detail views.
|
||||
_STATUS_COLOR_PRIORITY = (
|
||||
("INVALIDATED", "#f87838"), # orange - tx can no longer be mined
|
||||
("REPLACED", "#ff97e9"), # pink - superseded by another tx
|
||||
("UPDATED", "#b266b2"), # light violet - replaced keeping same locktime+heirs
|
||||
("CONFIRMED", "#bfbfbf"), # grey - already mined
|
||||
("PENDING", "#ffce30"), # yellow - in mempool, waiting
|
||||
("MEMPOOL", "#ffce30"), # yellow - seen in the Electrum mempool
|
||||
)
|
||||
|
||||
# Default colour used when no status in the priority list matches.
|
||||
|
||||
@@ -347,12 +347,16 @@ class LockTimeRawEdit(QLineEdit, _LockTimeEditor):
|
||||
self.textChanged.connect(self.numbify)
|
||||
self.isdays = False
|
||||
self.isyears = False
|
||||
self.isblocks = False
|
||||
self.time_edit = time_edit
|
||||
|
||||
@staticmethod
|
||||
def replace_str(text):
|
||||
return str(text).replace("d", "").replace("y", "").replace("b", "")
|
||||
"""Strip the relative-time suffixes (d/y) from the text.
|
||||
|
||||
Only days ("d") and years ("y") are supported. The block-height
|
||||
suffix ("b") was removed (A1): locktimes are always timestamps now.
|
||||
"""
|
||||
return str(text).replace("d", "").replace("y", "")
|
||||
|
||||
def checkbdy(self, s, pos, appendix):
|
||||
try:
|
||||
@@ -367,33 +371,29 @@ class LockTimeRawEdit(QLineEdit, _LockTimeEditor):
|
||||
return pos, s
|
||||
|
||||
def numbify(self):
|
||||
# Only digits plus the day ("d") and year ("y") suffixes are accepted.
|
||||
# The block-height suffix ("b") was removed (A1): locktimes are always
|
||||
# UNIX timestamps now, so block-relative input is no longer allowed.
|
||||
text = self.text().strip()
|
||||
# chars = '0123456789bdy' removed the option to choose locktime by block
|
||||
chars = "0123456789dy"
|
||||
pos = self.cursorPosition()
|
||||
pos = len("".join([i for i in text[:pos] if i in chars]))
|
||||
s = "".join([i for i in text if i in chars])
|
||||
self.isdays = False
|
||||
self.isyears = False
|
||||
self.isblocks = False
|
||||
|
||||
pos, s = self.checkbdy(s, pos, "d")
|
||||
pos, s = self.checkbdy(s, pos, "y")
|
||||
pos, s = self.checkbdy(s, pos, "b")
|
||||
|
||||
if "d" in s:
|
||||
self.isdays = True
|
||||
if "y" in s:
|
||||
self.isyears = True
|
||||
if "b" in s:
|
||||
self.isblocks = True
|
||||
|
||||
if self.isdays:
|
||||
s = self.replace_str(s) + "d"
|
||||
if self.isyears:
|
||||
s = self.replace_str(s) + "y"
|
||||
if self.isblocks:
|
||||
s = self.replace_str(s) + "b"
|
||||
self.blockSignals(True)
|
||||
self.setText(s)
|
||||
self.blockSignals(False)
|
||||
@@ -420,6 +420,11 @@ class LockTimeRawEdit(QLineEdit, _LockTimeEditor):
|
||||
|
||||
|
||||
class LockTimeDateEdit(QDateTimeEdit, _LockTimeEditor):
|
||||
# GUARD (kept on purpose, A1): NLOCKTIME_BLOCKHEIGHT_MAX is the highest value
|
||||
# Bitcoin interprets as a *block height*. By forcing the minimum to one above
|
||||
# it, every locktime entered here is guaranteed to be a UNIX *timestamp*,
|
||||
# never a block height. This is NOT block-height ordering; it is the
|
||||
# "bouncer" that prevents block-height values from ever being used again.
|
||||
min_allowed_value = NLOCKTIME_BLOCKHEIGHT_MAX + 1
|
||||
max_allowed_value = _LockTimeEditor.get_max_allowed_timestamp()
|
||||
|
||||
|
||||
@@ -368,7 +368,6 @@ class BalWindow:
|
||||
def check_will(self):
|
||||
return Will.is_will_valid(
|
||||
self.willitems,
|
||||
self.block_to_check,
|
||||
self.date_to_check,
|
||||
self.will_settings["baltx_fees"],
|
||||
self.window.wallet.get_utxos(),
|
||||
@@ -459,9 +458,10 @@ class BalWindow:
|
||||
try:
|
||||
self.date_to_check = BalTimestamp(self.will_settings['threshold']).to_timestamp()
|
||||
# found = False
|
||||
self.locktime_blocks = self.bal_plugin.LOCKTIME_BLOCKS.get()
|
||||
self.current_block = Util.get_current_height(self.wallet.network)
|
||||
self.block_to_check = 0
|
||||
# NOTE: block-height tracking removed (A1) - locktimes are always
|
||||
# UNIX timestamps now, so we no longer read the current block height
|
||||
# or compute a block_to_check here. Validity is decided purely by
|
||||
# comparing locktimes against date_to_check (a timestamp).
|
||||
self.no_willexecutor = self.bal_plugin.NO_WILLEXECUTOR.get()
|
||||
self.willexecutors = Willexecutors.get_willexecutors(
|
||||
self.bal_plugin, update=True, bal_window=self, task=False
|
||||
@@ -479,6 +479,10 @@ class BalWindow:
|
||||
|
||||
def build_inheritance_transaction(self, ignore_duplicate=True, keep_original=True):
|
||||
try:
|
||||
_logger.info(
|
||||
"BAL-plugin \u25b8 STEP 1/7: prepare inheritance "
|
||||
"(validate settings, amounts and locktime)"
|
||||
)
|
||||
if self.disable_plugin:
|
||||
_logger.info("plugin is disabled")
|
||||
return
|
||||
@@ -523,11 +527,26 @@ class BalWindow:
|
||||
return
|
||||
|
||||
try:
|
||||
_logger.info(
|
||||
"BAL-plugin \u25b8 STEP 2/7: checking if the current will is "
|
||||
"still coherent (heirs, will-executors, fees, locktime)"
|
||||
)
|
||||
self.check_will()
|
||||
_logger.info(
|
||||
"BAL-plugin \u25b8 STEP 2/7 result: will is COHERENT, "
|
||||
"nothing to rebuild"
|
||||
)
|
||||
except WillExpiredException:
|
||||
_logger.info(
|
||||
"BAL-plugin \u25b8 STEP 2/7 result: will EXPIRED -> "
|
||||
"invalidating on-chain (real fee)"
|
||||
)
|
||||
self.invalidate_will()
|
||||
return
|
||||
except NoHeirsException:
|
||||
_logger.info(
|
||||
"BAL-plugin \u25b8 STEP 2/7 result: no valid heirs -> abort"
|
||||
)
|
||||
return
|
||||
except WillPostponedException as e:
|
||||
# The will was already signed/sent and is being postponed.
|
||||
@@ -536,6 +555,10 @@ class BalWindow:
|
||||
# can never be used by a will-executor), then press "Prepare"
|
||||
# again
|
||||
# to create the new postponed inheritance.
|
||||
_logger.info(
|
||||
"BAL-plugin \u25b8 STEP 2/7 result: will POSTPONED on a "
|
||||
"signed/sent tx -> must invalidate on-chain first (real fee)"
|
||||
)
|
||||
_logger.info(f"will postponed: {e}")
|
||||
self.show_message(
|
||||
_(
|
||||
@@ -553,6 +576,10 @@ class BalWindow:
|
||||
self.invalidate_will()
|
||||
return
|
||||
except NotCompleteWillException as e:
|
||||
_logger.info(
|
||||
"BAL-plugin \u25b8 STEP 2/7 result: will NOT coherent -> "
|
||||
"REBUILD needed (no on-chain fee)"
|
||||
)
|
||||
_logger.info("{}:{}".format(type(e), e))
|
||||
message = False
|
||||
if isinstance(e, HeirChangeException):
|
||||
|
||||
Reference in New Issue
Block a user