From d9be8cb2f149079d1349b2d990ab33f4315254f8 Mon Sep 17 00:00:00 2001 From: scgbckbone Date: Mon, 14 Apr 2025 20:30:21 +0200 Subject: [PATCH] locktime ux fix (less spacing) --- shared/auth.py | 9 +++------ shared/psbt.py | 8 ++++---- testing/test_sign.py | 14 +++++++++----- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/shared/auth.py b/shared/auth.py index 235702ee..3e5f7667 100644 --- a/shared/auth.py +++ b/shared/auth.py @@ -426,7 +426,6 @@ class ApproveTransaction(UserAuthorizedAction): for label, m in self.psbt.ux_notes: msg.write('- %s: %s\n' % (label, m)) - msg.write("\n") if self.psbt.warnings: msg.write('---WARNING---\n\n') @@ -446,7 +445,7 @@ class ApproveTransaction(UserAuthorizedAction): if not hsm_active: esc = "" - msg.write("\nPress %s to approve and sign transaction." % OK) + msg.write("Press %s to approve and sign transaction." % OK) if needs_txn_explorer: esc += "2" msg.write(" Press (2) to explore txn.") @@ -686,7 +685,7 @@ class ApproveTransaction(UserAuthorizedAction): visible_change_sum = 0 if len(largest_change) == 1: visible_change_sum += largest_change[0][0] - msg.write(' - to address -\n%s\n' % show_single_address(largest_change[0][1])) + msg.write(' - to address -\n%s\n\n' % show_single_address(largest_change[0][1])) else: msg.write(' - to addresses -\n') for val, addr in largest_change: @@ -698,9 +697,7 @@ class ApproveTransaction(UserAuthorizedAction): if left_c: needs_txn_explorer = True msg.write('.. plus %d smaller change output(s), not shown here, which total: ' % left_c) - msg.write('%s %s\n' % self.chain.render_value(total_change - visible_change_sum)) - - msg.write("\n") + msg.write('%s %s\n\n' % self.chain.render_value(total_change - visible_change_sum)) # if we didn't already show all outputs, then give user a chance to # view them individually diff --git a/shared/psbt.py b/shared/psbt.py index 8d51c8d4..cfd35647 100644 --- a/shared/psbt.py +++ b/shared/psbt.py @@ -1313,11 +1313,11 @@ class psbtObject(psbtProxy): # Block height relative lock-time if num_bb == 1: idx, val = bb[0] - msg = "Input %d. has relative block height timelock of %d blocks" % ( + msg = "Input %d. has relative block height timelock of %d blocks\n" % ( idx, val ) elif all(bb[0][1] == i[1] for i in bb): - msg = "%d inputs have relative block height timelock of %d blocks" % ( + msg = "%d inputs have relative block height timelock of %d blocks\n" % ( num_bb, bb[0][1] ) else: @@ -1335,11 +1335,11 @@ class psbtObject(psbtProxy): if num_tb == 1: idx, val = tb[0] val = seconds2human_readable(val) - msg = "Input %d. has relative time-based timelock of:\n %s" % ( + msg = "Input %d. has relative time-based timelock of:\n %s\n" % ( idx, val ) elif all(tb[0][1] == i[1] for i in tb): - msg = "%d inputs have relative time-based timelock of:\n %s" % ( + msg = "%d inputs have relative time-based timelock of:\n %s\n" % ( num_tb, seconds2human_readable(tb[0][1]) ) else: diff --git a/testing/test_sign.py b/testing/test_sign.py index 7d429097..6efd9675 100644 --- a/testing/test_sign.py +++ b/testing/test_sign.py @@ -2553,7 +2553,7 @@ def test_nsequence_blockheight_relative_locktime_ux(sequence, use_regtest, bitco @pytest.mark.bitcoind @pytest.mark.parametrize("num_ins", [1, 4, 11]) @pytest.mark.parametrize("differ", [True, False]) -@pytest.mark.parametrize("seconds", [512, 10000, 1000000, 33554431]) +@pytest.mark.parametrize("seconds", [512, 10240, 1024000, 33554431]) def test_nsequence_timebased_relative_locktime_ux(seconds, use_regtest, bitcoind_d_sim_watch, start_sign, microsd_path, cap_story, goto_home, press_select, pick_menu_item, bitcoind, end_sign, num_ins, differ, @@ -2575,18 +2575,22 @@ def test_nsequence_timebased_relative_locktime_ux(seconds, use_regtest, bitcoind ins = [] num_ins_locked = 0 + locked_indexes = [] for i, utxo in enumerate(utxos): # time-based RTL - if i and differ: - nSeq = sequence - (sequence * i) + if i and differ and (seconds > 512): + secs = seconds // i + nSeq = SEQUENCE_LOCKTIME_TYPE_FLAG | (secs >> 9) if nSeq < 0: nSeq = 0 else: + secs = seconds nSeq = sequence if nSeq > 0: num_ins_locked += 1 + locked_indexes.append((i, secs)) inp = { "txid": utxo["txid"], @@ -2618,9 +2622,9 @@ def test_nsequence_timebased_relative_locktime_ux(seconds, use_regtest, bitcoind if num_ins_locked == 1: assert ("has " + base_msg) in story else: - if differ: + if differ and (seconds > 512): assert ("%d inputs have relative time-based timelock." % num_ins_locked) in story - for i in range(num_ins_locked): + for i, _ in sorted(locked_indexes, key=lambda i: i[1], reverse=True)[:10]: assert ("%d. " % i) in story else: msg1 = "%d inputs have " % num_ins_locked