Skip to content

feat(core): add support for tron vote witness#285

Merged
somebodyLi merged 1 commit intomainfrom
feature/tron_vote
Apr 10, 2025
Merged

feat(core): add support for tron vote witness#285
somebodyLi merged 1 commit intomainfrom
feature/tron_vote

Conversation

@somebodyLi
Copy link
Copy Markdown
Contributor

@somebodyLi somebodyLi commented Apr 10, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced Tron transaction support with improved data encoding and witness voting.
    • Introduced new confirmation screens for voting actions.
    • Expanded available resource types by adding "TRON POWER".
    • Upgraded localization with new multilingual translations for passphrase management and vote count notifications.
  • Refactor

    • Improved address conversion and transaction data handling for better reliability and error management.

@somebodyLi somebodyLi requested a review from a team as a code owner April 10, 2025 10:28
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2025

Walkthrough

This 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

Files Change Summary
common/protob/messages-tron.proto, core/src/trezor/messages.py, python/src/trezorlib/messages.py, core/src/trezor/enums/TronResourceCode.py, core/src/trezor/enums/__init__.py Updated TronSignTx: changed data from string to bytes; added TronVoteWitnessContract and Vote messages; extended TronContract with voting fields; introduced new enum member TRON_POWER.
core/src/apps/tron/address.py, core/src/apps/tron/layout.py, core/src/apps/tron/serialize.py, core/src/apps/tron/sign_tx.py Added explicit type annotations; renamed _address_base58 to address_base58; introduced require_confirm_vote_witness and vote contract handling; updated serialization to use TYPE_LEN with improved error handling.
core/src/trezor/lvglui/i18n/keys.py, core/src/trezor/lvglui/i18n/locales/{de,en,es,fr,it,ja,ko,pt_br,ru,zh_cn,zh_hk}.py Added new constants and translation strings for handling invalid phrases, passphrase warnings, edit options, and vote count labels.
core/src/trezor/lvglui/scrs/template.py, core/src/trezor/ui/layouts/lvgl/__init__.py Introduced new UI class TronVoteWitness for Tron vote display and an async function confirm_tron_vote for vote confirmation.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between b987480 and c8b00a4.

📒 Files selected for processing (24)
  • common/protob/check.py (1 hunks)
  • 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)
🚧 Files skipped from review as they are similar to previous changes (19)
  • core/src/trezor/enums/TronResourceCode.py
  • core/src/trezor/lvglui/i18n/locales/en.py
  • core/src/trezor/enums/init.py
  • core/src/trezor/lvglui/i18n/locales/pt_br.py
  • core/src/trezor/lvglui/i18n/locales/zh_hk.py
  • core/src/apps/tron/address.py
  • common/protob/check.py
  • core/src/trezor/lvglui/i18n/locales/de.py
  • core/src/trezor/lvglui/i18n/locales/it.py
  • core/src/trezor/lvglui/i18n/locales/ru.py
  • core/src/trezor/lvglui/i18n/locales/fr.py
  • core/src/trezor/lvglui/i18n/locales/zh_cn.py
  • common/protob/messages-tron.proto
  • core/src/apps/tron/serialize.py
  • core/src/trezor/lvglui/i18n/locales/ja.py
  • core/src/trezor/lvglui/i18n/locales/ko.py
  • core/src/trezor/lvglui/i18n/locales/es.py
  • core/src/apps/tron/sign_tx.py
  • core/src/trezor/messages.py
🧰 Additional context used
🧬 Code Graph Analysis (3)
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/trezor/ui/layouts/lvgl/__init__.py (2)
core/src/trezor/lvglui/scrs/template.py (2)
  • TronVoteWitness (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)
core/src/trezor/messages.py (2)
  • TronVoteWitnessContract (9481-9495)
  • Vote (9497-9511)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Style check
  • GitHub Check: Gen check
  • GitHub Check: Defs check
🔇 Additional comments (10)
core/src/trezor/lvglui/i18n/keys.py (1)

1941-1952: LGTM: New translation keys are properly added.

The six new translation keys follow the existing naming convention and are correctly numbered sequentially. These keys support the new Tron vote witness functionality mentioned in the PR objectives.

python/src/trezorlib/messages.py (6)

832-832: Add enum value TRON_POWER.

Adds new TronResourceCode enum value for handling Tron power votes.


11409-11409: Changed data field from string to bytes.

Data field type now matches protobuf definition.


11492-11492: Added vote witness contract field.

Adds support for Tron witness voting.


11502-11504: Added provider, contract_name, and permission_id fields.

New fields support extended Tron transaction capabilities.


11719-11734: Added TronVoteWitnessContract class.

New class to handle vote witness operations.


11736-11751: Added Vote class.

Class to store vote address and count information.

core/src/trezor/lvglui/scrs/template.py (1)

4356-4409: LGTM! Code looks good.

The implementation of TronVoteWitness is well-structured and follows consistent patterns from other UI components.

core/src/trezor/ui/layouts/lvgl/__init__.py (1)

2325-2343: New Tron vote confirmation function looks good.

The implementation correctly handles user interaction for confirming Tron votes with proper UI flow and cancellation handling.

core/src/apps/tron/layout.py (1)

238-254: Nice wrapper for vote confirmation.

Function cleanly handles both voting and vote removal cases based on the support parameter.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
core/src/trezor/lvglui/scrs/template.py (1)

4393-4400: Inconsistent i18n key naming

Using GLOBAL__VOTE_COUNT with double underscore but GLOBAL_CANDIDATE with single underscore.

-                _(i18n_keys.GLOBAL__VOTE_COUNT),
+                _(i18n_keys.GLOBAL_VOTE_COUNT),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 839118e and d3688f9.

📒 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 added

Added TRON_POWER as value 2 in TronResourceCode enum.


11405-11405: Data field type changed from string to bytes

Changed the data field type in TronSignTx from string to bytes.


11492-11492: Added vote witness contract field

Added vote_witness_contract field to TronContract class.


11502-11504: Added new fields to TronContract

Added provider, contract_name, and permission_id fields.


11719-11751: Added new classes for Tron voting

Added TronVoteWitnessContract and Vote classes to support witness voting functionality.

core/src/trezor/enums/__init__.py (1)

767-767: New enum value looks good

core/src/trezor/lvglui/i18n/locales/en.py (1)

889-894: Added translations for vote witness functionality

These new translation strings support passphrase management and voting functionality.

core/src/trezor/lvglui/i18n/locales/ko.py (1)

889-894: Korean translations added correctly

core/src/trezor/lvglui/i18n/locales/zh_hk.py (1)

889-894: Traditional Chinese translations look good

core/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 change

The change from TYPE_STRING to TYPE_LEN better reflects the purpose of the constant for length-prefixed fields.


65-82: LGTM! Vote witness contract implementation

Well-structured implementation for the Tron vote witness contract.


217-218: Good error handling improvement

Adding explicit error handling for invalid contract types.


233-242: Additional field handling works correctly

Contract 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: New confirm_tron_vote function 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.

@somebodyLi somebodyLi force-pushed the feature/tron_vote branch 2 times, most recently from 269d146 to b987480 Compare April 10, 2025 10:44
@somebodyLi somebodyLi enabled auto-merge (squash) April 10, 2025 11:18
@somebodyLi somebodyLi merged commit 29edc69 into main Apr 10, 2025
7 checks passed
@somebodyLi somebodyLi deleted the feature/tron_vote branch April 10, 2025 11:25
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.

3 participants