feat(core): adaptation related to Polkadot updates#615
Conversation
WalkthroughAdds 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
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)
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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Points to focus on:
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
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 newbanner_textparam and its pass‑through toconfirm_outputare straightforward and keep old callers working.- The new helpers for unfreeze v2 and voting hook cleanly into
confirm_tron_unfreezeandconfirm_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 checksYou compare
callPrivIdx(an int) to tuples like(1282, 2562)and(1026, 2562). These conditions never match, so those extrinsics fall back toTransactionUnknownand 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 possibleThe new optional
prefixfield is correctly exposed both inFIELDSand__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 tweakThe new
message_typefield defaults toTronMessageType.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.
⛔ Files ignored due to path filters (5)
core/src/trezor/lvglui/res/chain-bifrost-ksm.pngis excluded by!**/*.pngcore/src/trezor/lvglui/res/chain-bifrost.pngis excluded by!**/*.pngcore/src/trezor/lvglui/res/chain-dot.pngis excluded by!**/*.pngcore/src/trezor/lvglui/res/chain-hydration.pngis excluded by!**/*.pngcore/src/trezor/lvglui/res/chain-kusama.pngis 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: 1parameter 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
prefixfield extendsPolkadotSignTxto support custom SS58 address types. This mirrors theprefixfield inPolkadotGetAddress(line 16) and maintains backward compatibility.common/protob/messages-tron.proto (4)
38-38: Breaking change:datatype changed fromstringtobytes.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 = 0x02enum value cleanly extends the resource types.
102-102: LGTM!The optional
lock_periodfield extendsTronDelegateResourceContractwithout breaking compatibility.
109-110: LGTM!New
TronCancelAllUnfreezeV2Contractmessage 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) | ftypefollows the protobuf wire format spec correctly.
19-31: LGTM!Standard Base128 varint encoding. Clean and correct.
62-78: LGTM!
VoteWitnessContractserialization follows the proto definition. NestedVotemessages are encoded correctly with length-prefixed fields.
217-223: LGTM!
CancelAllUnfreezeV2Contractand the fallbackValueErrorare good additions. The else branch ensures unsupported contracts fail explicitly.
198-200: LGTM!
lock_periodserialization uses correct field number 6.
260-262: LGTM!The
datafield serialization now handles bytes correctly, matching the proto type change.core/src/trezor/enums/TronResourceCode.py (1)
5-7: LGTM!
TRON_POWER = 2matches 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_RENTALkey 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_RENTALinkeys.py.core/src/trezor/lvglui/i18n/keys.py (1)
2088-2089: NewBANNER_ENERGY_RENTALkey is well‑named and correctly indexed.Comment and name explain the intent, and value
950right afterMSG__UNKNOWN_NETWORK = 949matches 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 withBANNER_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 = 2matches 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 goodWording 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 goodThe 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
TronMessageTypeand the newTronResourceCode.TRON_POWERfollow 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 goodThe 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 correctlyPassing
msg.prefixintoget_address_typematches 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 TronAdding
trezor.enums.TronMessageTypeandapps.tron.providershere 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 goodThe 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_v2andvote_witnesscontracts 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_digestis more descriptive thanmessage_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) andPRIMARY_COLOR_KSMchanged 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_textparameter 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_textparameter is backward compatible and properly passed toTransactionOverview.
2083-2101: LGTM! Tron vote confirmation flow implemented correctly.The two-step flow (overview → details) provides good UX. Error handling with
raise_if_cancelledis consistent with other confirmation functions. Button request types are appropriate.core/src/trezor/messages.py (5)
7190-7202: PolkadotSignTxprefixfield matches the new helper APIAdding
prefix: int | NoneonPolkadotSignTxlines up with the updatedget_address_typehelper and multi‑network support. The stub shape looks consistent and safe.
8590-8610: TronSignTxdataas bytes aligns with contract encodingSwitching
datafromstr | Nonetobytes | None(field and__init__) matchesTronTriggerSmartContract.dataand binary encoding expectations, so this reduces type confusion.
8634-8644: TronSignMessage gainsmessage_typeand enum wiring is correctAdding
message_type: TronMessageTypeand the optional ctor arg cleanly wires in the new enum and keeps the default backwards compatible (Nonewhen not used).
8668-8702: TronContract extensions for voting/unfreeze metadata look consistentThe extra fields (
vote_witness_contract,cancel_all_unfreeze_v2_contract,provider,contract_name,permission_id) and matching__init__params mirror the desktoptrezorlibdefinitions and keep everything optional, so they won’t break older callers.
8836-8850: TronDelegateResourceContractlock_periodaddition is safe
lock_period: int | Noneand 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 patternThe added
ICON_*andPRIMARY_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 networksAdding
hydration,bifrost, andbifrost-ksmhere keeps address‑type lookup table‑driven. All three use prefix0; 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"andBIFROST_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 UXThe new
elifbranches forhydration,bifrost, andbifrost-ksmset:
- 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 firstThe new signature and logic:
- Use
preset_prefixonly when the network name is unknown.- For known networks, still prefer
POLKADOT_ADDRESS_TYPESand break early.That keeps behavior deterministic and adds a controlled override for future chains or special cases.
If you intend
preset_prefixto 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 extensionAdding
skip_type_lookup: bool = Falseand 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 specUsing
_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_typeChanging
deserialize_mantato acceptaddress_typeand 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_hydrationadds 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 fallbackAdding:
- 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
TransactionUnknownand blind‑sign, which is safe.
318-320: Inline note about future optional fields keeps intent visibleThe comment about optional
assetIdandmodedocuments 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 consistentThe new
TronMessageTypeenum andTRON_POWER = 2inTronResourceCodeare simple, backward‑compatible additions. Please just confirm all Tron flows that switch onTronResourceCodeandTronMessageTypehandleTRON_POWERandV2as expected (UI strings, fee estimation, serialization).
10763-10817: TronContract union and metadata fields match the new proto designThe added
vote_witness_contract,cancel_all_unfreeze_v2_contract, and the metadata fields (provider,contract_name,permission_id) are wired consistently betweenFIELDSand__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.pystill enforces that only the relevant sub‑contract is set at a time and that it usesprovider/contract_name/permission_idwhen present.
10955-10978: TronDelegateResourceContract lock_period addition is straightforwardThe new
lock_periodfield is correctly declared asuint64inFIELDSand exposed as an optionalintin__init__, with a direct assignment.Please confirm the Tron delegation logic treats
lock_period=Noneas “no explicit lock period” and that the UI renderslock+lock_periodcombinations 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.protoline 31) definesoptional bytes data = 5, not string. Both the firmware (core/src/trezor/messages.py) and Python client (python/src/trezorlib/messages.py) already definedata: "bytes". In-repo tests consistently usebinascii.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.
1. optimize display for tron energy rental transactions 2. fix side button issue when BLE is connected 3. adjust response timing during device initialization
There was a problem hiding this comment.
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: PolkadotSignTxprefixfield is wired correctly; check caller usageThe new optional
prefixfield matches theuint32protobuf type and keeps older call sites working if they omit it. Please double‑check any higher‑level Polkadot code to ensure it setsprefixwhere 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 nitUsing
message_type: TronMessageTypewith defaultTronMessageType.V1matches 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 commentedset_homescreen()is unnecessary sinceshow_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_GUIDEflag is unused.-# _SHOW_APP_GUIDE = False
164-174: Remove commented-out functions.Delete the commented
show_app_guide()andmake_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 = Truecore/src/apps/tron/providers.py (1)
1-13: Minor type hint improvements flagged in prior review.The past review already noted:
- Import
Iteratorfromcollections.abcinstead oftyping- Add
-> Nonereturn 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-> NonetoTronVoteWitness.__init__(repeat).The TronVoteWitness UI looks good and matches how
confirm_tron_voteuses it. To satisfy static analysis and make intent explicit, you can add a-> Nonereturn 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: avoidrequiredfields in Vote and add a zero value to TronMessageType (Buf, repeat).Buf’s warnings still apply here:
Vote.vote_address/vote_countare markedrequired, andTronMessageTypehas no zero‑valued enum member. To keep proto2 messages easier to evolve and more robust to partial messages, consider making the Vote fieldsoptional(and enforcing presence in application code) and adding a leading sentinel likeTRON_MESSAGE_TYPE_UNSPECIFIED = 0while keepingV1 = 1andV2 = 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 sideThese new classes mirror the shapes and types in
python/src/trezorlib/messages.py(votes list, optional support, required vote_address/vote_count). Keepingmsg: Anyinis_type_ofmatches the rest of this auto-generated file, so you shouldn’t special-case ANN401 here.
71-71: Drop unused# noqa: F401onTronMessageTypeimportRuff flags this as an unused
noqadirective (RUF100) becauseF401isn’t enabled. You can safely remove the# noqa: F401here 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
TronCancelAllUnfreezeV2Contractfollows the usual “empty message” pattern.TronVoteWitnessContractandVotemirror the core definitions: repeatedvotes, optionalsupport, and requiredvote_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 besupport: Optional[bool].- In
Vote.__init__,vote_address: "str"andvote_count: "int"can be unquoted.- RUF012 on
FIELDSbeing a mutable class attribute withoutClassVar: 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
FIELDSas‑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.
📒 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_fieldcomposes the wire tag correctly.write_varintandwrite_bytes_with_lengthfollow 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.TronMessageTypeandapps.tron.providershere 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.V2you pass the rawmsg.messageintomake_message_digest, so the signed digest iskeccak("\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 callmake_message_digest(signing_message), so V1 effectively signskeccak(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 gatebanner_text = _(i18n_keys.BANNER_ENERGY_RENTAL)and passing it throughlayout.require_confirm_tx(..., banner_text=banner_text)cleanly reuses the generic TransactionOverview UI without touching non‑provider transfers. As long astransfer_contract.to_addressis 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_contractandvote_witness_contractbranches correctly delegate tolayout.require_confirm_cancel_all_unfreeze_v2andlayout.require_confirm_vote_witness, and the vote helper receives(vote_address, vote_count)tuples andsupportas expected. Moving the generictransaction.dataconfirmation to the end of_require_confirm_by_typeslightly 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__, threadingbanner_textthroughconfirm_output()intoTransactionOverview, and implementingconfirm_tron_votewith an overview (AlgoCommon) followed by the detailedTronVoteWitnessscreen 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_textparameter and switching the container’s anchor fromself.titleto 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_textthroughrequire_confirm_txintoconfirm_outputis 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.datatobytes, addingTRON_POWERtoTronResourceCode, extending the stake/delegate contracts withlock_period, and introducingTronCancelAllUnfreezeV2Contract,TronVoteWitnessContract, and theTronMessageTypeenum all match how the runtime code now branches inapps.tron.sign_txandapps.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: optionalprefixfield is wired correctlyThe new
prefix: "int | None"field and matching ctor arg keep this stub in sync with the Polkadot proto andPolkadotGetAddress. No further changes needed here.
8589-8610: TronSignTx:dataasbytes | Nonematches other Tron fieldsSwitching
data(and the ctor param) tobytes | Nonelines up withTronTriggerSmartContract.dataand the underlying proto. This makes the stub type-correct; just ensure call sites now pass bytes, not strings.
8633-8644: TronSignMessage:message_typeintegration looks consistentAdding
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 exposedThe 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_periodaddition is consistentThe 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 syncEnum values match the core definitions and wire types; nothing blocking here.
10763-10816: New TronContract fields model voting / cancel‑unfreeze behavior correctlyThe 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 fineThe new
lock_periodas an optionaluint64fits the protobuf representation and plugs cleanly into bothFIELDSand__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 neededThe change from
strtobytesfor thedatafield 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 viabytes.fromhex()- Core handlers receive bytes and pass to
serialize(), which expects bytesThe 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
TypeErrorif passingstr.
Summary by CodeRabbit
New Features
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.