-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add benfen support #219
Conversation
概述演练这个拉取请求引入了对 OneKey 固件的重大更新,主要是为 Benfen 区块链添加了全面的支持。更新包括在协议缓冲区(protobuf)中定义新的消息类型、实现处理地址生成、交易签名和消息签名的功能,以及扩展 CLI 和库支持。版本号也相应地从 11 更新到 12。 变更
序列图sequenceDiagram
participant User
participant CLI
participant TrezorDevice
participant BenfenBlockchain
User->>CLI: 发起地址/交易/消息操作
CLI->>TrezorDevice: 发送 Benfen 请求
TrezorDevice->>TrezorDevice: 验证并处理请求
TrezorDevice->>BenfenBlockchain: 签名/验证
BenfenBlockchain-->>TrezorDevice: 返回结果
TrezorDevice-->>CLI: 响应结果
CLI-->>User: 显示结果
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 42
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
core/src/trezor/lvglui/res/chain-benfen.png
is excluded by!**/*.png
📒 Files selected for processing (20)
common/protob/messages-benfen.proto
(1 hunks)common/protob/messages.proto
(1 hunks)core/SConscript.firmware
(2 hunks)core/embed/firmware/version.h
(1 hunks)core/src/all_modules.py
(1 hunks)core/src/apps/benfen/__init__.py
(1 hunks)core/src/apps/benfen/get_address.py
(1 hunks)core/src/apps/benfen/helper.py
(1 hunks)core/src/apps/benfen/layout.py
(1 hunks)core/src/apps/benfen/sign_message.py
(1 hunks)core/src/apps/benfen/sign_tx.py
(1 hunks)core/src/apps/benfen/tx_parser.py
(1 hunks)core/src/apps/workflow_handlers.py
(1 hunks)core/src/trezor/enums/MessageType.py
(1 hunks)core/src/trezor/enums/__init__.py
(1 hunks)core/src/trezor/messages.py
(1 hunks)python/src/trezorlib/benfen.py
(1 hunks)python/src/trezorlib/cli/benfen.py
(1 hunks)python/src/trezorlib/cli/trezorctl.py
(3 hunks)python/src/trezorlib/messages.py
(2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
core/src/apps/benfen/__init__.py
1-1: The file is executable but no shebang is present
(EXE002)
core/src/apps/benfen/sign_message.py
1-1: The file is executable but no shebang is present
(EXE002)
22-22: Trailing comma missing
Add trailing comma
(COM812)
32-32: Avoid specifying long messages outside the exception class
(TRY003)
41-41: Boolean positional value in function call
(FBT003)
41-41: Trailing comma missing
Add trailing comma
(COM812)
45-45: Trailing comma missing
Add trailing comma
(COM812)
core/src/apps/benfen/get_address.py
1-1: The file is executable but no shebang is present
(EXE002)
21-21: Trailing comma missing
Add trailing comma
(COM812)
python/src/trezorlib/cli/benfen.py
33-33: Missing return type annotation for public function cli
Add return type annotation: None
(ANN201)
41-41: Boolean-typed positional argument in function definition
(FBT001)
52-52: Missing return type annotation for public function sign_raw_tx
(ANN201)
63-63: Trailing comma missing
Add trailing comma
(COM812)
69-69: Unnecessary assignment to result
before return
statement
Remove unnecessary assignment
(RET504)
90-90: Unnecessary assignment to output
before return
statement
Remove unnecessary assignment
(RET504)
core/src/apps/benfen/helper.py
1-1: The file is executable but no shebang is present
(EXE002)
core/src/apps/benfen/layout.py
1-1: The file is executable but no shebang is present
(EXE002)
20-20: Trailing comma missing
Add trailing comma
(COM812)
25-25: Unnecessary assignment to result
before return
statement
Remove unnecessary assignment
(RET504)
34-34: Unused function argument: gas_budget
(ARG001)
core/src/apps/benfen/tx_parser.py
1-1: The file is executable but no shebang is present
(EXE002)
31-31: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
31-31: Missing type annotation for function argument data
(ANN001)
34-34: Missing return type annotation for public function to_hex
Add return type annotation: str
(ANN201)
39-39: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
39-39: Missing type annotation for function argument address
(ANN001)
39-39: Missing type annotation for function argument sequence_number
(ANN001)
39-39: Missing type annotation for function argument digest
(ANN001)
44-44: Missing return type annotation for public function to_dict
(ANN201)
53-53: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
53-53: Missing type annotation for function argument data
(ANN001)
58-58: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
58-58: Missing type annotation for function argument kind
(ANN001)
58-58: Missing type annotation for function argument value
(ANN001)
58-58: Missing type annotation for function argument index
(ANN001)
58-58: Missing type annotation for function argument type
(ANN001)
66-66: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
66-66: Missing type annotation for function argument arg_type
(ANN001)
66-66: Missing type annotation for function argument index
(ANN001)
72-72: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
72-72: Missing type annotation for function argument type
(ANN001)
72-72: Missing type annotation for function argument data
(ANN001)
78-78: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
78-78: Missing type annotation for function argument data
(ANN001)
149-149: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
276-276: Missing return type annotation for public function parse_transaction_inputs
(ANN201)
276-276: Missing type annotation for function argument parser
(ANN001)
299-299: Trailing comma missing
Add trailing comma
(COM812)
306-306: Trailing comma missing
Add trailing comma
(COM812)
307-307: Trailing comma missing
Add trailing comma
(COM812)
315-315: Missing return type annotation for public function parse_gas_data
(ANN201)
315-315: Missing type annotation for function argument parser
(ANN001)
324-324: Trailing comma missing
Add trailing comma
(COM812)
333-333: Missing return type annotation for public function parse_transaction_expiration
(ANN201)
333-333: Missing type annotation for function argument parser
(ANN001)
337-337: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
344-344: Missing return type annotation for public function parse_transaction
(ANN201)
344-344: Missing type annotation for function argument hex_data
(ANN001)
386-386: Do not catch blind exception: Exception
(BLE001)
391-391: Missing return type annotation for public function parse_tx
(ANN201)
391-391: Missing type annotation for function argument tx_hex
(ANN001)
408-408: Trailing comma missing
Add trailing comma
(COM812)
413-413: Do not catch blind exception: Exception
(BLE001)
423-423: Trailing comma missing
Add trailing comma
(COM812)
427-427: Trailing comma missing
Add trailing comma
(COM812)
429-429: Consider moving this statement to an else
block
(TRY300)
429-429: Unnecessary assignment to final_result
before return
statement
Remove unnecessary assignment
(RET504)
431-431: Do not catch blind exception: Exception
(BLE001)
python/src/trezorlib/benfen.py
32-32: Boolean-typed positional argument in function definition
(FBT001)
32-32: Boolean default positional argument in function definition
(FBT002)
32-32: Trailing comma missing
Add trailing comma
(COM812)
35-35: Trailing comma missing
Add trailing comma
(COM812)
40-40: Missing return type annotation for public function sign_tx
(ANN201)
54-54: Trailing comma missing
Add trailing comma
(COM812)
core/src/apps/benfen/sign_tx.py
1-1: The file is executable but no shebang is present
(EXE002)
2-2: typing.Tuple
is deprecated, use tuple
instead
(UP035)
21-21: Missing type annotation for function argument ctx
(ANN001)
21-21: Trailing comma missing
Add trailing comma
(COM812)
26-26: Yoda condition detected
Rewrite as intent != INTENT_BYTES
(SIM300)
27-27: Avoid specifying long messages outside the exception class
(TRY003)
32-32: Avoid specifying long messages outside the exception class
(TRY003)
38-38: Avoid specifying long messages outside the exception class
(TRY003)
40-40: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
40-40: Avoid specifying long messages outside the exception class
(TRY003)
82-82: Trailing comma missing
Add trailing comma
(COM812)
92-92: Avoid specifying long messages outside the exception class
(TRY003)
107-107: Missing type annotation for function argument ctx
(ANN001)
107-107: Missing type annotation for function argument msg
(ANN001)
108-108: Yoda condition detected
Rewrite as msg.data_initial_chunk[:3] != INTENT_BYTES
(SIM300)
109-109: Avoid specifying long messages outside the exception class
(TRY003)
130-130: parse_transaction
is too complex (16 > 10)
(C901)
130-130: Use tuple
instead of Tuple
for type annotation
Replace with tuple
(UP006)
162-162: Avoid specifying long messages outside the exception class
(TRY003)
167-167: Do not catch blind exception: Exception
(BLE001)
168-168: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
168-168: Avoid specifying long messages outside the exception class
(TRY003)
174-174: Do not catch blind exception: Exception
(BLE001)
175-175: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
175-175: Avoid specifying long messages outside the exception class
(TRY003)
184-184: Avoid specifying long messages outside the exception class
(TRY003)
186-186: Avoid specifying long messages outside the exception class
(TRY003)
188-188: Avoid specifying long messages outside the exception class
(TRY003)
190-190: Avoid specifying long messages outside the exception class
(TRY003)
232-235: Return the negated condition directly
Inline condition
(SIM103)
python/src/trezorlib/messages.py
1174-1177: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1185-1185: Remove quotes from type annotation
Remove quotes
(UP037)
1191-1193: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1205-1211: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1222-1222: Remove quotes from type annotation
Remove quotes
(UP037)
1231-1234: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1248-1252: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1268-1270: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1282-1285: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1293-1293: Remove quotes from type annotation
Remove quotes
(UP037)
1299-1302: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
core/src/trezor/messages.py
430-430: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
444-444: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
466-466: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
482-482: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
500-500: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
514-514: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
530-530: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
546-546: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
🔇 Additional comments (32)
core/embed/firmware/version.h (1)
12-12
: 版本号更新看起来正常
此修改符合小版本号升级的需求,没有发现问题。
core/src/apps/benfen/helper.py (1)
1-1
: 整体实现良好
未发现主要问题,代码逻辑清晰易懂,保持下去。
🧰 Tools
🪛 Ruff (0.8.2)
1-1: The file is executable but no shebang is present
(EXE002)
core/src/apps/benfen/sign_message.py (3)
1-19
: 模块导入顺序看起来不错!
此处引入了必要的依赖,整体没问题。可以考虑去掉执行权限或添加 shebang,以符合可执行文件的约定。
🧰 Tools
🪛 Ruff (0.8.2)
1-1: The file is executable but no shebang is present
(EXE002)
20-23
: 函数签名定义清晰!
异步函数签名简单易读,自动注入 keychain 的做法也挺巧妙。注意保持与调用方的接口一致。
🧰 Tools
🪛 Ruff (0.8.2)
22-22: Trailing comma missing
Add trailing comma
(COM812)
44-47
: 签名过程合理,返回值合乎预期!
Ed25519 签名与 blake2b 散列配合正常,流程简单明了;注意及时测试兼容性。
🧰 Tools
🪛 Ruff (0.8.2)
45-45: Trailing comma missing
Add trailing comma
(COM812)
python/src/trezorlib/benfen.py (1)
1-29
: 文件头版权说明和类型导入OK!
遵循项目整体规范,相当完整。暂时无特别问题。
common/protob/messages-benfen.proto (7)
1-17
: Proto 语法与包名声明规范!
使用 proto2 并指定包名,布局规范。
18-25
: 解说文档完整,字段命名清晰!
BenfenGetAddress、BenfenAddress 均能很好描述逻辑,不存在明显问题。
26-37
: BenfenSignTx 扩展字段合理!
包括可选 data_initial_chunk, coin_type, data_length,灵活性好。注意测试各种负载大小。
44-47
: 响应消息格式合乎预期!
public_key、signature 设置为 required,能让返回值更确定。使用体验好。
49-60
: BenfenTxRequest 设计足够灵活!
可处理追加请求,也可直接携带签名,减少额外结构。
70-78
: BenfenSignMessage 字段简单明了!
对于一条消息签名需求,address_n 和 message 足以表达。
80-87
: 返回消息结构恰到好处!
signature 与 address 同时返还,一目了然。
python/src/trezorlib/cli/trezorctl.py (2)
119-119
: 新增命令别名"benfen"简洁好用
这个别名让CLI使用benfen功能更顺畅。
479-479
: 将benfen加入CLI命令列表
注册命令流畅,与当前结构保持一致。
core/src/apps/workflow_handlers.py (1)
366-373
: 新增Benfen相关消息类型处理逻辑
实现简明直接,与其他币种逻辑相同。无冲突点,可放心集成。
core/src/trezor/enums/__init__.py (1)
405-412
: 为Benfen新增枚举值
与MessageType.py保持一致,建议确认此处数值无冲突,并在后续测试中验证。
common/protob/messages.proto (1)
557-566
: 新增枚举值看起来很整洁。
这些新增的消息类型符合惯例,命名清晰,可维护性高。
core/SConscript.firmware (1)
18-18
: 开启 SYSTEM_VIEW 功能需留意性能消耗。
系统视图会带来额外的监控开销。建议你在开启后多做压力测试,确保固件稳定。
core/src/all_modules.py (1)
456-469
: 导入 benfen 模块很顺畅。
所有相关的 benfen 子模块均已显式导入,方便 qstring 收集,也让代码更清晰。
core/src/trezor/messages.py (4)
417-432
: 请确保测试新类的可用性。
“BenfenGetAddress” 类隔离性高,调用端需配套测试。请在测试套件中添加用例,确保 address_n、show_display 等字段工作可靠。
🧰 Tools
🪛 Ruff (0.8.2)
430-430: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
503-516
: 确保 data_chunk 块大小有界限。
“BenfenTxAck” 主要传输 data_chunk,建议在调用端或本地进行大小验证,避免内存膨胀或其它安全风险。
🧰 Tools
🪛 Ruff (0.8.2)
514-514: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
517-532
: 检查 message 字段长度。
“BenfenSignMessage” 接受较大的 byte 数据。请对 message 做边界验证,避免潜在的资源消耗。
🧰 Tools
🪛 Ruff (0.8.2)
530-530: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
533-548
: “BenfenMessageSignature” 命名明确,字段简洁。
此类字段清晰易懂,易于后续扩展。可在注释中说明签名流程,以便他人参考。
🧰 Tools
🪛 Ruff (0.8.2)
546-546: Dynamically typed expressions (typing.Any) are disallowed in msg
(ANN401)
python/src/trezorlib/messages.py (5)
413-420
: 消息类型枚举值定义合理
这些枚举值定义了 Benfen 相关的消息类型,从 12201 到 12208,编号连续且无重复。
1189-1201
: BenfenAddress 类定义简洁明了
类的结构清晰,只包含一个必要的地址字段。
🧰 Tools
🪛 Ruff (0.8.2)
1191-1193: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1246-1277
: BenfenTxRequest 和 BenfenTxAck 类的交互逻辑清晰
这两个类构成了请求-响应的配对,用于处理交易数据的分块传输。代码结构合理。
🧰 Tools
🪛 Ruff (0.8.2)
1248-1252: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1268-1270: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1280-1295
: 消息签名相关类定义完整
BenfenSignMessage 和 BenfenMessageSignature 类提供了完整的消息签名功能:
- 输入包含地址路径和消息内容
- 输出包含签名和地址
结构设计合理。
Also applies to: 1297-1312
🧰 Tools
🪛 Ruff (0.8.2)
1282-1285: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1293-1293: Remove quotes from type annotation
Remove quotes
(UP037)
1172-1187
: 🧹 Nitpick (assertive)
BenfenGetAddress 类定义规范
类定义遵循了 protobuf 消息类型的标准格式,包含:
- 正确的 MESSAGE_WIRE_TYPE
- 必要的字段定义
- 合理的初始化方法
建议添加字段注释以提高代码可读性。
class BenfenGetAddress(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 12201
FIELDS = {
+ # 地址路径
+ # 是否显示
}
Likely invalid or redundant comment.
🧰 Tools
🪛 Ruff (0.8.2)
1174-1177: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
1185-1185: Remove quotes from type annotation
Remove quotes
(UP037)
core/src/apps/benfen/__init__.py (3)
1-1
: 导入语句正确!
导入语句遵循项目惯例,使用了标准的 BIP44 ED25519 路径模式。
🧰 Tools
🪛 Ruff (0.8.2)
1-1: The file is executable but no shebang is present
(EXE002)
3-4
: 请验证 SLIP44_ID 注册状态
需要确认 728 是否已在 SLIP44 标准中正式注册为 Benfen 的币种 ID。
✅ Verification successful
SLIP44_ID 728 已注册为 BFC
根据 SLIP44 标准文档,ID 728 (0x800002d8) 已正式注册并分配给 BFC。这与代码中使用的 ID 相符。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查 SLIP44 注册状态
curl -s https://raw.githubusercontent.com/satoshilabs/slips/master/slip-0044.md | grep -B 1 -A 1 "728"
Length of output: 345
6-8
: 检查 UI 资源完整性
请确认:
- 图标文件
chain-benfen.png
是否存在 - 主题色
0xCD4937
是否符合设计规范
✅ Verification successful
UI 资源验证通过
图标文件已确认存在于正确位置:core/src/trezor/lvglui/res/chain-benfen.png
主题色 0xCD4937
符合其他链的配色规范:
- 与 Monero (
0xF36E36
) 和 Polkadot (0xE6007A
) 等链采用类似的醒目色调 - 颜色独特性良好,避免了与其他链的混淆
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查图标文件是否存在
fd "chain-benfen.png" res/
# 检查其他链的主题色作为参考
rg "PRIMARY_COLOR = 0x" core/src/apps/
Length of output: 1828
Script:
#!/bin/bash
# 检查资源目录结构
fd "res" --type d
# 检查所有图标文件位置
fd "chain-.+\.png"
# 检查其他应用的图标路径
rg "ICON = " core/src/apps/
Length of output: 4695
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
core/SConscript.firmware
(1 hunks)core/src/apps/benfen/layout.py
(1 hunks)core/src/apps/benfen/sign_tx.py
(1 hunks)core/src/apps/benfen/tx_parser.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
core/src/apps/benfen/tx_parser.py
1-1: The file is executable but no shebang is present
(EXE002)
31-31: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
31-31: Missing type annotation for function argument data
(ANN001)
34-34: Missing return type annotation for public function to_hex
Add return type annotation: str
(ANN201)
39-39: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
39-39: Missing type annotation for function argument address
(ANN001)
39-39: Missing type annotation for function argument sequence_number
(ANN001)
39-39: Missing type annotation for function argument digest
(ANN001)
44-44: Missing return type annotation for public function to_dict
(ANN201)
53-53: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
53-53: Missing type annotation for function argument data
(ANN001)
58-58: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
58-58: Missing type annotation for function argument kind
(ANN001)
58-58: Missing type annotation for function argument value
(ANN001)
58-58: Missing type annotation for function argument index
(ANN001)
58-58: Missing type annotation for function argument type
(ANN001)
66-66: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
66-66: Missing type annotation for function argument arg_type
(ANN001)
66-66: Missing type annotation for function argument index
(ANN001)
72-72: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
72-72: Missing type annotation for function argument type
(ANN001)
72-72: Missing type annotation for function argument data
(ANN001)
78-78: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
78-78: Missing type annotation for function argument data
(ANN001)
149-149: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
276-276: Missing type annotation for function argument parser
(ANN001)
299-299: Trailing comma missing
Add trailing comma
(COM812)
306-306: Trailing comma missing
Add trailing comma
(COM812)
307-307: Trailing comma missing
Add trailing comma
(COM812)
315-315: Missing type annotation for function argument parser
(ANN001)
324-324: Trailing comma missing
Add trailing comma
(COM812)
333-333: Missing type annotation for function argument parser
(ANN001)
337-337: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
344-344: Missing type annotation for function argument hex_data
(ANN001)
386-386: Do not catch blind exception: Exception
(BLE001)
391-391: Missing type annotation for function argument tx_hex
(ANN001)
408-408: Trailing comma missing
Add trailing comma
(COM812)
413-413: Do not catch blind exception: Exception
(BLE001)
423-423: Trailing comma missing
Add trailing comma
(COM812)
427-427: Trailing comma missing
Add trailing comma
(COM812)
429-429: Consider moving this statement to an else
block
(TRY300)
429-429: Unnecessary assignment to final_result
before return
statement
Remove unnecessary assignment
(RET504)
431-431: Do not catch blind exception: Exception
(BLE001)
core/src/apps/benfen/layout.py
1-1: The file is executable but no shebang is present
(EXE002)
20-20: Trailing comma missing
Add trailing comma
(COM812)
33-33: Unused function argument: gas_budget
(ARG001)
core/src/apps/benfen/sign_tx.py
1-1: The file is executable but no shebang is present
(EXE002)
2-2: typing.Tuple
is deprecated, use tuple
instead
(UP035)
21-21: Missing type annotation for function argument ctx
(ANN001)
29-29: Yoda condition detected
Rewrite as intent != INTENT_BYTES
(SIM300)
30-30: Avoid specifying long messages outside the exception class
(TRY003)
35-35: Avoid specifying long messages outside the exception class
(TRY003)
41-41: Avoid specifying long messages outside the exception class
(TRY003)
43-43: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
43-43: Avoid specifying long messages outside the exception class
(TRY003)
85-85: Trailing comma missing
Add trailing comma
(COM812)
95-95: Avoid specifying long messages outside the exception class
(TRY003)
110-110: Missing type annotation for function argument ctx
(ANN001)
110-110: Missing type annotation for function argument msg
(ANN001)
111-111: Yoda condition detected
Rewrite as msg.data_initial_chunk[:3] != INTENT_BYTES
(SIM300)
112-112: Avoid specifying long messages outside the exception class
(TRY003)
133-133: parse_transaction
is too complex (16 > 10)
(C901)
133-133: Use tuple
instead of Tuple
for type annotation
Replace with tuple
(UP006)
165-165: Avoid specifying long messages outside the exception class
(TRY003)
170-170: Do not catch blind exception: Exception
(BLE001)
171-171: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
171-171: Avoid specifying long messages outside the exception class
(TRY003)
177-177: Do not catch blind exception: Exception
(BLE001)
178-178: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
178-178: Avoid specifying long messages outside the exception class
(TRY003)
187-187: Avoid specifying long messages outside the exception class
(TRY003)
189-189: Avoid specifying long messages outside the exception class
(TRY003)
191-191: Avoid specifying long messages outside the exception class
(TRY003)
193-193: Avoid specifying long messages outside the exception class
(TRY003)
235-238: Return the negated condition directly
Inline condition
(SIM103)
🔇 Additional comments (21)
core/src/apps/benfen/layout.py (4)
1-1
: 请确认无需独立执行脚本。
如本文件无需作为可执行脚本运行,可去掉可执行权限;若需要运行,请添加 Shebang。
🧰 Tools
🪛 Ruff (0.8.2)
1-1: The file is executable but no shebang is present
(EXE002)
20-20
: 与之前评论重复:格式化参数后建议加逗号。
🧰 Tools
🪛 Ruff (0.8.2)
20-20: Trailing comma missing
Add trailing comma
(COM812)
33-33
: 与之前评论重复:未使用的 gas_budget 参数。
如果确实不需要,请移除以保持代码简洁;若将来可能使用,可先保留并加注释。
🧰 Tools
🪛 Ruff (0.8.2)
33-33: Unused function argument: gas_budget
(ARG001)
27-53
: 🛠️ Refactor suggestion
可考虑改进交易费用逻辑。
目前只用到 gas_price 来计算 total_amount,gas_budget 未实际生效。对用户而言,这可能会引起疑惑或错误估算。请评估是否应结合 gas_budget 一并计算费用或移除不必要参数。
🧰 Tools
🪛 Ruff (0.8.2)
33-33: Unused function argument: gas_budget
(ARG001)
core/src/apps/benfen/sign_tx.py (7)
2-2
: 请使用内置的 tuple
替换 typing.Tuple
。
typing.Tuple 已经不推荐使用,换成内置的 tuple 更简洁。
🧰 Tools
🪛 Ruff (0.8.2)
2-2: typing.Tuple
is deprecated, use tuple
instead
(UP035)
21-21
: 为参数 ctx
添加类型注解。
为可读性和可维护性,给 ctx
增加类型注解。
🧰 Tools
🪛 Ruff (0.8.2)
21-21: Missing type annotation for function argument ctx
(ANN001)
29-29
: 避免 Yoda 式的比较写法。
改为 if intent != INTENT_BYTES:
可提升可读性。
🧰 Tools
🪛 Ruff (0.8.2)
29-29: Yoda condition detected
Rewrite as intent != INTENT_BYTES
(SIM300)
111-111
: 再提醒:避免 Yoda 式比较。
请改为 if msg.data_initial_chunk[:3] != INTENT_BYTES:
。
🧰 Tools
🪛 Ruff (0.8.2)
111-111: Yoda condition detected
Rewrite as msg.data_initial_chunk[:3] != INTENT_BYTES
(SIM300)
133-133
: parse_transaction
函数过于复杂。
建议拆分成更小的方法,便于测试和维护。
🧰 Tools
🪛 Ruff (0.8.2)
133-133: parse_transaction
is too complex (16 > 10)
(C901)
133-133: Use tuple
instead of Tuple
for type annotation
Replace with tuple
(UP006)
170-171
: 不要使用笼统的 except Exception
捕获。
请捕获更具体的异常,这样更容易排查错误。
🧰 Tools
🪛 Ruff (0.8.2)
170-170: Do not catch blind exception: Exception
(BLE001)
171-171: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
171-171: Avoid specifying long messages outside the exception class
(TRY003)
178-178
: 同上:请捕获更具体的异常。
避免用 except Exception:
,建议改为更精准的异常类别。
🧰 Tools
🪛 Ruff (0.8.2)
178-178: Within an except
clause, raise exceptions with raise ... from err
or raise ... from None
to distinguish them from errors in exception handling
(B904)
178-178: Avoid specifying long messages outside the exception class
(TRY003)
core/SConscript.firmware (1)
970-970
: 已正确扩展 Benfen 应用目录。
此变动让固件能使用 apps/benfen
下的功能,建议再添加匹配的单元测试。
core/src/apps/benfen/tx_parser.py (9)
31-31
: 重复评论:为 __init__
添加类型注解
建议在参数 data
上加上类型注解,并在函数声明里显式写出 -> None
,有助于静态分析和可读性。
🧰 Tools
🪛 Ruff (0.8.2)
31-31: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
31-31: Missing type annotation for function argument data
(ANN001)
39-39
: 重复评论:为 __init__
添加类型注解
address
, sequence_number
, digest
等参数建议标明类型,并显式写出返回类型为 None
。
🧰 Tools
🪛 Ruff (0.8.2)
39-39: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
39-39: Missing type annotation for function argument address
(ANN001)
39-39: Missing type annotation for function argument sequence_number
(ANN001)
39-39: Missing type annotation for function argument digest
(ANN001)
149-149
: 重复评论:移除多余的 elif
上一条评论也提醒了:前面已有 return
,这里用 elif
没意义,可改成 if
或直接早退。
🧰 Tools
🪛 Ruff (0.8.2)
149-149: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
299-299
: 重复评论:缺少尾随逗号
和过去的评论相同,建议在多行参数或字典结尾添加逗号,便于后续维护和 diff 对比。
🧰 Tools
🪛 Ruff (0.8.2)
299-299: Trailing comma missing
Add trailing comma
(COM812)
306-307
: 重复评论:缺少尾随逗号
在多行字典或函数参数的最后一行,最好加一个逗号,减少无关的后续变动行数。
🧰 Tools
🪛 Ruff (0.8.2)
306-306: Trailing comma missing
Add trailing comma
(COM812)
307-307: Trailing comma missing
Add trailing comma
(COM812)
324-324
: 重复评论:缺少尾随逗号
同样的风格需求,为多行字典的最后一行加逗号有助于后续维护。
🧰 Tools
🪛 Ruff (0.8.2)
324-324: Trailing comma missing
Add trailing comma
(COM812)
386-386
: 重复评论:避免使用通用 except Exception:
可能捕获到意外错误,建议捕获更明确的异常或在异常时打印关键信息,方便排查。
🧰 Tools
🪛 Ruff (0.8.2)
386-386: Do not catch blind exception: Exception
(BLE001)
413-413
: 重复评论:不要盲目捕获 Exception
如无特殊需求,请捕获特定异常类型或在出错时适当记录信息,以利于后续分析。
🧰 Tools
🪛 Ruff (0.8.2)
413-413: Do not catch blind exception: Exception
(BLE001)
431-431
: 重复评论:不要无差别地捕获所有异常
如无特殊需求,捕获更具体的异常类型,或在异常时记录信息,利于追踪问题。
🧰 Tools
🪛 Ruff (0.8.2)
431-431: Do not catch blind exception: Exception
(BLE001)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
core/src/apps/benfen/tx_parser.py
(1 hunks)python/src/trezorlib/cli/benfen.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
python/src/trezorlib/cli/benfen.py
33-33: Missing return type annotation for public function cli
Add return type annotation: None
(ANN201)
41-41: Boolean-typed positional argument in function definition
(FBT001)
52-52: Missing return type annotation for public function sign_raw_tx
(ANN201)
63-63: Trailing comma missing
Add trailing comma
(COM812)
89-89: Unnecessary assignment to output
before return
statement
Remove unnecessary assignment
(RET504)
core/src/apps/benfen/tx_parser.py
1-1: The file is executable but no shebang is present
(EXE002)
31-31: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
31-31: Missing type annotation for function argument data
(ANN001)
34-34: Missing return type annotation for public function to_hex
Add return type annotation: str
(ANN201)
39-39: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
39-39: Missing type annotation for function argument address
(ANN001)
39-39: Missing type annotation for function argument sequence_number
(ANN001)
39-39: Missing type annotation for function argument digest
(ANN001)
44-44: Missing return type annotation for public function to_dict
(ANN201)
53-53: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
53-53: Missing type annotation for function argument data
(ANN001)
58-58: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
58-58: Missing type annotation for function argument kind
(ANN001)
58-58: Missing type annotation for function argument value
(ANN001)
58-58: Missing type annotation for function argument index
(ANN001)
58-58: Missing type annotation for function argument type
(ANN001)
66-66: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
66-66: Missing type annotation for function argument arg_type
(ANN001)
66-66: Missing type annotation for function argument index
(ANN001)
72-72: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
72-72: Missing type annotation for function argument type
(ANN001)
72-72: Missing type annotation for function argument data
(ANN001)
78-78: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
78-78: Missing type annotation for function argument data
(ANN001)
149-149: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
276-276: Missing type annotation for function argument parser
(ANN001)
299-299: Trailing comma missing
Add trailing comma
(COM812)
306-306: Trailing comma missing
Add trailing comma
(COM812)
307-307: Trailing comma missing
Add trailing comma
(COM812)
315-315: Missing type annotation for function argument parser
(ANN001)
324-324: Trailing comma missing
Add trailing comma
(COM812)
333-333: Missing type annotation for function argument parser
(ANN001)
337-337: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
344-344: Missing type annotation for function argument hex_data
(ANN001)
386-386: Do not catch blind exception: Exception
(BLE001)
391-391: Missing type annotation for function argument tx_hex
(ANN001)
408-408: Trailing comma missing
Add trailing comma
(COM812)
413-413: Do not catch blind exception: Exception
(BLE001)
423-423: Trailing comma missing
Add trailing comma
(COM812)
427-427: Trailing comma missing
Add trailing comma
(COM812)
430-430: Do not catch blind exception: Exception
(BLE001)
🔇 Additional comments (16)
python/src/trezorlib/cli/benfen.py (5)
41-41
: 布尔类型参数可用关键字方式
此处与之前评论相似,为避免重复,将其标记为重复。
🧰 Tools
🪛 Ruff (0.8.2)
41-41: Boolean-typed positional argument in function definition
(FBT001)
63-63
: 可添加尾逗号,保持风格一致
此条与之前评论相似。
🧰 Tools
🪛 Ruff (0.8.2)
63-63: Trailing comma missing
Add trailing comma
(COM812)
89-89
: 可直接 return output
此条与之前评论相似,可去掉临时变量,简化代码。
🧰 Tools
🪛 Ruff (0.8.2)
89-89: Unnecessary assignment to output
before return
statement
Remove unnecessary assignment
(RET504)
33-33
: 🧹 Nitpick (assertive)
为 cli()
添加返回类型注解
这能提升可读性并方便后续维护。
- def cli():
+ def cli() -> None:
"""Benfen commands."""
Likely invalid or redundant comment.
🧰 Tools
🪛 Ruff (0.8.2)
33-33: Missing return type annotation for public function cli
Add return type annotation: None
(ANN201)
52-52
: 🧹 Nitpick (assertive)
为 sign_raw_tx
添加返回类型注解
有助于向使用者清晰展示返回对象格式,便于维护。
- def sign_raw_tx(client: "TrezorClient", address: str, message: str, coin_type: str | None):
+ def sign_raw_tx(client: "TrezorClient", address: str, message: str, coin_type: str | None) -> dict:
"""Sign a base64 encoded of the transaction data."""
Likely invalid or redundant comment.
🧰 Tools
🪛 Ruff (0.8.2)
52-52: Missing return type annotation for public function sign_raw_tx
(ANN201)
core/src/apps/benfen/tx_parser.py (11)
1-1
: 移除可执行权限或添加 Shebang(重复)
该文件若仅作库使用,可移除可执行权限;若打算直接执行,可添加 Shebang。
🧰 Tools
🪛 Ruff (0.8.2)
1-1: The file is executable but no shebang is present
(EXE002)
31-31
: 为构造函数添加类型注解与返回类型注解(重复)
__init__
建议声明 -> None
并为 data
添加类型注解,利于可读和静态分析。
🧰 Tools
🪛 Ruff (0.8.2)
31-31: Missing return type annotation for special method __init__
Add return type annotation: None
(ANN204)
31-31: Missing type annotation for function argument data
(ANN001)
34-34
: 为 to_hex
方法添加返回类型注解(重复)
在函数声明处显式标明 -> str
,可增强可读性。
🧰 Tools
🪛 Ruff (0.8.2)
34-34: Missing return type annotation for public function to_hex
Add return type annotation: str
(ANN201)
44-44
: 为 to_dict
方法添加返回类型注解(重复)
在函数声明处显式标明 -> dict
,可让返回值更直观。
🧰 Tools
🪛 Ruff (0.8.2)
44-44: Missing return type annotation for public function to_dict
(ANN201)
149-149
: 去除不必要的 elif
(重复)
前面已执行 return
,此处 elif
无意义,可改成 if
或 else
简化代码。
🧰 Tools
🪛 Ruff (0.8.2)
149-149: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
299-299
: 添加尾随逗号(重复)
在多行参数或列表中添加尾随逗号,能简化 diff,增强可读性。
🧰 Tools
🪛 Ruff (0.8.2)
299-299: Trailing comma missing
Add trailing comma
(COM812)
337-337
: 合并 elif
分支(重复)
前面已有 return
,此处 elif
显得多余,建议简化为 if
或使用 else
。
🧰 Tools
🪛 Ruff (0.8.2)
337-337: Unnecessary elif
after return
statement
Remove unnecessary elif
(RET505)
386-386
: 避免使用无差别的 except Exception:
(重复)
请捕获更精确的异常类型,或增加日志记录,否则会给调试带来难度。
🧰 Tools
🪛 Ruff (0.8.2)
386-386: Do not catch blind exception: Exception
(BLE001)
413-413
: 避免使用无差别的 except Exception:
(重复)
同上所述,请考虑捕获明确的异常类型。
🧰 Tools
🪛 Ruff (0.8.2)
413-413: Do not catch blind exception: Exception
(BLE001)
430-430
: 避免使用无差别的 except Exception:
(重复)
同上所述,请更改为特定异常或适当记录异常信息。
🧰 Tools
🪛 Ruff (0.8.2)
430-430: Do not catch blind exception: Exception
(BLE001)
390-431
: 确认新交易解析逻辑能满足 Benfen 功能需求
请确保本段对交易进行格式化后,接口能正确对接 Benfen 的后续流程,包括签名、校验和展示等。
🧰 Tools
🪛 Ruff (0.8.2)
391-391: Missing type annotation for function argument tx_hex
(ANN001)
408-408: Trailing comma missing
Add trailing comma
(COM812)
413-413: Do not catch blind exception: Exception
(BLE001)
423-423: Trailing comma missing
Add trailing comma
(COM812)
427-427: Trailing comma missing
Add trailing comma
(COM812)
430-430: Do not catch blind exception: Exception
(BLE001)
Summary by CodeRabbit
新功能
版本更新
文档