mirror of
https://github.com/SeedSigner/seedsigner.git
synced 2026-10-05 15:08:25 +00:00
Minor cleanup
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)])
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 == [
|
||||
|
||||
Reference in New Issue
Block a user