Skip to content

feat(core): adaptation related to Polkadot updates#615

Merged
somebodyLi merged 3 commits intotouchfrom
4.12.0
Nov 26, 2025
Merged

feat(core): adaptation related to Polkadot updates#615
somebodyLi merged 3 commits intotouchfrom
4.12.0

Conversation

@somebodyLi
Copy link
Copy Markdown
Contributor

@somebodyLi somebodyLi commented Nov 26, 2025

Summary by CodeRabbit

  • New Features

    • Added Hydration and Bifrost Polkadot networks with branding and address-type support
    • Tron: witness voting UI, new cancel-all-unfreeze flow, and energy-rental provider identification banner
    • Tron message versioning (V2) for alternate signing behavior
  • Bug Fixes

    • Improved Polkadot SS58 address-type handling
  • Chores

    • Bumped firmware to 4.12.0
    • Added translations for the energy-provider warning
    • Removed onboarding app guide from startup flow

✏️ Tip: You can customize this high-level summary in your review settings.

@somebodyLi somebodyLi requested a review from a team as a code owner November 26, 2025 09:05
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 26, 2025

Walkthrough

Adds Polkadot SS58 prefix support, expands Polkadot networks, introduces multiple Tron contract/message types and protobuf/serialization changes, adds provider lookup and UI banners for energy rental, bumps firmware to 4.12.0, and adds locale strings and enum/constants for Tron.

Changes

Cohort / File(s) Summary
Protocol Buffer Definitions
common/protob/messages-polkadot.proto, common/protob/messages-tron.proto
Added prefix (uint32) to PolkadotSignTx. Extended Tron proto: TronVoteWitnessContract, TronCancelAllUnfreezeV2Contract, TronMessageType enum, TRON_POWER, lock_period, new contract fields (provider, contract_name, permission_id), and changed TronSignTx.data from string to bytes.
Firmware Version
core/embed/firmware/version.h
Bumped ONEKEY_VERSION_MINOR 11→12 and ONEKEY_VERSION "4.11.0"→"4.12.0".
Polkadot app — config & deserialization
core/src/apps/polkadot/__init__.py, core/src/apps/polkadot/helper.py, core/src/apps/polkadot/sign_tx.py, core/src/apps/polkadot/transaction.py
Added networks (hydration, bifrost, bifrost-ksm) with colors/icons; extended get_address_type() to accept optional preset_prefix; pass msg.prefix into address-type resolution; updated deserializers with skip_type_lookup, deserialize_manta(..., address_type), and new deserialize_hydration.
Tron — UI, signing, and flow
core/src/apps/tron/layout.py, core/src/apps/tron/sign_message.py, core/src/apps/tron/sign_tx.py
Added confirm helpers (require_confirm_cancel_all_unfreeze_v2, require_confirm_vote_witness), forwarded banner_text in confirmations, added TronMessageType handling (V2 uses raw message), renamed message_digestmake_message_digest, moved data confirmation ordering, and integrated provider-based banner logic.
Tron — serialization & providers
core/src/apps/tron/serialize.py, core/src/apps/tron/providers.py
Replaced add_field with write_field/write_varint/write_bytes_with_length, introduced TYPE_LEN, added error on unsupported contract types, and added providers.py with ProviderInfo and provider_by_address() (yields known provider entry).
Enums & constants
core/src/trezor/enums/TronMessageType.py, core/src/trezor/enums/TronResourceCode.py, core/src/trezor/enums/__init__.py
Added TronMessageType (V1,V2) and TRON_POWER = 2 constant/enum member.
Message model updates
core/src/trezor/messages.py, python/src/trezorlib/messages.py
Added prefix to PolkadotSignTx, changed TronSignTx.data to bytes, added message_type to TronSignMessage, added vote_witness_contract, cancel_all_unfreeze_v2_contract, provider/contract_name/permission_id fields to TronContract, added TronCancelAllUnfreezeV2Contract, TronVoteWitnessContract, and Vote types, and added lock_period to TronDelegateResourceContract.
Module tracking & exports
core/src/all_modules.py, core/src/trezor/ui/layouts/lvgl/__init__.py
Exposed trezor.enums.TronMessageType, apps.tron.providers, and exported new Tron confirm helpers (confirm_tron_vote, confirm_tron_unfreeze, etc.). confirm_output now accepts banner_text.
App guide & homescreen changes
core/src/apps/base.py, core/src/apps/management/recovery_device/homescreen.py, core/src/apps/management/reset_device/__init__.py, core/src/session.py, core/src/trezor/utils.py
Removed BLE status check in set_homescreen. Disabled or simplified app-guide invocation paths and commented-out show_app_guide / make_show_app_guide definitions. Recovery/reset flows simplified to always use app guide.
UI templates
core/src/trezor/lvglui/scrs/template.py
TransactionOverview.__init__ accepts banner_text and shows a warning banner if present. Added TronVoteWitness UI component (duplicated definition present—likely merge artifact).
Internationalization
core/src/trezor/lvglui/i18n/keys.py, core/src/trezor/lvglui/i18n/locales/{en,de,es,fr,it,ja,ko,pt_br,ru,zh_cn,zh_hk}.py
Added BANNER_ENERGY_RENTAL = 950 key and inserted energy-rental warning translation into all listed locales.
Tools & checks
tools/i18n.py, common/protob/check.py
tools/i18n.py: added replace_breaks: 1 to Localisé API request. common/protob/check.py: added "Tron" to skipped prefixes when scanning protos.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SignTx as Tron.sign_tx
    participant Provider as providers.provider_by_address()
    participant Layout as layout.confirmers
    participant Serialize as serialize.pack_contract

    User->>SignTx: submit transaction (transfer_contract)
    SignTx->>Provider: provider_by_address(recipient)
    alt provider found
        Provider-->>SignTx: ProviderInfo
        SignTx->>Layout: require_confirm_tx(..., banner_text)
        Note right of Layout: Show energy rental banner
    else not found
        SignTx->>Layout: require_confirm_tx(..., banner_text=None)
    end
    SignTx->>Layout: require_confirm_tx (other confirmations)
    SignTx->>Serialize: pack_contract(...)
    Serialize-->>SignTx: encoded bytes
    SignTx->>SignTx: confirm_final(TRON)
Loading
sequenceDiagram
    participant Caller
    participant PSign as Polkadot.sign_tx
    participant Helper as helper.get_address_type
    participant Tx as transaction.deserialize

    Caller->>PSign: send PolkadotSignTx (may include prefix)
    PSign->>Helper: get_address_type(network, preset_prefix=msg.prefix)
    alt prefix provided
        Helper-->>PSign: return preset prefix
    else no prefix
        Helper-->>PSign: return default (42 or network match)
    end
    PSign->>Tx: deserialize(raw_tx, network)
    Tx->>Tx: dispatch to specific deserializer (hydration/manta/bifrost)
    Note right of Tx: deserialize uses address_type and skip_type_lookup where applicable
    Tx-->>PSign: parsed transaction
