Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emulator.get_debug_state response #271

Merged
merged 1 commit into from
Oct 14, 2024
Merged

Conversation

szymonlesisz
Copy link
Contributor

@szymonlesisz szymonlesisz commented Oct 9, 2024

fixing problem 1:
get_debug_state tries to serialize non buffer fields/keys (1 indent missing)
edit: after further testing this change can be tricky.
DebugLinkState may contain some other filed types not only bytes (like int for example) but in the same time they might be complex and not serializable.
see thp state:

<DebugLinkState: {'mnemonic_secret': b'all all all all all all all all all all all all', 'passphrase_protection': False, 'reset_entropy': b'', 'mnemonic_type': <BackupType.Bip39: 0>, 'tokens': ['{', '"component"', ': ', '"SimplePage"', ', ', '"active_page"', ': ', '0', ', ', '"page_count"', ': ', '2', ', ', '"content"', ': ', '{', '"component"', ': ', '"AddressDetails"', ', ', '"qr_code"', ': ', '{', '"component"', ': ', '"Frame"', ', ', '"title"', ': ', '{', '"component"', ': ', '"Label"', ', ', '"text"', ': ', '"Scan QR code to pair"', '}', ', ', '"content"', ': ', '{', '"component"', ': ', '"Qr"', ', ', '"text"', ': ', '""', '}', ', ', '"button"', ': ', '{', '"component"', ': ', '"Button"', ', ', '"icon"', ': ', 'true', '}', '}', '}', '}'], 'thp_pairing_code_entry_code': 417041}>

fixing problem 2:
UI client assumes that dataObject.response is a string but in case of debug state it is an object

example: send JSON to server

{"type": "emulator-get-debug-state"}

src/emulator.py Outdated
@@ -917,8 +917,7 @@ def get_debug_state() -> Dict[str, Any]:
val = val.decode("utf-8")
except UnicodeDecodeError:
val = val.hex()

debug_state_dict[key] = val
debug_state_dict[key] = val
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem right, it means we will only save byte values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, as i mentioned in the description and also discussed on slack, im aware that this isnt right but user-env crasches without it (tries to serialize complex field)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fixup commit into this branch/PR, can you please confirm it works fine for you? I can merge it in a positive case

Copy link
Contributor Author

@szymonlesisz szymonlesisz Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me, thanks

Copy link
Contributor

@grdddj grdddj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge

@grdddj grdddj merged commit 766f7d2 into master Oct 14, 2024
1 check passed
@grdddj grdddj deleted the fix/get_debug_state branch October 14, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants