feat(core): add support for tron vote witness#285
Conversation
WalkthroughThis pull request implements changes across message definitions, application logic, and user interface components. The Tron transaction messages now use explicit byte types and include new voting-related structures and fields. Function signatures in the Tron app modules have been updated with type annotations and renaming for clarity. Serialization now uses length-based encoding, and error handling is enhanced. Additionally, several new translation strings and UI elements have been added to support vote confirmation and passphrase management. Changes
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (24)
🚧 Files skipped from review as they are similar to previous changes (19)
🧰 Additional context used🧬 Code Graph Analysis (3)core/src/apps/tron/layout.py (2)
core/src/trezor/ui/layouts/lvgl/__init__.py (2)
python/src/trezorlib/messages.py (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🔇 Additional comments (10)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
core/src/trezor/lvglui/scrs/template.py (1)
4393-4400: Inconsistent i18n key namingUsing
GLOBAL__VOTE_COUNTwith double underscore butGLOBAL_CANDIDATEwith single underscore.- _(i18n_keys.GLOBAL__VOTE_COUNT), + _(i18n_keys.GLOBAL_VOTE_COUNT),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (23)
common/protob/messages-tron.proto(4 hunks)core/src/apps/tron/address.py(1 hunks)core/src/apps/tron/layout.py(1 hunks)core/src/apps/tron/serialize.py(8 hunks)core/src/apps/tron/sign_tx.py(3 hunks)core/src/trezor/enums/TronResourceCode.py(1 hunks)core/src/trezor/enums/__init__.py(1 hunks)core/src/trezor/lvglui/i18n/keys.py(1 hunks)core/src/trezor/lvglui/i18n/locales/de.py(1 hunks)core/src/trezor/lvglui/i18n/locales/en.py(1 hunks)core/src/trezor/lvglui/i18n/locales/es.py(1 hunks)core/src/trezor/lvglui/i18n/locales/fr.py(1 hunks)core/src/trezor/lvglui/i18n/locales/it.py(1 hunks)core/src/trezor/lvglui/i18n/locales/ja.py(1 hunks)core/src/trezor/lvglui/i18n/locales/ko.py(1 hunks)core/src/trezor/lvglui/i18n/locales/pt_br.py(1 hunks)core/src/trezor/lvglui/i18n/locales/ru.py(1 hunks)core/src/trezor/lvglui/i18n/locales/zh_cn.py(1 hunks)core/src/trezor/lvglui/i18n/locales/zh_hk.py(1 hunks)core/src/trezor/lvglui/scrs/template.py(1 hunks)core/src/trezor/messages.py(6 hunks)core/src/trezor/ui/layouts/lvgl/__init__.py(1 hunks)python/src/trezorlib/messages.py(8 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
core/src/apps/tron/address.py (2)
core/src/apps/ton/tonsdk/contract/__init__.py (1)
address(15-19)crypto/sha3.c (1)
sha3_256(399-405)
core/src/trezor/ui/layouts/lvgl/__init__.py (4)
core/src/trezor/wire/__init__.py (1)
GenericContext(71-87)core/src/trezor/lvglui/scrs/template.py (2)
TonVoteWitness(4356-4408)AlgoCommon(2758-2777)core/src/trezor/ui/layouts/lvgl/common.py (2)
raise_if_cancelled(32-37)interact(40-47)python/src/trezorlib/messages.py (1)
ButtonRequestType(472-492)
core/src/apps/tron/layout.py (2)
core/src/trezor/wire/__init__.py (1)
Context(236-386)core/src/trezor/ui/layouts/lvgl/__init__.py (1)
confirm_tron_vote(2325-2342)
core/src/apps/tron/sign_tx.py (1)
core/src/apps/tron/address.py (2)
address_base58(10-11)get_address_from_public_key(5-7)
python/src/trezorlib/messages.py (1)
core/src/trezor/messages.py (2)
TronVoteWitnessContract(9481-9495)Vote(9497-9511)
core/src/trezor/messages.py (1)
python/src/trezorlib/messages.py (2)
TronVoteWitnessContract(11719-11733)Vote(11736-11750)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Style check
- GitHub Check: Defs check
- GitHub Check: Gen check
🔇 Additional comments (40)
core/src/trezor/enums/TronResourceCode.py (1)
7-7: Looks good.python/src/trezorlib/messages.py (5)
832-832: New Tron resource code addedAdded TRON_POWER as value 2 in TronResourceCode enum.
11405-11405: Data field type changed from string to bytesChanged the
datafield type in TronSignTx from string to bytes.
11492-11492: Added vote witness contract fieldAdded vote_witness_contract field to TronContract class.
11502-11504: Added new fields to TronContractAdded provider, contract_name, and permission_id fields.
11719-11751: Added new classes for Tron votingAdded TronVoteWitnessContract and Vote classes to support witness voting functionality.
core/src/trezor/enums/__init__.py (1)
767-767: New enum value looks goodcore/src/trezor/lvglui/i18n/locales/en.py (1)
889-894: Added translations for vote witness functionalityThese new translation strings support passphrase management and voting functionality.
core/src/trezor/lvglui/i18n/locales/ko.py (1)
889-894: Korean translations added correctlycore/src/trezor/lvglui/i18n/locales/zh_hk.py (1)
889-894: Traditional Chinese translations look goodcore/src/trezor/lvglui/i18n/locales/zh_cn.py (1)
889-894: LGTM!These translations are correctly added for the Tron vote witness feature.
core/src/trezor/lvglui/i18n/locales/pt_br.py (1)
889-894: LGTM!Translations match required terms for Tron vote witness functionality.
core/src/apps/tron/serialize.py (4)
10-10: Correct type constant name changeThe change from TYPE_STRING to TYPE_LEN better reflects the purpose of the constant for length-prefixed fields.
65-82: LGTM! Vote witness contract implementationWell-structured implementation for the Tron vote witness contract.
217-218: Good error handling improvementAdding explicit error handling for invalid contract types.
233-242: Additional field handling works correctlyContract provider, name and permission ID fields are properly handled.
core/src/trezor/lvglui/i18n/locales/es.py (1)
889-894: LGTM!Spanish translations correctly added for the vote witness feature.
core/src/trezor/lvglui/i18n/locales/fr.py (1)
889-894: LGTM: New translations added correctly.These new French translations align with the Tron voting feature implementation described in the PR title.
core/src/trezor/lvglui/i18n/locales/ja.py (1)
889-894: LGTM: Japanese translations properly implemented.The new strings support passphrase management and voting functionality.
core/src/trezor/lvglui/i18n/locales/it.py (1)
889-894: LGTM: Italian translations added correctly.Proper translations for passphrase management and vote counting features.
core/src/trezor/lvglui/i18n/locales/de.py (1)
889-894: New German translations added successfully.These translations support the Tron vote witness functionality mentioned in the PR objectives.
core/src/trezor/lvglui/i18n/locales/ru.py (1)
889-894: Russian translations added correctly.The translations support Tron vote witness functionality mentioned in the PR objectives.
core/src/trezor/ui/layouts/lvgl/__init__.py (1)
2325-2342: Newconfirm_tron_votefunction implements proper UI flow.The function correctly handles vote confirmation through two screens and follows the established pattern for user interaction.
core/src/apps/tron/address.py (3)
5-5: Function signature improved with type annotations.Return type now uses renamed public function.
Also applies to: 7-7
10-10: Private function renamed to public with type annotations.Function now properly exposed for external use.
14-14: Added type annotations to address_to_bytes function.Type hints improve code clarity.
core/src/apps/tron/layout.py (1)
238-253:Details
✅ Verification successful
Function looks good, but double-check vote data handling.
The implementation for confirming witness votes is clean and follows existing patterns. However, ensure the vote tuple format matches what the UI component expects.
🏁 Script executed:
#!/bin/bash # Check if the format of votes matches what the UI component expects rg -A 5 "confirm_tron_vote\(" core/src/trezor/ui/layouts/lvgl/Length of output: 464
Verified: Vote tuple handling is correct.
The votes parameter meets the expected UI signature.core/src/trezor/lvglui/i18n/keys.py (1)
941-952: LGTM - Key constants added for vote witness support.The new string constants follow the established naming pattern.
core/src/apps/tron/sign_tx.py (3)
10-10: LGTM - Updated import to use public function.Changed from private to public function.
87-87: LGTM - Updated function call to match import.Consistent change with line 10.
182-189: LGTM - Implemented vote witness contract handling.The implementation follows the pattern of other contract types.
common/protob/messages-tron.proto (5)
38-38: Changed field type from string to bytes.More appropriate for binary data.
66-66: Added TRON_POWER resource code.Enhances resource types.
109-117: LGTM - Added TronVoteWitnessContract message.Well-structured with nested Vote message.
119-119: LGTM - Added vote_witness_contract field.Properly integrated with TronContract.
129-131: LGTM - Added provider, contract_name, and permission_id fields.Enhances contract message structure.
core/src/trezor/messages.py (4)
9206-9206: Changed data type from string to bytes.The data field type is now bytes instead of string, which matches the type used in the protocol.
Also applies to: 9220-9220
9279-9279: Added new fields for contract handling.Added vote witness contract support and provider/contract name fields.
Also applies to: 9289-9291
9297-9297: Updated constructor params to match new fields.Constructor parameters now include vote_witness_contract, provider, contract_name and permission_id.
Also applies to: 9307-9309
9481-9512: Added new classes for vote witness support.The TronVoteWitnessContract and Vote classes enable witness voting functionality.
269d146 to
b987480
Compare
b987480 to
c8b00a4
Compare
Summary by CodeRabbit
New Features
Refactor