Loading
sequenceDiagram
    participant SignMsg as Tron.sign_message
    participant TType as TronMessageType

    SignMsg->>SignMsg: receive message + message_type
    alt message_type == V2
        Note right of SignMsg: Use raw message for signing
        SignMsg->>SignMsg: signing_message = raw message
    else V1
        Note right of SignMsg: Hash with TRON header
        SignMsg->>SignMsg: signing_message = make_message_digest(hashed payload)
    end
    SignMsg->>SignMsg: compute signature over signing_message
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Points to focus on:

  • Tron serialization refactor (core/src/apps/tron/serialize.py) — verify varint/tag encoding and compatibility with existing consumers.
  • Polkadot transaction parsing (core/src/apps/polkadot/transaction.py) — check skip_type_lookup logic, address_type threading, and new deserializers (hydration/manta variants).
  • Provider lookup and banner propagation (core/src/apps/tron/providers.py, core/src/apps/tron/sign_tx.py, UI plumbing) — ensure correct detection and i18n key usage.
  • UI changes and duplicated TronVoteWitness in template.py — resolve duplicate class definitions.
  • App-guide removal/commenting (core/src/trezor/utils.py, session and management files) — confirm no unintended runtime side effects.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'feat(core): adaptation related to Polkadot updates' is partially related to the changeset but misleading. While Polkadot changes exist, the PR contains substantial Tron updates, version bumps, UI changes, and new features that represent equal or greater scope than Polkadot work. Revise the title to reflect the full scope. Consider: 'feat(core): Polkadot multi-chain support and Tron enhancements' or break into separate PRs by feature domain.
Docstring Coverage ⚠️ Warning Docstring coverage is 5.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 4.12.0

Comment @coderabbitai help to get the list of available commands and usage tips.

@revan-zhang
Copy link
Copy Markdown
Contributor

revan-zhang commented Nov 26, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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: 13

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
core/src/apps/tron/layout.py (1)

35-46: Tron confirmations look correct; consider small API and text tweaks

  • require_confirm_tx’s new banner_text param and its pass‑through to confirm_output are straightforward and keep old callers working.
  • The new helpers for unfreeze v2 and voting hook cleanly into confirm_tron_unfreeze and confirm_tron_vote; parameter ordering matches the layout functions.

Two minor improvements to consider:

  • Make the boolean flag keyword‑only to address the Ruff FBT001 warning and improve call‑site clarity:
-def require_confirm_vote_witness(
-    ctx: Context,
-    signer: str,
-    votes: list[tuple[str, int]],
-    support: bool | None,
-) -> Awaitable[None]:
+def require_confirm_vote_witness(
+    ctx: Context,
+    signer: str,
+    votes: list[tuple[str, int]],
+    *,
+    support: bool | None,
+) -> Awaitable[None]:

Then update callers to use support=....

  • For user‑facing copy, you may want to standardize capitalization: e.g. "Cancel All Unstaking" instead of "Cancel All UnStaking", and "Unfreeze Balance V2 Contract" instead of "UnFreeze Balance V2 Contract", to match normal English style.

Also applies to: 160-182, 239-263

core/src/apps/polkadot/transaction.py (1)

56-81: Fix tuple comparison in Polkadot/Kusama callPrivIdx checks

You compare callPrivIdx (an int) to tuples like (1282, 2562) and (1026, 2562). These conditions never match, so those extrinsics fall back to TransactionUnknown and show only blind‑sign UI.

Use membership tests instead:

@@ def deserialize_polkadot(rawtx: codec.base.ScaleBytes, callPrivIdx: int) -> "Transaction":
-        if callPrivIdx in (1287, 1280, 2560):
+        if callPrivIdx in (1287, 1280, 2560):
@@
-        elif callPrivIdx == (1282, 2562):
+        elif callPrivIdx in (1282, 2562):
@@
-        elif callPrivIdx == (1283, 2563):
+        elif callPrivIdx in (1283, 2563):
@@
-        elif callPrivIdx == (1284, 2564):
+        elif callPrivIdx in (1284, 2564):
@@ def deserialize_kusama(rawtx: codec.base.ScaleBytes, callPrivIdx: int) -> "Transaction":
-        if callPrivIdx in (1031, 1024, 2560):
+        if callPrivIdx in (1031, 1024, 2560):
@@
-        elif callPrivIdx == (1026, 2562):
+        elif callPrivIdx in (1026, 2562):
@@
-        elif callPrivIdx == (1027, 2563):
+        elif callPrivIdx in (1027, 2563):
@@
-        elif callPrivIdx == (1028, 2564):
+        elif callPrivIdx in (1028, 2564):

Also applies to: 84-108

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

9084-9104: PolkadotSignTx prefix field wiring looks correct; minor typing polish possible

The new optional prefix field is correctly exposed both in FIELDS and __init__, and keeps the message backward compatible on the wire.

You can clean up the type hint to satisfy Ruff’s UP037 without behavior change:

-        prefix: Optional["int"] = None,
+        prefix: Optional[int] = None,

[sorted as optional refactor; no need to change generator unless you want Ruff fully clean here.]


10727-10744: TronSignMessage message_type default is sane; small typing tweak

The new message_type field defaults to TronMessageType.V1, which keeps existing callers working while enabling V2.

You can drop the unnecessary quotes around the already‑defined enum in the type hint:

-        message_type: Optional["TronMessageType"] = TronMessageType.V1,
+        message_type: Optional[TronMessageType] = TronMessageType.V1,

Behavior stays the same.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 204425e and c8a8900.

