diff --git a/src/seedsigner/gui/screens/psbt_screens.py b/src/seedsigner/gui/screens/psbt_screens.py index 369e93af..502c3921 100644 --- a/src/seedsigner/gui/screens/psbt_screens.py +++ b/src/seedsigner/gui/screens/psbt_screens.py @@ -688,7 +688,7 @@ class PSBTChangeDetailsScreen(ButtonListScreen): @dataclass class PSBTOpReturnScreen(ButtonListScreen): - op_return: str = None + op_return_data: bytes = None def __post_init__(self): # Customize defaults @@ -699,7 +699,7 @@ class PSBTOpReturnScreen(ButtonListScreen): try: # Simple case: display human-readable text self.components.append(TextArea( - text=self.op_return.decode(errors="strict"), + text=self.op_return_data.decode(errors="strict"), # "strict" is a good enough heuristic to decide if it's human readable font_size=GUIConstants.TOP_NAV_TITLE_FONT_SIZE, is_text_centered=True, allow_text_overflow=True, @@ -713,7 +713,7 @@ class PSBTOpReturnScreen(ButtonListScreen): font = Fonts.get_font(GUIConstants.FIXED_WIDTH_FONT_NAME, size=GUIConstants.BODY_FONT_SIZE) (left, top, right, bottom) = font.getbbox("X", anchor="ls") chars_per_line = int((self.canvas_width - 2*GUIConstants.EDGE_PADDING) / (right - left)) - decoded_str = self.op_return.hex() + decoded_str = self.op_return_data.hex() num_lines = math.ceil(len(decoded_str) / chars_per_line) text = "" for i in range(num_lines): diff --git a/src/seedsigner/gui/screens/seed_screens.py b/src/seedsigner/gui/screens/seed_screens.py index 9fe35c1c..89e42daa 100644 --- a/src/seedsigner/gui/screens/seed_screens.py +++ b/src/seedsigner/gui/screens/seed_screens.py @@ -1511,6 +1511,8 @@ class SeedSignMessageConfirmMessageScreen(ButtonListScreen): end_y = renderer.canvas_height - GUIConstants.EDGE_PADDING - GUIConstants.BUTTON_HEIGHT - GUIConstants.COMPONENT_PADDING message_height = end_y - start_y + # TODO: Pass the full message in from the View so that this Screen doesn't need to + # interact with the Controller here. self.sign_message_data = Controller.get_instance().sign_message_data if "paged_message" not in self.sign_message_data: paged = reflow_text_into_pages( diff --git a/src/seedsigner/models/psbt_parser.py b/src/seedsigner/models/psbt_parser.py index 2846e6b5..8faba3fe 100644 --- a/src/seedsigner/models/psbt_parser.py +++ b/src/seedsigner/models/psbt_parser.py @@ -31,7 +31,7 @@ class PSBTParser(): self.num_inputs = 0 self.destination_addresses = [] self.destination_amounts = [] - self.op_return = None + self.op_return_data: bytes = None self.root = None @@ -177,7 +177,7 @@ class PSBTParser(): if self.psbt.tx.vout[i].script_pubkey.data[0] == OPCODES.OP_RETURN: # The data is written as: OP_RETURN + OP_PUSHDATA1 + len(payload) + payload - self.op_return = self.psbt.tx.vout[i].script_pubkey.data[3:] + self.op_return_data = self.psbt.tx.vout[i].script_pubkey.data[3:] elif is_change: addr = self.psbt.tx.vout[i].script_pubkey.address(NETWORKS[SettingsConstants.map_network_to_embit(self.network)]) diff --git a/src/seedsigner/views/psbt_views.py b/src/seedsigner/views/psbt_views.py index e8ac194e..acacfd8c 100644 --- a/src/seedsigner/views/psbt_views.py +++ b/src/seedsigner/views/psbt_views.py @@ -138,7 +138,7 @@ class PSBTOverviewView(View): num_self_transfer_outputs=num_self_transfer_outputs, num_change_outputs=num_change_outputs, destination_addresses=psbt_parser.destination_addresses, - has_op_return=psbt_parser.op_return is not None, + has_op_return=psbt_parser.op_return_data is not None, ) if selected_menu_num == RET_CODE__BACK_BUTTON: @@ -277,7 +277,7 @@ class PSBTAddressDetailsView(View): # Move on to display change return Destination(PSBTChangeDetailsView, view_args={"change_address_num": 0}) - elif psbt_parser.op_return: + elif psbt_parser.op_return_data: return Destination(PSBTOpReturnView) else: @@ -421,7 +421,7 @@ class PSBTChangeDetailsView(View): if self.change_address_num < psbt_parser.num_change_outputs - 1: return Destination(PSBTChangeDetailsView, view_args={"change_address_num": self.change_address_num + 1}) - elif psbt_parser.op_return: + elif psbt_parser.op_return_data: return Destination(PSBTOpReturnView) else: @@ -481,7 +481,7 @@ class PSBTOpReturnView(View): PSBTOpReturnScreen, title=title, button_data=button_data, - op_return=psbt_parser.op_return, + op_return_data=psbt_parser.op_return_data, ) if selected_menu_num == RET_CODE__BACK_BUTTON: diff --git a/tests/test_psbt_parser.py b/tests/test_psbt_parser.py index 801a52d4..99b20c23 100644 --- a/tests/test_psbt_parser.py +++ b/tests/test_psbt_parser.py @@ -140,7 +140,7 @@ def test_parse_op_return_content(): psbt_parser = PSBTParser(p=tx, seed=seed, network=SettingsConstants.REGTEST) # Remember to do the comparison as bytes - assert psbt_parser.op_return == "Chancellor on the brink of third bailout".encode() + assert psbt_parser.op_return_data == "Chancellor on the brink of third bailout".encode() # PSBT is an internal self-spend to the its own receive addr, but the parser categorizes it as "change" assert psbt_parser.change_data == [