⛔ Files ignored due to path filters (5)
  • core/src/trezor/lvglui/res/chain-bifrost-ksm.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-bifrost.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-dot.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-hydration.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-kusama.png is excluded by !**/*.png
📒 Files selected for processing (38)
  • common/protob/messages-polkadot.proto (1 hunks)
  • common/protob/messages-tron.proto (5 hunks)
  • core/embed/firmware/version.h (1 hunks)
  • core/src/all_modules.py (2 hunks)
  • core/src/apps/base.py (0 hunks)
  • core/src/apps/management/recovery_device/homescreen.py (1 hunks)
  • core/src/apps/management/reset_device/__init__.py (1 hunks)
  • core/src/apps/polkadot/__init__.py (1 hunks)
  • core/src/apps/polkadot/helper.py (5 hunks)
  • core/src/apps/polkadot/sign_tx.py (1 hunks)
  • core/src/apps/polkadot/transaction.py (6 hunks)
  • core/src/apps/tron/layout.py (3 hunks)
  • core/src/apps/tron/providers.py (1 hunks)
  • core/src/apps/tron/serialize.py (3 hunks)
  • core/src/apps/tron/sign_message.py (3 hunks)
  • core/src/apps/tron/sign_tx.py (3 hunks)
  • core/src/session.py (1 hunks)
  • core/src/trezor/enums/TronMessageType.py (1 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 (3 hunks)
  • core/src/trezor/messages.py (11 hunks)
  • core/src/trezor/ui/layouts/lvgl/__init__.py (4 hunks)
  • core/src/trezor/utils.py (2 hunks)
  • python/src/trezorlib/messages.py (13 hunks)
  • tools/i18n.py (1 hunks)
💤 Files with no reviewable changes (1)
  • core/src/apps/base.py
🧰 Additional context used
🧬 Code graph analysis (12)
core/src/apps/tron/layout.py (1)
core/src/trezor/ui/layouts/lvgl/__init__.py (2)
  • confirm_tron_unfreeze (2025-2050)
  • confirm_tron_vote (2083-2100)
core/src/apps/tron/sign_tx.py (2)
core/src/apps/tron/providers.py (1)
  • provider_by_address (16-20)
core/src/apps/tron/layout.py (4)
  • require_confirm_tx (31-46)
  • require_confirm_cancel_all_unfreeze_v2 (239-245)
  • require_confirm_vote_witness (248-263)
  • require_confirm_data (18-28)
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)
  • TronVoteWitness (2266-2301)
  • AlgoCommon (1398-1413)
core/src/trezor/ui/layouts/lvgl/common.py (2)
  • raise_if_cancelled (31-36)
  • interact (39-46)
core/src/trezor/enums/__init__.py (1)
  • ButtonRequestType (434-454)
core/src/apps/polkadot/sign_tx.py (1)
core/src/apps/polkadot/helper.py (1)
  • get_address_type (164-170)
core/src/all_modules.py (2)
core/src/trezor/enums/__init__.py (1)
  • TronMessageType (728-730)
python/src/trezorlib/messages.py (1)
  • TronMessageType (792-794)
core/src/apps/management/reset_device/__init__.py (1)
core/src/trezor/ui/layouts/lvgl/__init__.py (1)
  • show_onekey_app_guide (1338-1347)
core/src/apps/management/recovery_device/homescreen.py (1)
core/src/trezor/ui/layouts/lvgl/__init__.py (1)
  • show_onekey_app_guide (1338-1347)
core/src/trezor/messages.py (2)
core/src/trezor/enums/__init__.py (2)
  • TronMessageType (728-730)
  • MessageType (27-415)
python/src/trezorlib/messages.py (5)
  • TronMessageType (792-794)
  • TronCancelAllUnfreezeV2Contract (11000-11001)
  • MessageType (36-424)
  • TronVoteWitnessContract (11004-11018)
  • Vote (11021-11035)
core/src/apps/tron/sign_message.py (3)
core/src/trezor/enums/__init__.py (1)
  • TronMessageType (728-730)
python/src/trezorlib/messages.py (1)
  • TronMessageType (792-794)
core/src/trezor/utils.py (4)
  • extend (316-317)
  • extend (329-330)
  • extend (376-377)
  • get_digest (335-336)
core/src/apps/polkadot/transaction.py (2)
core/src/apps/polkadot/codec/base.py (6)
  • ScaleBytes (5-64)
  • value (108-112)
  • value (115-116)
  • get_next_bytes (22-25)
  • get_next_bytes (145-147)
  • decode (165-192)
core/src/apps/polkadot/codec/types.py (1)
  • Compact (4-42)
core/src/trezor/enums/__init__.py (1)
python/src/trezorlib/messages.py (2)
  • TronMessageType (792-794)
  • TronResourceCode (797-800)
core/src/trezor/lvglui/scrs/template.py (4)
core/src/trezor/lvglui/scrs/components/banner.py (1)
  • Banner (12-40)
core/src/trezor/lvglui/scrs/components/container.py (1)
  • ContainerFlexCol (8-38)
core/src/trezor/lvglui/scrs/common.py (1)
  • FullSizeWindow (157-389)
core/src/trezor/lvglui/scrs/components/listitem.py (1)
  • DisplayItemNoBgc (144-150)
🪛 Buf (1.60.0)
common/protob/messages-tron.proto

114-114: Field named "vote_address" should not be required.

(FIELD_NOT_REQUIRED)


115-115: Field named "vote_count" should not be required.

(FIELD_NOT_REQUIRED)


148-148: First enum value "V1" should have a numeric value of 0

(ENUM_FIRST_VALUE_ZERO)


159-159: Field named "message" should not be required.

(FIELD_NOT_REQUIRED)

🪛 Ruff (0.14.5)
core/src/apps/tron/layout.py

252-252: Boolean-typed positional argument in function definition

(FBT001)

core/src/apps/tron/providers.py

1-1: Import from collections.abc instead: Iterator

Import from collections.abc

(UP035)


5-5: Missing return type annotation for special method __init__

Add return type annotation: None

(ANN204)

core/src/apps/tron/sign_tx.py

186-186: Avoid specifying long messages outside the exception class

(TRY003)

core/src/trezor/messages.py

71-71: Unused noqa directive (non-enabled: F401)

Remove unused noqa directive

(RUF100)


8878-8878: Dynamically typed expressions (typing.Any) are disallowed in msg

(ANN401)


8894-8894: Dynamically typed expressions (typing.Any) are disallowed in msg

(ANN401)


8910-8910: Dynamically typed expressions (typing.Any) are disallowed in msg

(ANN401)

python/src/trezorlib/messages.py

9100-9100: Remove quotes from type annotation

Remove quotes

(UP037)


10741-10741: Remove quotes from type annotation

Remove quotes

(UP037)


11006-11009: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


11017-11017: Remove quotes from type annotation

Remove quotes

(UP037)


11023-11026: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)

core/src/apps/polkadot/transaction.py

30-30: Boolean-typed positional argument in function definition

(FBT001)


30-30: Boolean default positional argument in function definition

(FBT002)

core/src/apps/tron/serialize.py

223-223: Avoid specifying long messages outside the exception class

(TRY003)

core/src/trezor/lvglui/scrs/template.py

2267-2267: Missing return type annotation for special method __init__

Add return type annotation: None

(ANN204)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Gen check
  • GitHub Check: Defs check
  • GitHub Check: Style check
  • GitHub Check: Analyze (python)
🔇 Additional comments (65)
core/embed/firmware/version.h (1)

11-16: Version bump is consistent and appropriate.

The minor version increment from 4.11.0 to 4.12.0 aligns with the feature additions in this PR. The macro and string values match correctly.

tools/i18n.py (1)

99-102: LGTM!

The replace_breaks: 1 parameter is a clean addition. It tells the Localisé API to handle line breaks consistently.

common/protob/messages-polkadot.proto (1)

35-40: LGTM!

The optional prefix field extends PolkadotSignTx to support custom SS58 address types. This mirrors the prefix field in PolkadotGetAddress (line 16) and maintains backward compatibility.

common/protob/messages-tron.proto (4)

38-38: Breaking change: data type changed from string to bytes.

This field type change may break existing clients that send string data. Ensure all callers are updated to send bytes instead.


66-66: LGTM!

New TRON_POWER = 0x02 enum value cleanly extends the resource types.


102-102: LGTM!

The optional lock_period field extends TronDelegateResourceContract without breaking compatibility.


109-110: LGTM!

New TronCancelAllUnfreezeV2Contract message and optional fields (provider, contract_name, permission_id) are clean additions.

Also applies to: 131-134

core/src/apps/tron/serialize.py (6)

14-16: LGTM!

Clean implementation. The tag computation (fnumber << 3) | ftype follows the protobuf wire format spec correctly.


19-31: LGTM!

Standard Base128 varint encoding. Clean and correct.


62-78: LGTM!

VoteWitnessContract serialization follows the proto definition. Nested Vote messages are encoded correctly with length-prefixed fields.


217-223: LGTM!

CancelAllUnfreezeV2Contract and the fallback ValueError are good additions. The else branch ensures unsupported contracts fail explicitly.


198-200: LGTM!

lock_period serialization uses correct field number 6.


260-262: LGTM!

The data field serialization now handles bytes correctly, matching the proto type change.

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

5-7: LGTM!

TRON_POWER = 2 matches the proto definition. Clean addition.

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

951-953: Energy rental banner text and placement look correct.

The new German string reads clearly and sits right after the “Unbekannte Nachricht” / “Unbekanntes Netzwerk” entries, which keeps it aligned with the new BANNER_ENERGY_RENTAL key and other locales.

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

951-953: Korean energy rental banner is clear and correctly positioned.

The sentence is natural Korean and matches the English intent. It follows the “unknown message/network” entries, so the index lines up with BANNER_ENERGY_RENTAL.

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

951-953: Traditional Chinese banner text matches intent and index.

The new sentence is clear and idiomatic, and it comes right after “未知訊息/未知網路”, so it aligns with BANNER_ENERGY_RENTAL in keys.py.

core/src/trezor/lvglui/i18n/keys.py (1)

2088-2089: New BANNER_ENERGY_RENTAL key is well‑named and correctly indexed.

Comment and name explain the intent, and value 950 right after MSG__UNKNOWN_NETWORK = 949 matches the added locale strings.

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

951-953: English banner copy is clear and aligned with the key definition.

The sentence reads fine, matches the comment in keys.py, and sits after “Unknown Network”, so it lines up with BANNER_ENERGY_RENTAL = 950.

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

951-953: Italian translation is accurate and in the right slot.

The wording is clear Italian for the English banner, and placing it after “Messaggio sconosciuto” / “Rete sconosciuta” keeps indexes aligned with BANNER_ENERGY_RENTAL.

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

951-953: pt‑BR banner text is natural and correctly placed.

The sentence is clear, idiomatic Portuguese and follows the unknown message/network entries, so it aligns with BANNER_ENERGY_RENTAL.

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

1-5: TronMessageType enum stub is minimal and consistent with generated style.

V2 = 2 matches expected enum usage and the file follows the usual pb2py pattern. No changes needed here.

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

953-953: Energy rental banner CN string looks good

Wording is clear, correctly localized, and placement after “未知网络” keeps index alignment with other locales.

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

953-953: Energy rental banner JA string looks good

The sentence is grammatically sound, clear, and matches the intended meaning of the new banner text.

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

728-735: Tron enum additions are consistent and type‑safe

TronMessageType and the new TronResourceCode.TRON_POWER follow the existing enum pattern and stay in sync with the host library definitions; no issues spotted.

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

953-953: Energy rental banner RU string looks good

The new sentence reads naturally, clearly conveys the warning, and keeps index alignment with other locales.

core/src/apps/polkadot/sign_tx.py (1)

19-21: Polkadot address type override is wired correctly

Passing msg.prefix into get_address_type matches the helper’s contract and keeps known‑network mappings authoritative while allowing overrides for others. No functional issues seen.

core/src/all_modules.py (1)

140-143: all_modules qstring coverage updated correctly for Tron

Adding trezor.enums.TronMessageType and apps.tron.providers here matches the existing pattern and will keep their qualified names interned without affecting runtime.

Also applies to: 888-891

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

953-953: Energy rental banner FR string looks good

The sentence is clear, idiomatic French and correctly placed after “Réseau inconnu” to keep indices aligned.

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

953-953: LGTM! Translation addition looks good.

The new Spanish translation for the energy rental provider warning is correctly positioned and grammatically sound.

core/src/apps/tron/sign_tx.py (4)

14-14: LGTM! Import is clean and used.


50-65: LGTM! Energy rental provider detection implemented correctly.

The banner warning triggers when the recipient matches a known energy rental provider address. The lazy i18n import keeps overhead low. Logic is clear and well-structured.


172-184: LGTM! New Tron contract types handled properly.

Both cancel_all_unfreeze_v2 and vote_witness contracts are integrated cleanly with corresponding UI confirmation flows. The list comprehension for vote tuples is idiomatic and clear.


187-189: LGTM! Data confirmation moved to a logical position.

Consolidating the data check after all type-specific handling is cleaner and maintains better separation of concerns.

core/src/apps/tron/sign_message.py (3)

5-5: LGTM! Import is correct.


40-53: LGTM! V2 message type handling implemented correctly.

V2 messages bypass the initial hash and sign the raw message directly, while V1 messages retain the original hashing behavior. The flow is clear and correct.


61-67: LGTM! Function rename improves clarity.

make_message_digest is more descriptive than message_digest, clearly indicating it's a factory/builder function.

core/src/apps/tron/providers.py (2)

16-20: LGTM! Lookup function is clear and correct.

Linear search is appropriate for the small provider list. The function signature and logic are sound.


23-25: LGTM! Provider iterator is clean and extensible.

Single provider (TrxRes) is defined. The generator pattern makes it easy to add more providers in the future.

core/src/apps/polkadot/__init__.py (2)

6-7: Verify the primary color change for DOT and KSM.

Both PRIMARY_COLOR (DOT) and PRIMARY_COLOR_KSM changed from pink (0xE6007A) and white (0xFFFFFF) to bright green (0x00FF33). This significantly alters the UI appearance for existing Polkadot networks.

Confirm this aligns with updated brand guidelines or design requirements.


12-14: LGTM! New Polkadot network constants added.

Hydration, Bifrost, and Bifrost-KSM constants follow the established naming pattern. Colors are consistent with the updated primary color scheme.

Also applies to: 21-23

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

244-277: LGTM! Banner text support added cleanly.

The optional banner_text parameter is backward compatible. The conditional logic for banner creation and container alignment is clear and correct.

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

78-82: LGTM! New Tron confirmation functions exported.

The exports follow the established naming pattern and align with the new Tron contract support.


482-516: LGTM! Banner text parameter propagated correctly.

The optional banner_text parameter is backward compatible and properly passed to TransactionOverview.


2083-2101: LGTM! Tron vote confirmation flow implemented correctly.

The two-step flow (overview → details) provides good UX. Error handling with raise_if_cancelled is consistent with other confirmation functions. Button request types are appropriate.

core/src/trezor/messages.py (5)

7190-7202: PolkadotSignTx prefix field matches the new helper API

Adding prefix: int | None on PolkadotSignTx lines up with the updated get_address_type helper and multi‑network support. The stub shape looks consistent and safe.


8590-8610: TronSignTx data as bytes aligns with contract encoding

Switching data from str | None to bytes | None (field and __init__) matches TronTriggerSmartContract.data and binary encoding expectations, so this reduces type confusion.


8634-8644: TronSignMessage gains message_type and enum wiring is correct

Adding message_type: TronMessageType and the optional ctor arg cleanly wires in the new enum and keeps the default backwards compatible (None when not used).


8668-8702: TronContract extensions for voting/unfreeze metadata look consistent

The extra fields (vote_witness_contract, cancel_all_unfreeze_v2_contract, provider, contract_name, permission_id) and matching __init__ params mirror the desktop trezorlib definitions and keep everything optional, so they won’t break older callers.


8836-8850: TronDelegateResourceContract lock_period addition is safe

lock_period: int | None and its optional ctor arg extend the contract without affecting existing call sites and keep semantics clear.

core/src/apps/polkadot/helper.py (5)

7-26: New Hydration/Bifrost icon and color imports fit existing pattern

The added ICON_* and PRIMARY_COLOR_* imports follow the same style as the existing networks and keep them centralized in the theme module.


32-42: POLKADOT_ADDRESS_TYPES extended cleanly for new networks

Adding hydration, bifrost, and bifrost-ksm here keeps address‑type lookup table‑driven. All three use prefix 0; if any of these chains later diverge, you only need to adjust this list.

Please double‑check chain prefixes against upstream specs to confirm that all three really use 0.


44-55: Hydration and Bifrost tickers read clearly

HYDRATION_COIN_TICKER = "HDX" and BIFROST_COIN_TICKER = "BNC" match common symbols and integrate with the rest of the ticker constants without side effects.


98-161: update_chain_res covers new networks with consistent UX

The new elif branches for hydration, bifrost, and bifrost-ksm set:

  • proper primary colors and icons,
  • chain_name/ticker,
  • 12 decimal places.

This mirrors existing networks and keeps the default “UNKN Chain” fallback intact.


164-170: get_address_type now supports preset prefixes while keeping table lookup first

The new signature and logic:

  • Use preset_prefix only when the network name is unknown.
  • For known networks, still prefer POLKADOT_ADDRESS_TYPES and break early.

That keeps behavior deterministic and adds a controlled override for future chains or special cases.

If you intend preset_prefix to always win, even for known networks, you’d need to invert the precedence; confirm current callers match this intent.

core/src/apps/polkadot/transaction.py (6)

29-36: skip_type_lookup flag is a reasonable extension

Adding skip_type_lookup: bool = False and the guarded read lets you support formats where the variant byte is absent, without touching existing callers. All current uses pass it by keyword, so the signature stays clear.


168-203: Joy deserializer now skips type lookup byte; check against latest spec

Using _readAccountIdLookupOfT_V15(..., skip_type_lookup=True) for Joystream for all four balance calls lets you parse plain AccountId encodings. This change is consistent across methods and avoids desync in the stream.

Confirm Joystream’s current runtime really omits the AccountIdLookup variant byte here; otherwise older tx formats might break.


205-231: Manta/Bifrost share a single deserializer parametrized by address_type

Changing deserialize_manta to accept address_type and wiring all four calls through _readAccountIdLookupOfT_V15(rawtx, address_type) keeps encoding logic in one place and supports multiple chains cleanly.


233-269: Hydration deserializer mirrors Joystream’s skip_type_lookup path

deserialize_hydration adds support for callPrivIdx 1792/1794/1795/1796 using the same skip‑type lookup pattern as Joystream, and consistent balance handling. This gives Hydration first‑class, non‑blind decoding.

Please confirm these call indices match Hydration’s Balances pallet mapping in the targeted runtime.


271-298: Network dispatch now covers manta/bifrost/hydration and keeps a safe fallback

Adding:

  • a shared manta/bifrost/bifrost‑ksm branch with per‑network address_type, and
  • a dedicated hydration branch,

extends decoding without changing behavior for existing networks. Unknown networks still fall back to TransactionUnknown and blind‑sign, which is safe.


318-320: Inline note about future optional fields keeps intent visible

The comment about optional assetId and mode documents remaining payload fields without touching decoding yet. Helpful for future work and harmless now.

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

792-801: TronMessageType enum and TRON_POWER value look consistent

The new TronMessageType enum and TRON_POWER = 2 in TronResourceCode are simple, backward‑compatible additions. Please just confirm all Tron flows that switch on TronResourceCode and TronMessageType handle TRON_POWER and V2 as expected (UI strings, fee estimation, serialization).


10763-10817: TronContract union and metadata fields match the new proto design

The added vote_witness_contract, cancel_all_unfreeze_v2_contract, and the metadata fields (provider, contract_name, permission_id) are wired consistently between FIELDS and __init__. All remain optional, so the wire format stays backward compatible.

Given this is a “union‑like” message, please verify the signing logic in core/src/apps/tron/sign_tx.py still enforces that only the relevant sub‑contract is set at a time and that it uses provider/contract_name/permission_id when present.


10955-10978: TronDelegateResourceContract lock_period addition is straightforward

The new lock_period field is correctly declared as uint64 in FIELDS and exposed as an optional int in __init__, with a direct assignment.

Please confirm the Tron delegation logic treats lock_period=None as “no explicit lock period” and that the UI renders lock + lock_period combinations clearly (especially for the new energy‑rental flows).


10675-10707: Based on my verification, I can now provide the rewritten review comment:

No API breaking change: TronSignTx.data has always been bytes in the wire protocol

The proto file (common/protob/messages-tron.proto line 31) defines optional bytes data = 5, not string. Both the firmware (core/src/trezor/messages.py) and Python client (python/src/trezorlib/messages.py) already define data: "bytes". In-repo tests consistently use binascii.unhexlify() to pass bytes to this field. There is no evidence of a prior string type or any migration from string→bytes. The implementation is internally consistent with the protobuf wire definition.

Comment thread common/protob/messages-tron.proto
Comment thread common/protob/messages-tron.proto
Comment thread core/src/apps/management/recovery_device/homescreen.py
Comment thread core/src/apps/management/reset_device/__init__.py
Comment thread core/src/apps/tron/providers.py
Comment thread core/src/trezor/messages.py
Comment thread core/src/trezor/messages.py
Comment thread core/src/trezor/utils.py
Comment thread core/src/trezor/utils.py
Comment thread python/src/trezorlib/messages.py
1. optimize display for tron energy rental transactions
2. fix side button issue when BLE is connected
3. adjust response timing during device initialization
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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
python/src/trezorlib/messages.py (2)

9084-9104: PolkadotSignTx prefix field is wired correctly; check caller usage

The new optional prefix field matches the uint32 protobuf type and keeps older call sites working if they omit it. Please double‑check any higher‑level Polkadot code to ensure it sets prefix where new SS58 networks require it.

If you want Ruff’s UP037 quiet on this block, you can safely unquote the builtin type in the new argument:

-        address_n: Optional[Sequence["int"]] = None,
-        prefix: Optional["int"] = None,
+        address_n: Optional[Sequence["int"]] = None,
+        prefix: Optional[int] = None,

10727-10744: TronSignMessage.message_type default is sensible; minor type‑hint nit

Using message_type: TronMessageType with default TronMessageType.V1 matches existing enum defaults elsewhere and should be backward‑compatible (older firmware will ignore the extra field). Ruff’s UP037 warning here is only about style; if you care about it in new code, you can drop the quotes:

-        message_type: Optional["TronMessageType"] = TronMessageType.V1,
+        message_type: Optional[TronMessageType] = TronMessageType.V1,

Functionality otherwise looks good.

♻️ Duplicate comments (12)
core/src/session.py (1)

32-35: Remove commented-out dead code.

These lines reference show_onekey_app_guide(), which isn't defined anywhere. Delete them—version control preserves history.

-# if utils.show_app_guide():
-#     from trezor.ui.layouts import show_onekey_app_guide
-
-#     loop.schedule(show_onekey_app_guide())
-
core/src/apps/management/reset_device/__init__.py (1)

125-127: Remove commented dead code.

Delete lines 125-127. Keep only the active await show_onekey_app_guide() call.

-        # if isinstance(ctx, wire.DummyContext):
-        #     utils.make_show_app_guide()
-        # else:
         await show_onekey_app_guide()
core/src/apps/management/recovery_device/homescreen.py (1)

160-164: Remove commented dead code.

Delete lines 160-162 and 164. Keep only the active await show_onekey_app_guide() call. The commented set_homescreen() is unnecessary since show_onekey_app_guide() calls it internally.

-    # if isinstance(ctx, wire.DummyContext):
-    #     utils.make_show_app_guide()
-    # else:
     await show_onekey_app_guide()
-    # set_homescreen()
core/src/trezor/utils.py (2)

54-54: Remove commented flag.

Delete this line. The _SHOW_APP_GUIDE flag is unused.

-# _SHOW_APP_GUIDE = False

164-174: Remove commented-out functions.

Delete the commented show_app_guide() and make_show_app_guide() functions. Verification confirms no active references exist—all calls are also commented out.

-# def show_app_guide():
-#     global _SHOW_APP_GUIDE
-#     if _SHOW_APP_GUIDE:
-#         _SHOW_APP_GUIDE = False
-#         return True
-#     return False
-
-
-# def make_show_app_guide():
-#     global _SHOW_APP_GUIDE
-#     _SHOW_APP_GUIDE = True
core/src/apps/tron/providers.py (1)

1-13: Minor type hint improvements flagged in prior review.

The past review already noted:

  1. Import Iterator from collections.abc instead of typing
  2. Add -> None return type to __init__

These are minor nitpicks. The implementation is functionally correct.

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

239-247: Field numbers mismatch the proto definition.

Past review flagged this issue. It appears unresolved.

According to the proto:

  • provider = 3 ✓ (correct)
  • contract_name = 5 (code uses field 4)
  • permission_id = 6 (code uses field 5)

This will break wire format compatibility.

Apply this diff:

     if contract.provider:
         write_field(retc, 3, TYPE_LEN)
         write_bytes_with_length(retc, contract.provider)
     if contract.contract_name:
-        write_field(retc, 4, TYPE_LEN)
+        write_field(retc, 5, TYPE_LEN)
         write_bytes_with_length(retc, contract.contract_name)
     if contract.permission_id is not None:
-        write_field(retc, 5, TYPE_VARINT)
+        write_field(retc, 6, TYPE_VARINT)
         write_varint(retc, contract.permission_id)
core/src/trezor/lvglui/scrs/template.py (1)

2266-2302: Consider adding -> None to TronVoteWitness.__init__ (repeat).

The TronVoteWitness UI looks good and matches how confirm_tron_vote uses it. To satisfy static analysis and make intent explicit, you can add a -> None return type to __init__, in line with other widget classes.

 class TronVoteWitness(FullSizeWindow):
-    def __init__(
+    def __init__(
         self,
         voter,
         votes,
         primary_color,
-    ):
+    ) -> None:
common/protob/messages-tron.proto (1)

112-119: Proto2: avoid required fields in Vote and add a zero value to TronMessageType (Buf, repeat).

Buf’s warnings still apply here: Vote.vote_address / vote_count are marked required, and TronMessageType has no zero‑valued enum member. To keep proto2 messages easier to evolve and more robust to partial messages, consider making the Vote fields optional (and enforcing presence in application code) and adding a leading sentinel like TRON_MESSAGE_TYPE_UNSPECIFIED = 0 while keeping V1 = 1 and V2 = 2.

-        message TronVoteWitnessContract {
-            message Vote {
-                required string vote_address = 1;
-                required uint32 vote_count = 2;
-            }
+        message TronVoteWitnessContract {
+            message Vote {
+                optional string vote_address = 1;
+                optional uint32 vote_count = 2;
+            }
@@
-enum TronMessageType {
-    V1 = 1 [deprecated=true];
-    V2 = 2;
-}
+enum TronMessageType {
+    TRON_MESSAGE_TYPE_UNSPECIFIED = 0;
+    V1 = 1 [deprecated=true];
+    V2 = 2;
+}

Also applies to: 147-150

core/src/trezor/messages.py (2)

8875-8911: New TronCancelAllUnfreezeV2Contract / TronVoteWitnessContract / Vote stubs match python side

These new classes mirror the shapes and types in python/src/trezorlib/messages.py (votes list, optional support, required vote_address/vote_count). Keeping msg: Any in is_type_of matches the rest of this auto-generated file, so you shouldn’t special-case ANN401 here.


71-71: Drop unused # noqa: F401 on TronMessageType import

Ruff flags this as an unused noqa directive (RUF100) because F401 isn’t enabled. You can safely remove the # noqa: F401 here and keep the import as-is.

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

11000-11036: New Tron voting contracts are consistent; Ruff nits on types/FIELDS remain

TronCancelAllUnfreezeV2Contract follows the usual “empty message” pattern. TronVoteWitnessContract and Vote mirror the core definitions: repeated votes, optional support, and required vote_address/vote_count. Serialization should work as expected.

Ruff’s feedback here is purely about typing:

  • UP037 on quoted non‑forward types:
    • support: Optional["bool"] can be support: Optional[bool].
    • In Vote.__init__, vote_address: "str" and vote_count: "int" can be unquoted.
  • RUF012 on FIELDS being a mutable class attribute without ClassVar: this applies to the entire generated file, not just these classes, so I’d fix it in the generator or via Ruff config rather than hand‑editing just this block.

If you want to address the UP037 hints locally (as suggested in the earlier review), this minimal change is enough:

 class TronVoteWitnessContract(protobuf.MessageType):
@@
-        votes: Optional[Sequence["Vote"]] = None,
-        support: Optional["bool"] = None,
+        votes: Optional[Sequence["Vote"]] = None,
+        support: Optional[bool] = None,
@@
 class Vote(protobuf.MessageType):
@@
-        vote_address: "str",
-        vote_count: "int",
+        vote_address: str,
+        vote_count: int,

Leave FIELDS as‑is unless you plan to update the generator globally.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c8a8900 and b84837e.

📒 Files selected for processing (33)
  • common/protob/check.py (1 hunks)
  • common/protob/messages-tron.proto (5 hunks)
  • core/embed/firmware/version.h (1 hunks)
  • core/src/all_modules.py (2 hunks)
  • core/src/apps/base.py (0 hunks)
  • core/src/apps/management/recovery_device/homescreen.py (1 hunks)
  • core/src/apps/management/reset_device/__init__.py (1 hunks)
  • core/src/apps/tron/layout.py (3 hunks)
  • core/src/apps/tron/providers.py (1 hunks)
  • core/src/apps/tron/serialize.py (3 hunks)
  • core/src/apps/tron/sign_message.py (3 hunks)
  • core/src/apps/tron/sign_tx.py (3 hunks)
  • core/src/session.py (1 hunks)
  • core/src/trezor/enums/TronMessageType.py (1 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 (3 hunks)
  • core/src/trezor/messages.py (11 hunks)
  • core/src/trezor/ui/layouts/lvgl/__init__.py (4 hunks)
  • core/src/trezor/utils.py (2 hunks)
  • python/src/trezorlib/messages.py (13 hunks)
💤 Files with no reviewable changes (1)
  • core/src/apps/base.py
🧰 Additional context used
🧬 Code graph analysis (11)
core/src/all_modules.py (2)
core/src/trezor/enums/__init__.py (1)
  • TronMessageType (728-730)
python/src/trezorlib/messages.py (1)
  • TronMessageType (792-794)
core/src/apps/management/reset_device/__init__.py (1)
core/src/trezor/ui/layouts/lvgl/__init__.py (1)
  • show_onekey_app_guide (1338-1347)
core/src/trezor/enums/__init__.py (1)
python/src/trezorlib/messages.py (2)
  • TronMessageType (792-794)
  • TronResourceCode (797-800)
core/src/trezor/ui/layouts/lvgl/__init__.py (3)
core/src/trezor/lvglui/scrs/template.py (2)
  • TronVoteWitness (2266-2301)
  • AlgoCommon (1398-1413)
core/src/trezor/ui/layouts/lvgl/common.py (2)
  • raise_if_cancelled (31-36)
  • interact (39-46)
core/src/trezor/enums/__init__.py (1)
  • ButtonRequestType (434-454)
core/src/apps/tron/sign_tx.py (2)
core/src/apps/tron/providers.py (1)
  • provider_by_address (16-20)
core/src/apps/tron/layout.py (4)
  • require_confirm_tx (31-46)
  • require_confirm_cancel_all_unfreeze_v2 (239-245)
  • require_confirm_vote_witness (248-263)
  • require_confirm_data (18-28)
core/src/apps/tron/layout.py (1)
core/src/trezor/ui/layouts/lvgl/__init__.py (2)
  • confirm_tron_unfreeze (2025-2050)
  • confirm_tron_vote (2083-2100)
core/src/apps/tron/sign_message.py (3)
core/src/trezor/enums/__init__.py (1)
  • TronMessageType (728-730)
python/src/trezorlib/messages.py (1)
  • TronMessageType (792-794)
core/src/trezor/utils.py (4)
  • extend (316-317)
  • extend (329-330)
  • extend (376-377)
  • get_digest (335-336)
core/src/apps/management/recovery_device/homescreen.py (1)
core/src/trezor/ui/layouts/lvgl/__init__.py (1)
  • show_onekey_app_guide (1338-1347)
core/src/trezor/messages.py (2)
core/src/trezor/enums/__init__.py (2)
  • TronMessageType (728-730)
  • MessageType (27-415)
python/src/trezorlib/messages.py (5)
  • TronMessageType (792-794)
  • TronCancelAllUnfreezeV2Contract (11000-11001)
  • MessageType (36-424)
  • TronVoteWitnessContract (11004-11018)
  • Vote (11021-11035)
core/src/trezor/lvglui/scrs/template.py (3)
core/src/trezor/lvglui/scrs/components/banner.py (1)
  • Banner (12-40)
core/src/trezor/lvglui/scrs/components/container.py (1)
  • ContainerFlexCol (8-38)
core/src/trezor/lvglui/scrs/common.py (1)
  • FullSizeWindow (157-389)
python/src/trezorlib/messages.py (3)
core/src/trezor/enums/__init__.py (3)
  • TronMessageType (728-730)
  • TronResourceCode (732-735)
  • MessageType (27-415)
python/src/trezorlib/protobuf.py (2)
  • Field (148-179)
  • MessageType (189-249)
core/src/trezor/messages.py (3)
  • TronCancelAllUnfreezeV2Contract (8875-8879)
  • TronVoteWitnessContract (8881-8895)
  • Vote (8897-8911)
🪛 Buf (1.60.0)
common/protob/messages-tron.proto

114-114: Field named "vote_address" should not be required.

(FIELD_NOT_REQUIRED)


115-115: Field named "vote_count" should not be required.

(FIELD_NOT_REQUIRED)


148-148: First enum value "V1" should have a numeric value of 0

(ENUM_FIRST_VALUE_ZERO)


159-159: Field named "message" should not be required.

(FIELD_NOT_REQUIRED)

🪛 Ruff (0.14.5)
core/src/apps/tron/providers.py

1-1: Import from collections.abc instead: Iterator

Import from collections.abc

(UP035)


5-5: Missing return type annotation for special method __init__

Add return type annotation: None

(ANN204)

core/src/apps/tron/sign_tx.py

186-186: Avoid specifying long messages outside the exception class

(TRY003)

core/src/apps/tron/layout.py

252-252: Boolean-typed positional argument in function definition

(FBT001)

core/src/trezor/messages.py

71-71: Unused noqa directive (non-enabled: F401)

Remove unused noqa directive

(RUF100)


8878-8878: Dynamically typed expressions (typing.Any) are disallowed in msg

(ANN401)


8894-8894: Dynamically typed expressions (typing.Any) are disallowed in msg

(ANN401)


8910-8910: Dynamically typed expressions (typing.Any) are disallowed in msg

(ANN401)

core/src/apps/tron/serialize.py

223-223: Avoid specifying long messages outside the exception class

(TRY003)

core/src/trezor/lvglui/scrs/template.py

2267-2267: Missing return type annotation for special method __init__

Add return type annotation: None

(ANN204)

python/src/trezorlib/messages.py

9100-9100: Remove quotes from type annotation

Remove quotes

(UP037)


10741-10741: Remove quotes from type annotation

Remove quotes

(UP037)


11006-11009: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


11017-11017: Remove quotes from type annotation

Remove quotes

(UP037)


11023-11026: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Style check
  • GitHub Check: Gen check
  • GitHub Check: Defs check
  • GitHub Check: Analyze (python)
🔇 Additional comments (35)
core/src/trezor/lvglui/i18n/locales/zh_hk.py (1)

953-953: String is properly formatted and grammatically sound.

The new translation string is correctly placed in the array, uses proper Traditional Chinese grammar, and aligns with the energy rental feature described in the PR objectives.

Since the AI summary mentions this mirrors similar expansions across multiple locale files, verify that corresponding strings exist in other language files (e.g., en.py, zh_cn.py) to ensure consistent coverage.

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

953-953: LGTM!

The Korean translation for the energy rental banner is correctly placed and grammatically appropriate.

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

953-953: LGTM!

German translation for the energy rental provider warning is correctly added.

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

953-953: LGTM!

Simplified Chinese translation for the energy rental banner is properly added.

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

953-953: LGTM!

Japanese translation for the energy rental provider warning is correctly placed.

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

16-25: LGTM!

The provider lookup logic is clean and correct. The generator pattern keeps the provider list extensible.

core/src/apps/tron/serialize.py (4)

10-36: LGTM!

The new protobuf encoding helpers are clean. write_field composes the wire tag correctly. write_varint and write_bytes_with_length follow standard protobuf encoding.


62-78: LGTM!

VoteWitnessContract serialization handles nested vote messages correctly. The structure follows standard protobuf patterns for repeated fields.


217-223: LGTM!

CancelAllUnfreezeV2Contract handling and the explicit ValueError for unsupported types are good additions. Clear error messages help debugging.


251-275: LGTM!

The serialize function uses the new helpers consistently. Field numbers align with the Tron transaction format.

common/protob/check.py (1)

18-26: LGTM!

Adding "Tron" to the skip list is correct. The change aligns with the new Tron message types introduced in this PR.

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

953-953: LGTM!

The Portuguese translation for the energy rental banner is correctly added and aligns with the new BANNER_ENERGY_RENTAL key.

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

953-953: LGTM!

The Italian translation for the energy rental banner is correctly placed and consistent with other locale additions.

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

7-7: LGTM!

The TRON_POWER constant is correctly added to the TronResourceCode enum and aligns with the Python messages definition.

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

953-953: LGTM!

The English translation for the energy rental banner is correctly added and serves as the base for other locale translations.

core/src/trezor/lvglui/i18n/keys.py (1)

2088-2089: LGTM!

The BANNER_ENERGY_RENTAL key is correctly defined and aligns with the energy rental translations added across all locale files.

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

735-735: LGTM!

The TRON_POWER = 2 addition to TronResourceCode is correct and consistent with the enum definition in python/src/trezorlib/messages.py.

core/src/all_modules.py (1)

140-141: Tron enum and providers correctly registered in all_modules.

Adding trezor.enums.TronMessageType and apps.tron.providers here matches how other enums/modules are preloaded for qstrings. No issues from a runtime or GC perspective.

Also applies to: 890-891

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

953-954: New Russian banner string reads clearly.

The sentence “Получатель — это известный адрес поставщика услуг аренды энергии.” is clear, natural, and matches the intended “known energy‑rental provider address” banner.

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

5-5: Verify Tron V1/V2 message hashing semantics (possible double‑hash).

For TronMessageType.V2 you pass the raw msg.message into make_message_digest, so the signed digest is keccak("\x19TRON Signed Message:\n" || len(message) || message), which matches the usual Tron signed‑message pattern. For the legacy path you first hash the message (h.extend(msg.message); signing_message = h.get_digest()) and then call make_message_digest(signing_message), so V1 effectively signs keccak(prefix || len(keccak(msg)) || keccak(msg)).

If V1 is meant to preserve the old behavior (or match the standard single‑hash Tron scheme), this double‑hash will change existing signatures. Please double‑check the intended V1 vs V2 behavior and adjust the branches (or helper) so each variant matches the expected signing spec and any existing golden tests.

Also applies to: 41-48, 61-67

core/src/apps/tron/sign_tx.py (2)

14-15: Energy‑rental provider banner is wired correctly into TRX transfers.

Using provider_by_address(recipient) to gate banner_text = _(i18n_keys.BANNER_ENERGY_RENTAL) and passing it through layout.require_confirm_tx(..., banner_text=banner_text) cleanly reuses the generic TransactionOverview UI without touching non‑provider transfers. As long as transfer_contract.to_address is always a non‑empty base58 string from the host, this path looks safe.

Also applies to: 53-65


172-185: New cancel‑all‑unfreeze and vote‑witness flows look correct; confirm UX around extra data.

The new cancel_all_unfreeze_v2_contract and vote_witness_contract branches correctly delegate to layout.require_confirm_cancel_all_unfreeze_v2 and layout.require_confirm_vote_witness, and the vote helper receives (vote_address, vote_count) tuples and support as expected. Moving the generic transaction.data confirmation to the end of _require_confirm_by_type slightly changes the prompt order (type‑specific confirmation now comes before raw‑data review). Please confirm this new ordering is intentional and matches product UX expectations.

Also applies to: 187-191

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

78-83: LVGL layouts: banner support and TRON vote confirmations integrate cleanly.

Exposing the TRON helpers in __all__, threading banner_text through confirm_output() into TransactionOverview, and implementing confirm_tron_vote with an overview (AlgoCommon) followed by the detailed TronVoteWitness screen all follow existing layout patterns. The changes are backward‑compatible and give the Tron flows a consistent UX.

Also applies to: 482-497, 503-512, 2083-2100

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

244-277: TransactionOverview banner integration is consistent and non‑breaking.

Adding the optional banner_text parameter and switching the container’s anchor from self.title to the warning banner when present matches how other warning banners work. Existing callers keep the old layout, while Tron flows can now show an extra contextual banner without further changes.

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

31-46: TRX transfer confirmation now cleanly supports an optional banner.

Threading banner_text through require_confirm_tx into confirm_output is straightforward and keeps the Tron‑specific “energy rental” banner logic outside the generic layout layer. Existing callers that don’t pass a banner remain unaffected.

common/protob/messages-tron.proto (1)

38-42: Tron proto extensions line up with the new transaction and message flows.

Changing TronSignTx.data to bytes, adding TRON_POWER to TronResourceCode, extending the stake/delegate contracts with lock_period, and introducing TronCancelAllUnfreezeV2Contract, TronVoteWitnessContract, and the TronMessageType enum all match how the runtime code now branches in apps.tron.sign_tx and apps.tron.sign_message. As long as you regenerate all language bindings after this change, the wire format remains well‑structured.

Also applies to: 62-67, 86-103, 109-135, 158-160

core/src/trezor/messages.py (5)

7189-7202: PolkadotSignTx: optional prefix field is wired correctly

The new prefix: "int | None" field and matching ctor arg keep this stub in sync with the Polkadot proto and PolkadotGetAddress. No further changes needed here.


8589-8610: TronSignTx: data as bytes | None matches other Tron fields

Switching data (and the ctor param) to bytes | None lines up with TronTriggerSmartContract.data and the underlying proto. This makes the stub type-correct; just ensure call sites now pass bytes, not strings.


8633-8644: TronSignMessage: message_type integration looks consistent

Adding message_type: "TronMessageType" and the optional ctor arg matches the new enum and mirrors how other enums are used here. The TYPE_CHECKING import above provides the symbol, so this is good.


8667-8701: TronContract: new voting/unfreeze/provider fields are correctly exposed

The added fields (vote_witness_contract, cancel_all_unfreeze_v2_contract, provider, contract_name, permission_id) and their optional ctor params all reference existing/new Tron message types and basic types, so the stub now reflects the extended Tron contract proto.


8835-8850: TronDelegateResourceContract: lock_period addition is consistent

The new lock_period: "int | None" field and ctor arg follow the pattern of the existing optional fields and align with the updated proto.

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

792-801: TronMessageType / TRON_POWER enums look correct and in sync

Enum values match the core definitions and wire types; nothing blocking here.


10763-10816: New TronContract fields model voting / cancel‑unfreeze behavior correctly

The added fields (vote_witness_contract, cancel_all_unfreeze_v2_contract, provider, contract_name, permission_id) are optional and typed consistently with the corresponding message types and protobuf tags. This keeps the existing contracts untouched while enabling the new flows, so I don’t see functional or serialization issues here.


10955-10978: TronDelegateResourceContract.lock_period matches schema; behavior looks fine

The new lock_period as an optional uint64 fits the protobuf representation and plugs cleanly into both FIELDS and __init__. No correctness issues on the Python side; just make sure upstream code agrees on the unit (blocks vs seconds) with firmware.


10675-10707: Data field conversion is properly handled; no caller updates needed

The change from str to bytes for the data field is safe. All call sites already use bytes correctly:

  • Tests use binascii.unhexlify() (bytes)
  • CLI passes hex strings through dict_to_proto()value_to_proto(), which converts hex strings to bytes via bytes.fromhex()
  • Core handlers receive bytes and pass to serialize(), which expects bytes

The protobuf infrastructure automatically converts hex string inputs to bytes, so CLI users don't need changes. Direct code already passes bytes or will get a TypeError if passing str.

Comment thread core/embed/firmware/version.h
Comment thread core/src/apps/tron/layout.py
Comment thread core/src/trezor/enums/__init__.py
Comment thread core/src/trezor/enums/TronMessageType.py
Comment thread core/src/trezor/lvglui/i18n/locales/es.py
Comment thread core/src/trezor/lvglui/i18n/locales/fr.py
@somebodyLi somebodyLi enabled auto-merge (squash) November 26, 2025 09:36
@Lu1zz Lu1zz self-requested a review November 26, 2025 10:08
@somebodyLi somebodyLi merged commit eb7f10f into touch Nov 26, 2025
14 checks passed
@somebodyLi somebodyLi deleted the 4.12.0 branch November 26, 2025 10:08
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.

4 participants