-
Notifications
You must be signed in to change notification settings - Fork 50
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: support ton #583
base: touch
Are you sure you want to change the base?
feat: support ton #583
Conversation
Signed-off-by: Lu1zz <[email protected]>
Walkthrough本次更改主要涉及对TON(The Open Network)区块链的支持。更新包括添加新的protobuf消息类型、功能和常量,以便于地址获取、消息签名和证明签名。此外,CLI工具也进行了扩展,以支持TON相关的命令和操作。这些更改增强了现有的Trezor硬件钱包功能,允许用户与TON区块链进行交互。 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TrezorClient
participant TON
User->>TrezorClient: get_address()
TrezorClient->>TON: TonGetAddress
TON-->>TrezorClient: Address
TrezorClient-->>User: Address
User->>TrezorClient: sign_message()
TrezorClient->>TON: TonSignMessage
TON-->>TrezorClient: SignedMessage
TrezorClient-->>User: Signature
User->>TrezorClient: sign_proof()
TrezorClient->>TON: TonSignProof
TON-->>TrezorClient: SignedProof
TrezorClient-->>User: Signature
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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.
Caution
Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.
🛑 Comments failed to post (218)
core/src/trezor/enums/TonWalletVersion.py (1)
5-5: 🧹 Nitpick (assertive)
建议添加常量文档说明
为了提高代码可维护性,建议在常量定义前添加文档注释,说明该版本的具体用途和特性。
建议添加如下注释:
+# TON钱包版本V4R2,用于支持最新的钱包操作 V4R2 = 3
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.# TON钱包版本V4R2,用于支持最新的钱包操作 V4R2 = 3
core/src/trezor/enums/TonWorkChain.py (1)
5-6: 🧹 Nitpick (assertive)
常量定义清晰且符合 TON 区块链规范!
这两个常量定义了 TON 区块链的两个重要工作链:
- BASECHAIN (0):主工作链,用于普通交易
- MASTERCHAIN (1):主链,用于系统操作
这些值与 TON 区块链的技术规范完全一致。
建议在代码中添加简短的注释,说明这些常量的用途,以提高代码可读性。
core/src/apps/ton/tonsdk/boc/dict/__init__.py (1)
1-2: 🧹 Nitpick (assertive)
建议添加模块级文档字符串
为了提高代码可维护性,建议添加一个简短的模块级文档字符串,说明这个包的用途和功能。
建议添加如下文档:
+"""TON区块链的BOC(Binary Object Container)字典操作模块。 + +本模块提供了用于处理TON区块链BOC格式中字典结构的工具函数。 +""" from .find_common_prefix import find_common_prefix # noqa: F401 from .serialize_dict import serialize_dict # noqa: F401📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements."""TON区块链的BOC(Binary Object Container)字典操作模块。 本模块提供了用于处理TON区块链BOC格式中字典结构的工具函数。 """ from .find_common_prefix import find_common_prefix # noqa: F401 from .serialize_dict import serialize_dict # noqa: F401
🧰 Tools
🪛 Ruff
1-1: The file is executable but no shebang is present
(EXE002)
core/src/apps/ton/tonsdk/contract/token/nft/__init__.py (1)
5-9: 🧹 Nitpick (assertive)
__all__
声明完整且规范!
__all__
列表正确导出了所有导入的类,使模块的公共接口清晰明确。建议在后续开发中保持这种良好的封装习惯。core/src/apps/ton/__init__.py (1)
6-8: 🧹 Nitpick (assertive)
钱包路径模式和UI元素设置合理!
- 派生路径遵循BIP-44标准规范
- UI元素(颜色和图标)符合品牌标识
建议添加简单的注释说明PRIMARY_COLOR的用途。
PATTERN = "m/44'/coin_type'/account'" -PRIMARY_COLOR = 0x0098EA +# TON品牌主色调 +PRIMARY_COLOR = 0x0098EA ICON = "A:/res/chain-ton.png"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.PATTERN = "m/44'/coin_type'/account'" # TON品牌主色调 PRIMARY_COLOR = 0x0098EA ICON = "A:/res/chain-ton.png"
core/src/apps/ton/tonsdk/boc/__init__.py (1)
5-13: 🧹 Nitpick (assertive)
公共API定义完整,建议添加模块文档
__all__
列表完整地定义了模块的公共接口。建议在文件顶部添加模块级文档字符串,说明这些公共API的用途。建议添加如下文档:
+"""TON SDK的Bag of Cells (BOC)实现。 + +此模块提供了处理TON区块链数据序列化的核心功能: +- Cell: BOC的基本数据单元 +- Builder: 用于构建Cell的工具 +- DictBuilder: 用于构建字典类型的工具 +"""📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements."""TON SDK的Bag of Cells (BOC)实现。 此模块提供了处理TON区块链数据序列化的核心功能: - Cell: BOC的基本数据单元 - Builder: 用于构建Cell的工具 - DictBuilder: 用于构建字典类型的工具 """ __all__ = [ "Cell", "Builder", "begin_cell", "DictBuilder", "begin_dict", "deserialize_cell_data", "parse_boc_header", ]
core/src/apps/ton/tonsdk/boc/dict/find_common_prefix.py (3)
1-1: 🛠️ Refactor suggestion
需要添加类型注解
为了提高代码的可维护性和IDE支持,建议添加类型注解:
-def find_common_prefix(src): +def find_common_prefix(src: List[str]) -> str:请在文件开头添加:
from typing import List🧰 Tools
🪛 Ruff
1-1: The file is executable but no shebang is present
(EXE002)
1-1: Missing return type annotation for public function
find_common_prefix
(ANN201)
1-1: Missing type annotation for function argument
src
(ANN001)
2-6: 🧹 Nitpick (assertive)
建议添加输入验证和文档
当前代码虽然处理了边界情况,但建议增加以下改进:
- 添加输入类型验证
- 添加函数文档说明
def find_common_prefix(src: List[str]) -> str: + """查找字符串列表中的最长公共前缀。 + + Args: + src: 输入的字符串列表 + + Returns: + 最长公共前缀字符串 + + Raises: + TypeError: 当输入列表包含非字符串元素时 + """ + if not all(isinstance(s, str) for s in src): + raise TypeError("所有元素必须是字符串类型") + # Corner cases📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def find_common_prefix(src: List[str]) -> str: """查找字符串列表中的最长公共前缀。 Args: src: 输入的字符串列表 Returns: 最长公共前缀字符串 Raises: TypeError: 当输入列表包含非字符串元素时 """ if not all(isinstance(s, str) for s in src): raise TypeError("所有元素必须是字符串类型") # Corner cases if len(src) == 0: return "" if len(src) == 1: return src[0]
8-17:
⚠️ Potential issue需要处理字符串长度不一致的情况
当前实现在处理不同长度的字符串时可能会出现索引越界。建议增加长度检查:
# Searching for prefix _sorted = sorted(src) size = 0 + min_length = min(len(_sorted[0]), len(_sorted[-1])) - for i, e in enumerate(_sorted[0]): + for i in range(min_length): if e == _sorted[-1][i]: size += 1 else: break另外,建议添加注释说明当前的优化策略:
- # Searching for prefix + # 通过排序后比较首尾两个字符串来优化查找 + # 因为排序后的字符串,首尾两个字符串的差异最大 + # 如果它们有共同前缀,那么中间的所有字符串也一定有相同的前缀📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.# 通过排序后比较首尾两个字符串来优化查找 # 因为排序后的字符串,首尾两个字符串的差异最大 # 如果它们有共同前缀,那么中间的所有字符串也一定有相同的前缀 _sorted = sorted(src) size = 0 min_length = min(len(_sorted[0]), len(_sorted[-1])) for i in range(min_length): if _sorted[0][i] == _sorted[-1][i]: size += 1 else: break return _sorted[0][:size]
core/src/apps/ton/tonsdk/utils/__init__.py (1)
13-23: 🧹 Nitpick (assertive)
建议保持导入和__all__列表的顺序一致
虽然功能正确,但为了更好的可维护性,建议让
__all__
列表中的项目顺序与导入顺序保持一致。建议按如下方式调整顺序:
__all__ = [ "Address", - "concat_bytes", - "move_to_end", - "tree_walk", - "crc32c", - "crc16", - "read_n_bytes_uint_from_array", - "compare_bytes", - "int_to_hex", + "compare_bytes", + "concat_bytes", + "crc16", + "crc32c", + "int_to_hex", + "move_to_end", + "read_n_bytes_uint_from_array", + "tree_walk", ]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.__all__ = [ "Address", "compare_bytes", "concat_bytes", "crc16", "crc32c", "int_to_hex", "move_to_end", "read_n_bytes_uint_from_array", "tree_walk", ]
core/src/apps/ton/tokens.py (3)
7-7: 🧹 Nitpick (assertive)
建议为常量添加类型注解
为提高代码可读性,建议添加类型注解。
-UNKNOWN_TOKEN = TokenInfo("UNKN", 0) +UNKNOWN_TOKEN: TokenInfo = TokenInfo("UNKN", 0)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.UNKNOWN_TOKEN: TokenInfo = TokenInfo("UNKN", 0)
1-4: 🧹 Nitpick (assertive)
需要添加类型注解和文档
建议进行以下改进:
- 为
__init__
方法的self
参数添加类型注解- 添加类文档字符串,说明类的用途和属性含义
建议按如下方式修改代码:
+from typing import Self + class TokenInfo: + """表示TON代币的信息。 + + Attributes: + symbol: 代币符号 + decimals: 代币小数位数 + """ - def __init__(self, symbol: str, decimals: int) -> None: + def __init__(self: Self, symbol: str, decimals: int) -> None: self.symbol = symbol self.decimals = decimals📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from typing import Self class TokenInfo: """表示TON代币的信息。 Attributes: symbol: 代币符号 decimals: 代币小数位数 """ def __init__(self: Self, symbol: str, decimals: int) -> None: self.symbol = symbol self.decimals = decimals
🧰 Tools
🪛 Ruff
2-2: Missing type annotation for
self
in method(ANN101)
10-18: 💡 Codebase verification
⚠️ Potential issue建议优化代币地址处理逻辑
代码分析显示:
- TokenInfo类已经有类型注解,其他模块也在使用typing
- 项目中已有ValueError异常处理模式
- TON_TOKEN仅在两处使用,没有统一常量定义
建议修改如下:
from typing import Literal # 将地址映射移至模块级常量 TON_TOKEN_MAPPING = { "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA": TokenInfo("jUSDT", 6), "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs": TokenInfo("USDT", 6), "EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT": TokenInfo("NOT", 9), } def token_by_address( token_type: Literal["TON_TOKEN"], address: str ) -> TokenInfo: """获取代币信息。""" if not isinstance(address, str): raise TypeError("地址必须为字符串") if not address.startswith("EQ"): raise ValueError("无效的TON地址格式") if token_type != "TON_TOKEN": raise ValueError(f"不支持的代币类型: {token_type}") return TON_TOKEN_MAPPING.get(address, UNKNOWN_TOKEN)🔗 Analysis chain
函数实现需要多处改进
当前实现存在以下问题:
- 缺少参数类型注解
- 硬编码的代币地址不易维护
- 缺少地址格式验证
- 缺少token_type参数验证
建议按如下方式改进:
-def token_by_address(token_type, address) -> TokenInfo: +from typing import Literal + +def token_by_address( + token_type: Literal["TON_TOKEN"], + address: str +) -> TokenInfo: + """根据代币类型和地址返回代币信息。 + + Args: + token_type: 代币类型,目前仅支持 "TON_TOKEN" + address: TON代币合约地址 + + Returns: + TokenInfo: 代币信息对象 + """ + if not isinstance(address, str): + raise TypeError("地址必须是字符串类型") + + if not address.startswith("EQ"): + raise ValueError("无效的TON地址格式") + if token_type == "TON_TOKEN": - if address == "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA": - return TokenInfo("jUSDT", 6) - if address == "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs": - return TokenInfo("USDT", 6) - if address == "EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT": - return TokenInfo("NOT", 9) + # 将代币地址映射移到配置文件或常量中 + TOKEN_MAPPING = { + "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA": TokenInfo("jUSDT", 6), + "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs": TokenInfo("USDT", 6), + "EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT": TokenInfo("NOT", 9), + } + return TOKEN_MAPPING.get(address, UNKNOWN_TOKEN) + else: + raise ValueError(f"不支持的代币类型: {token_type}") - return UNKNOWN_TOKEN验证代币地址的有效性:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 检查这些地址是否在其他地方被引用或验证 rg "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA|EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs|EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT"Length of output: 459
Script:
#!/bin/bash # Check if there are any token address validations or tests rg -A 3 "def.*validate.*address|def.*check.*address" core/src/apps/ton/ # Check if there are any token type validations or constants rg "TON_TOKEN" core/src/apps/ton/ # Check for TokenInfo class definition and usage ast-grep --pattern 'class TokenInfo { $$$ }'Length of output: 332
Script:
#!/bin/bash # Check TokenInfo class implementation rg -A 5 "class TokenInfo" # Check if there are any existing type hints or imports rg "from typing import|import typing" core/src/apps/ton/ # Look for any existing error handling patterns rg "raise (TypeError|ValueError)" core/src/apps/ton/Length of output: 3590
🧰 Tools
🪛 Ruff
10-10: Missing type annotation for function argument
token_type
(ANN001)
10-10: Missing type annotation for function argument
address
(ANN001)
11-11: Possible hardcoded password assigned to: "token_type"
(S105)
core/src/apps/ton/tonsdk/contract/token/nft/nft_utils.py (3)
19-24: 🛠️ Refactor suggestion
建议添加类型提示和错误处理
-def create_offchain_uri_cell(uri): +def create_offchain_uri_cell(uri: str) -> Cell: + if not isinstance(uri, str): + raise ValueError("URI must be a string") cell = Cell() cell.bits.write_uint8(OFFCHAIN_CONTENT_PREFIX) cell.bits.write_bytes(serialize_uri(uri)) return cell📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def create_offchain_uri_cell(uri: str) -> Cell: if not isinstance(uri, str): raise ValueError("URI must be a string") cell = Cell() cell.bits.write_uint8(OFFCHAIN_CONTENT_PREFIX) cell.bits.write_bytes(serialize_uri(uri)) return cell
🧰 Tools
🪛 Ruff
19-19: Missing return type annotation for public function
create_offchain_uri_cell
(ANN201)
19-19: Missing type annotation for function argument
uri
(ANN001)
11-17: 🛠️ Refactor suggestion
建议添加类型提示和输入验证
代码功能正确,但可以通过以下改进增强安全性:
-def serialize_uri(uri): +def serialize_uri(uri: str) -> bytes: + if not isinstance(uri, str): + raise ValueError("URI must be a string") return urllib.parse.quote(uri, safe="~@#$&()*!+=:;,?/'").encode() -def parse_uri(uri): +def parse_uri(uri: bytes) -> str: + if not isinstance(uri, bytes): + raise ValueError("URI must be bytes") return uri.decode()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def serialize_uri(uri: str) -> bytes: if not isinstance(uri, str): raise ValueError("URI must be a string") return urllib.parse.quote(uri, safe="~@#$&()*!+=:;,?/'").encode() def parse_uri(uri: bytes) -> str: if not isinstance(uri, bytes): raise ValueError("URI must be bytes") return uri.decode()
🧰 Tools
🪛 Ruff
11-11: Missing return type annotation for public function
serialize_uri
(ANN201)
11-11: Missing type annotation for function argument
uri
(ANN001)
15-15: Missing return type annotation for public function
parse_uri
(ANN201)
15-15: Missing type annotation for function argument
uri
(ANN001)
26-42: 🛠️ Refactor suggestion
优化代码逻辑,提高性能
当前代码存在以下问题:
- 重复计算长度
- 使用assert进行验证不够安全
- 位操作逻辑可以简化
建议重构如下:
-def parse_offchain_uri_cell(cell): +def parse_offchain_uri_cell(cell: Cell) -> str: + if not isinstance(cell, Cell): + raise ValueError("Input must be a Cell") + if cell.bits[0] != OFFCHAIN_CONTENT_PREFIX: + raise ValueError("Invalid offchain uri cell") - assert cell.bits[0] == OFFCHAIN_CONTENT_PREFIX, "Invalid offchain uri cell" - length = 0 - c = cell - while c: - length += len(c.bits) - c = c.refs[0] if c.refs else None _bytes = b"" - length = 0 c = cell while c: _bytes += c.bits - length += len(c.bits) c = c.refs[0] if c.refs else None return parse_uri(_bytes[1:])📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def parse_offchain_uri_cell(cell: Cell) -> str: if not isinstance(cell, Cell): raise ValueError("Input must be a Cell") if cell.bits[0] != OFFCHAIN_CONTENT_PREFIX: raise ValueError("Invalid offchain uri cell") _bytes = b"" c = cell while c: _bytes += c.bits c = c.refs[0] if c.refs else None return parse_uri(_bytes[1:])
🧰 Tools
🪛 Ruff
26-26: Missing return type annotation for public function
parse_offchain_uri_cell
(ANN201)
26-26: Missing type annotation for function argument
cell
(ANN001)
27-27: Use of
assert
detected(S101)
core/src/apps/ton/tonsdk/contract/wallet/__init__.py (2)
13-18: 🧹 Nitpick (assertive)
建议添加类文档说明
为
WalletVersionEnum
类添加文档字符串,说明每个钱包版本的具体用途和区别。这将帮助其他开发者更好地理解和使用这些版本。class WalletVersionEnum(str, Enum): + """TON钱包合约版本枚举。 + + 支持的版本: + - v3r1: 钱包合约 V3 修订版1 + - v3r2: 钱包合约 V3 修订版2 + - v4r1: 钱包合约 V4 修订版1 + - v4r2: 钱包合约 V4 修订版2 + """ v3r1 = "v3r1"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.class WalletVersionEnum(str, Enum): """TON钱包合约版本枚举。 支持的版本: - v3r1: 钱包合约 V3 修订版1 - v3r2: 钱包合约 V3 修订版2 - v4r1: 钱包合约 V4 修订版1 - v4r2: 钱包合约 V4 修订版2 """ v3r1 = "v3r1" v3r2 = "v3r2" v4r1 = "v4r1" v4r2 = "v4r2"
20-27: 🛠️ Refactor suggestion
需要添加类型注解
为了提高代码的类型安全性,建议进行以下改进:
+from typing import ClassVar, Dict, Type + class Wallets: - default_version = WalletVersionEnum.v3r2 - ALL = { + default_version: ClassVar[WalletVersionEnum] = WalletVersionEnum.v3r2 + ALL: ClassVar[Dict[WalletVersionEnum, Type[WalletContract]]] = { WalletVersionEnum.v3r1: WalletV3ContractR1, WalletVersionEnum.v3r2: WalletV3ContractR2, WalletVersionEnum.v4r1: WalletV4ContractR1, WalletVersionEnum.v4r2: WalletV4ContractR2, }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from typing import ClassVar, Dict, Type class Wallets: default_version: ClassVar[WalletVersionEnum] = WalletVersionEnum.v3r2 ALL: ClassVar[Dict[WalletVersionEnum, Type[WalletContract]]] = { WalletVersionEnum.v3r1: WalletV3ContractR1, WalletVersionEnum.v3r2: WalletV3ContractR2, WalletVersionEnum.v4r1: WalletV4ContractR1, WalletVersionEnum.v4r2: WalletV4ContractR2, }
🧰 Tools
🪛 Ruff
22-27: Mutable class attributes should be annotated with
typing.ClassVar
(RUF012)
common/protob/check.py (1)
18-18: 🧹 Nitpick (assertive)
建议改进代码组织
建议将豁免前缀列表提取为常量,使代码更易维护:
+SKIP_PREFIX_VALIDATION = frozenset(( + "Bitcoin", "Bootloader", "Common", + "Crypto", "Management", "Ton" +)) - if prefix in ("Bitcoin", "Bootloader", "Common", "Crypto", "Management", "Ton"): + if prefix in SKIP_PREFIX_VALIDATION:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.SKIP_PREFIX_VALIDATION = frozenset(( "Bitcoin", "Bootloader", "Common", "Crypto", "Management", "Ton" )) if prefix in SKIP_PREFIX_VALIDATION:
core/src/apps/ton/tonsdk/boc/_dict_builder.py (7)
21-28: 🛠️ Refactor suggestion
完善 store_ref 方法的参数验证
建议进行以下改进:
- 添加参数和返回值的类型注解
- 在创建新的 Cell 之前验证输入参数
- 使用异常替代断言进行验证
- def store_ref(self, index, value: Cell): + def store_ref(self, index: Union[int, bytes], value: Cell) -> 'DictBuilder': - assert self.ended is False, "Already ended" + if self.ended: + raise ValueError("Dictionary already ended") + if not isinstance(value, Cell): + raise TypeError("Value must be a Cell instance") cell = Cell() cell.refs.append(value) self.store_cell(index, cell) return self📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def store_ref(self, index: Union[int, bytes], value: Cell) -> 'DictBuilder': if self.ended: raise ValueError("Dictionary already ended") if not isinstance(value, Cell): raise TypeError("Value must be a Cell instance") cell = Cell() cell.refs.append(value) self.store_cell(index, cell) return self
🧰 Tools
🪛 Ruff
21-21: Missing return type annotation for private function
store_ref
(ANN202)
21-21: Missing type annotation for
self
in method(ANN101)
21-21: Missing type annotation for function argument
index
(ANN001)
22-22: Use of
assert
detected(S101)
11-20: 🛠️ Refactor suggestion
改进类型检查和验证逻辑
当前实现存在以下问题:
- 使用
type()
进行类型检查不如使用isinstance()
- 缺少参数类型注解
- 使用 assert 进行验证可能在生产环境被禁用
- def store_cell(self, index, value: Cell): + def store_cell(self, index: Union[int, bytes], value: Cell) -> 'DictBuilder': assert self.ended is False, "Already ended" - if type(index) == bytes: + if isinstance(index, bytes): index = int(index.hex(), 16) - assert type(index) == int, "Invalid index type" + if not isinstance(index, int): + raise TypeError("Invalid index type") - assert not (index in self.items), f"Item {index} already exist" + if index in self.items: + raise ValueError(f"Item {index} already exists") self.items[index] = value return self📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def store_cell(self, index: Union[int, bytes], value: Cell) -> 'DictBuilder': assert self.ended is False, "Already ended" if isinstance(index, bytes): index = int(index.hex(), 16) if not isinstance(index, int): raise TypeError("Invalid index type") if index in self.items: raise ValueError(f"Item {index} already exists") self.items[index] = value return self
🧰 Tools
🪛 Ruff
11-11: Missing return type annotation for private function
store_cell
(ANN202)
11-11: Missing type annotation for
self
in method(ANN101)
11-11: Missing type annotation for function argument
index
(ANN001)
12-12: Use of
assert
detected(S101)
13-13: Use
is
andis not
for type comparisons, orisinstance()
for isinstance checks(E721)
16-16: Use of
assert
detected(S101)
16-16: Use
is
andis not
for type comparisons, orisinstance()
for isinstance checks(E721)
17-17: Use of
assert
detected(S101)
17-17: Test for membership should be
not in
Convert to
not in
(E713)
46-47: 🧹 Nitpick (assertive)
完善 begin_dict 工厂函数
需要添加以下内容:
- 参数和返回值的类型注解
- 函数文档
- key_size 参数验证
-def begin_dict(key_size): +def begin_dict(key_size: int) -> DictBuilder: + """创建新的字典构建器实例。 + + Args: + key_size: 字典键的位大小 + + Returns: + DictBuilder: 新的字典构建器实例 + + Raises: + ValueError: 当 key_size 不是正整数时 + """ + if not isinstance(key_size, int) or key_size <= 0: + raise ValueError("key_size must be a positive integer") return DictBuilder(key_size)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def begin_dict(key_size: int) -> DictBuilder: """创建新的字典构建器实例。 Args: key_size: 字典键的位大小 Returns: DictBuilder: 新的字典构建器实例 Raises: ValueError: 当 key_size 不是正整数时 """ if not isinstance(key_size, int) or key_size <= 0: raise ValueError("key_size must be a positive integer") return DictBuilder(key_size)
🧰 Tools
🪛 Ruff
46-46: Missing return type annotation for private function
begin_dict
(ANN202)
46-46: Missing type annotation for function argument
key_size
(ANN001)
40-44: 🧹 Nitpick (assertive)
明确 end_cell 方法的用途并改进实现
建议进行以下改进:
- 添加方法文档说明其与 end_dict 的区别
- 改进验证逻辑
- 考虑重用 end_dict 的验证代码
- def end_cell(self) -> Cell: + def end_cell(self) -> Cell: + """完成非空字典的构建并返回最终的 Cell。 + + 与 end_dict 不同,此方法要求字典必须包含数据。 + + Raises: + ValueError: 当字典为空或已经结束时抛出 + """ - assert self.ended is False, "Already ended" - assert self.items, "Dict is empty" + if self.ended: + raise ValueError("Dictionary already ended") + if not self.items: + raise ValueError("Dictionary is empty") return self.end_dict()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def end_cell(self) -> Cell: """完成非空字典的构建并返回最终的 Cell。 与 end_dict 不同,此方法要求字典必须包含数据。 Raises: ValueError: 当字典为空或已经结束时抛出 """ if self.ended: raise ValueError("Dictionary already ended") if not self.items: raise ValueError("Dictionary is empty") return self.end_dict()
🧰 Tools
🪛 Ruff
40-40: Missing type annotation for
self
in method(ANN101)
41-41: Use of
assert
detected(S101)
42-42: Use of
assert
detected(S101)
1-10: 🧹 Nitpick (assertive)
需要添加类型注解和文档
建议进行以下改进:
- 为
__init__
方法添加返回类型注解- 添加类级别的文档字符串,说明类的用途和用法
- 为
self
参数添加类型注解from ._cell import Cell from .dict import serialize_dict class DictBuilder: + """用于构建 TON 区块链字典结构的构建器类。 + + 用于存储和管理 Cell 对象的集合,支持按索引存储和引用操作。 + """ - def __init__(self, key_size: int): + def __init__(self, key_size: int) -> None: self.key_size = key_size self.items = {} self.ended = False📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from ._cell import Cell from .dict import serialize_dict class DictBuilder: """用于构建 TON 区块链字典结构的构建器类。 用于存储和管理 Cell 对象的集合,支持按索引存储和引用操作。 """ def __init__(self, key_size: int) -> None: self.key_size = key_size self.items = {} self.ended = False
🧰 Tools
🪛 Ruff
1-1: The file is executable but no shebang is present
(EXE002)
6-6: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
6-6: Missing type annotation for
self
in method(ANN101)
29-39: 🛠️ Refactor suggestion
优化 end_dict 方法的实现
存在以下问题:
default_serializer
内部函数缺少类型注解和文档- 空字典返回空 Cell 的逻辑需要说明
- 使用断言进行状态检查不够安全
- def end_dict(self) -> Cell: + def end_dict(self) -> Cell: + """完成字典构建并返回最终的 Cell。 + + Returns: + Cell: 如果字典为空返回空 Cell,否则返回序列化后的字典。 + """ - assert self.ended is False, "Already ended" + if self.ended: + raise ValueError("Dictionary already ended") self.ended = True if not self.items: - return Cell() # ? + return Cell() # 返回空 Cell 表示空字典 - def default_serializer(src, dest): + def default_serializer(src: Cell, dest: Cell) -> None: + """默认的序列化处理函数""" dest.write_cell(src) return serialize_dict(self.items, self.key_size, default_serializer)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def end_dict(self) -> Cell: """完成字典构建并返回最终的 Cell。 Returns: Cell: 如果字典为空返回空 Cell,否则返回序列化后的字典。 """ if self.ended: raise ValueError("Dictionary already ended") self.ended = True if not self.items: return Cell() # 返回空 Cell 表示空字典 def default_serializer(src: Cell, dest: Cell) -> None: """默认的序列化处理函数""" dest.write_cell(src) return serialize_dict(self.items, self.key_size, default_serializer)
🧰 Tools
🪛 Ruff
29-29: Missing type annotation for
self
in method(ANN101)
30-30: Use of
assert
detected(S101)
35-35: Missing return type annotation for private function
default_serializer
Add return type annotation:
None
(ANN202)
35-35: Missing type annotation for function argument
src
(ANN001)
35-35: Missing type annotation for function argument
dest
(ANN001)
1-47: 💡 Codebase verification
⚠️ Potential issue建议改进代码安全性和错误处理
代码需要以下改进:
- 将 assert 语句替换为显式异常:
if self.ended: raise ValueError("Already ended")
- 添加 key_size 的验证:
def __init__(self, key_size: int): if not isinstance(key_size, int) or key_size <= 0: raise ValueError("key_size must be a positive integer") self.key_size = key_size
- 对整数转换添加安全检查:
def store_cell(self, index, value: Cell): if isinstance(index, bytes): try: index = int.from_bytes(index, 'big') except OverflowError: raise ValueError("Index value too large")🔗 Analysis chain
安全性建议
代码中存在以下安全隐患:
- 使用 assert 进行验证可能在生产环境被禁用
- 缺少对 key_size 的范围验证
- 整数转换可能导致溢出
建议:
- 将所有 assert 替换为显式的异常处理
- 添加 key_size 的上限检查
- 添加整数转换的溢出检查
Let me analyze the validation patterns before providing the final response.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 检查是否有其他文件也使用了不安全的 assert rg -l "assert\s+.*" --type pyLength of output: 11838
Script:
#!/bin/bash # Check if there are any validation checks for key_size in other files rg -p "key_size" core/src/apps/ton/tonsdk/boc/ # Check if there are any exception handling patterns in TON SDK rg -p "raise\s+\w+Error" core/src/apps/ton/tonsdk/Length of output: 1992
🧰 Tools
🪛 Ruff
1-1: The file is executable but no shebang is present
(EXE002)
6-6: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
6-6: Missing type annotation for
self
in method(ANN101)
11-11: Missing return type annotation for private function
store_cell
(ANN202)
11-11: Missing type annotation for
self
in method(ANN101)
11-11: Missing type annotation for function argument
index
(ANN001)
12-12: Use of
assert
detected(S101)
13-13: Use
is
andis not
for type comparisons, orisinstance()
for isinstance checks(E721)
16-16: Use of
assert
detected(S101)
16-16: Use
is
andis not
for type comparisons, orisinstance()
for isinstance checks(E721)
17-17: Use of
assert
detected(S101)
17-17: Test for membership should be
not in
Convert to
not in
(E713)
21-21: Missing return type annotation for private function
store_ref
(ANN202)
21-21: Missing type annotation for
self
in method(ANN101)
21-21: Missing type annotation for function argument
index
(ANN001)
22-22: Use of
assert
detected(S101)
29-29: Missing type annotation for
self
in method(ANN101)
30-30: Use of
assert
detected(S101)
35-35: Missing return type annotation for private function
default_serializer
Add return type annotation:
None
(ANN202)
35-35: Missing type annotation for function argument
src
(ANN001)
35-35: Missing type annotation for function argument
dest
(ANN001)
40-40: Missing type annotation for
self
in method(ANN101)
41-41: Use of
assert
detected(S101)
42-42: Use of
assert
detected(S101)
46-46: Missing return type annotation for private function
begin_dict
(ANN202)
46-46: Missing type annotation for function argument
key_size
(ANN001)
core/src/apps/ton/tonsdk/contract/token/nft/nft_sale.py (4)
5-6: 🧹 Nitpick (assertive)
需要为合约代码添加注释说明
合约代码是重要的实现细节,建议添加注释说明其用途和来源。这将帮助其他开发者更好地理解和维护代码。
27-31: 🧹 Nitpick (assertive)
建议将操作码定义为常量
将魔法数字
3
定义为有意义的常量,可以提高代码的可读性和可维护性。class NFTSale(Contract): + OPERATION_CANCEL = 3 + def create_cancel_body(self, query_id: int = 0) -> Cell: cell = Cell() - cell.bits.write_uint(3, 32) # cancel OP-code + cell.bits.write_uint(self.OPERATION_CANCEL, 32) # cancel OP-code cell.bits.write_uint(query_id, 64)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.OPERATION_CANCEL = 3 def create_cancel_body(self, query_id: int = 0) -> Cell: cell = Cell() cell.bits.write_uint(self.OPERATION_CANCEL, 32) # cancel OP-code cell.bits.write_uint(query_id, 64) return cell
🧰 Tools
🪛 Ruff
27-27: Missing type annotation for
self
in method(ANN101)
8-11: 🧹 Nitpick (assertive)
建议添加类型注解
为提高代码的可维护性和类型安全性,建议添加以下类型注解:
- def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def __init__(self, **kwargs) -> None: self.code = kwargs.get("code") or self.code kwargs["code"] = Cell.one_from_boc(self.code) super().__init__(**kwargs)
🧰 Tools
🪛 Ruff
8-8: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
8-8: Missing type annotation for
self
in method(ANN101)
8-8: Missing type annotation for
**kwargs
(ANN003)
13-26:
⚠️ Potential issue建议添加参数验证
当前实现没有验证必需的选项是否存在。建议在方法开始时添加参数验证,以避免运行时错误。
建议添加如下验证:
def create_data_cell(self) -> Cell: + required_options = [ + "marketplace_address", + "nft_address", + "full_price", + "marketplace_fee", + "royalty_address", + "royalty_amount" + ] + for option in required_options: + if option not in self.options: + raise ValueError(f"Missing required option: {option}") + cell = Cell()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def create_data_cell(self) -> Cell: required_options = [ "marketplace_address", "nft_address", "full_price", "marketplace_fee", "royalty_address", "royalty_amount" ] for option in required_options: if option not in self.options: raise ValueError(f"Missing required option: {option}") cell = Cell() cell.bits.write_address(self.options["marketplace_address"]) cell.bits.write_address(self.options["nft_address"]) cell.bits.write_address(None) # nft_owner_address cell.bits.write_grams(self.options["full_price"]) fees_cell = Cell() fees_cell.bits.write_coins(self.options["marketplace_fee"]) fees_cell.bits.write_address(self.options["royalty_address"]) fees_cell.bits.write_coins(self.options["royalty_amount"]) cell.refs.append(fees_cell) return cell
🧰 Tools
🪛 Ruff
13-13: Missing type annotation for
self
in method(ANN101)
core/src/apps/ton/tonsdk/boc/_builder.py (9)
82-83: 🧹 Nitpick (assertive)
完善工厂函数
为
begin_cell
工厂函数添加返回类型提示:-def begin_cell(): +def begin_cell() -> Builder:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def begin_cell() -> Builder: return Builder()
🧰 Tools
🪛 Ruff
82-82: Missing return type annotation for private function
begin_cell
(ANN202)
76-80: 🧹 Nitpick (assertive)
完善单元终结方法
为
end_cell
方法添加返回类型提示:- def end_cell(self): + def end_cell(self) -> Cell:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def end_cell(self) -> Cell: cell = Cell() cell.write_cell(self) return cell
🧰 Tools
🪛 Ruff
76-76: Missing return type annotation for private function
end_cell
(ANN202)
76-76: Missing type annotation for
self
in method(ANN101)
11-13: 🧹 Nitpick (assertive)
优化 repr 方法
建议改进字符串格式化并添加类型提示:
- def __repr__(self): + def __repr__(self) -> str: - return f"<Builder refs_num: {len(self.refs)}, {repr(self.bits)}>" + return f"<Builder refs={len(self.refs)} {self.bits!r}>"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def __repr__(self) -> str: return f"<Builder refs={len(self.refs)} {self.bits!r}>"
🧰 Tools
🪛 Ruff
11-11: Missing return type annotation for special method
__repr__
Add return type annotation:
str
(ANN204)
11-11: Missing type annotation for
self
in method(ANN101)
12-12: Use explicit conversion flag
Replace with conversion flag
(RUF010)
32-39: 🧹 Nitpick (assertive)
添加位操作的类型提示
为位操作相关方法添加类型提示:
- def store_bit(self, value): + def store_bit(self, value: bool) -> "Builder": - def store_bit_array(self, value): + def store_bit_array(self, value: List[bool]) -> "Builder":📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def store_bit(self, value: bool) -> "Builder": self.bits.write_bit(value) return self def store_bit_array(self, value: List[bool]) -> "Builder": self.bits.write_bit_array(value) return self
🧰 Tools
🪛 Ruff
32-32: Missing return type annotation for private function
store_bit
(ANN202)
32-32: Missing type annotation for
self
in method(ANN101)
32-32: Missing type annotation for function argument
value
(ANN001)
36-36: Missing return type annotation for private function
store_bit_array
(ANN202)
36-36: Missing type annotation for
self
in method(ANN101)
36-36: Missing type annotation for function argument
value
(ANN001)
52-63: 🧹 Nitpick (assertive)
添加字符串和字节操作的类型提示
为字符串和字节操作方法添加适当的类型提示:
- def store_string(self, value): + def store_string(self, value: str) -> "Builder": - def store_bytes(self, value): + def store_bytes(self, value: bytes) -> "Builder": - def store_bit_string(self, value): + def store_bit_string(self, value: BitString) -> "Builder":📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def store_string(self, value: str) -> "Builder": self.bits.write_string(value) return self def store_bytes(self, value: bytes) -> "Builder": self.bits.write_bytes(value) return self def store_bit_string(self, value: BitString) -> "Builder": self.bits.write_bit_string(value) return self
🧰 Tools
🪛 Ruff
52-52: Missing return type annotation for private function
store_string
(ANN202)
52-52: Missing type annotation for
self
in method(ANN101)
52-52: Missing type annotation for function argument
value
(ANN001)
56-56: Missing return type annotation for private function
store_bytes
(ANN202)
56-56: Missing type annotation for
self
in method(ANN101)
56-56: Missing type annotation for function argument
value
(ANN001)
60-60: Missing return type annotation for private function
store_bit_string
(ANN202)
60-60: Missing type annotation for
self
in method(ANN101)
60-60: Missing type annotation for function argument
value
(ANN001)
1-10: 🧹 Nitpick (assertive)
需要添加类型提示和常量说明
建议进行以下改进:
- 为
__init__
方法添加返回类型提示-> None
- 将魔法数字 1023 定义为类常量并添加注释说明其用途
+from typing import Optional, List class Builder: + # Maximum bits allowed in a cell + MAX_BITS = 1023 + - def __init__(self): + def __init__(self) -> None: - self.bits = BitString(1023) + self.bits: BitString = BitString(self.MAX_BITS) - self.refs = [] + self.refs: List[Cell] = [] - self.is_exotic = False + self.is_exotic: bool = False📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from typing import Optional, List from ._bit_string import BitString from ._cell import Cell class Builder: # Maximum bits allowed in a cell MAX_BITS = 1023 def __init__(self) -> None: self.bits: BitString = BitString(self.MAX_BITS) self.refs: List[Cell] = [] self.is_exotic: bool = False
🧰 Tools
🪛 Ruff
1-1: The file is executable but no shebang is present
(EXE002)
6-6: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
6-6: Missing type annotation for
self
in method(ANN101)
64-75: 🛠️ Refactor suggestion
完善 TON 特定操作
建议添加 TON 特定类型的导入和类型提示:
+from .address import Address +from .coins import Coins - def store_address(self, value): + def store_address(self, value: Address) -> "Builder": - def store_grams(self, value): + def store_grams(self, value: int) -> "Builder": - def store_coins(self, value): + def store_coins(self, value: Coins) -> "Builder":Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
64-64: Missing return type annotation for private function
store_address
(ANN202)
64-64: Missing type annotation for
self
in method(ANN101)
64-64: Missing type annotation for function argument
value
(ANN001)
68-68: Missing return type annotation for private function
store_grams
(ANN202)
68-68: Missing type annotation for
self
in method(ANN101)
68-68: Missing type annotation for function argument
value
(ANN001)
72-72: Missing return type annotation for private function
store_coins
(ANN202)
72-72: Missing type annotation for
self
in method(ANN101)
72-72: Missing type annotation for function argument
value
(ANN001)
14-31: 🧹 Nitpick (assertive)
完善核心单元操作的类型提示
这些方法实现良好,但需要添加类型提示以提高代码可维护性:
- def store_cell(self, src: Cell): + def store_cell(self, src: Cell) -> "Builder": - def store_ref(self, src: Cell): + def store_ref(self, src: Cell) -> "Builder": - def store_maybe_ref(self, src): + def store_maybe_ref(self, src: Optional[Cell]) -> "Builder":📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def store_cell(self, src: Cell) -> "Builder": self.bits.write_bit_string(src.bits) self.refs += src.refs return self def store_ref(self, src: Cell) -> "Builder": self.refs.append(src) return self def store_maybe_ref(self, src: Optional[Cell]) -> "Builder": if src: self.bits.write_bit(1) self.store_ref(src) else: self.bits.write_bit(0) return self
🧰 Tools
🪛 Ruff
14-14: Missing return type annotation for private function
store_cell
(ANN202)
14-14: Missing type annotation for
self
in method(ANN101)
19-19: Missing return type annotation for private function
store_ref
(ANN202)
19-19: Missing type annotation for
self
in method(ANN101)
23-23: Missing return type annotation for private function
store_maybe_ref
(ANN202)
23-23: Missing type annotation for
self
in method(ANN101)
23-23: Missing type annotation for function argument
src
(ANN001)
40-51: 🛠️ Refactor suggestion
完善数值操作方法
建议添加类型提示和参数验证:
- def store_uint(self, value, bit_length): + def store_uint(self, value: int, bit_length: int) -> "Builder": + if bit_length <= 0: + raise ValueError("bit_length must be positive") self.bits.write_uint(value, bit_length) return self - def store_int(self, value, bit_length): + def store_int(self, value: int, bit_length: int) -> "Builder": + if bit_length <= 0: + raise ValueError("bit_length must be positive") self.bits.write_int(value, bit_length) return selfCommittable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
40-40: Missing return type annotation for private function
store_uint
(ANN202)
40-40: Missing type annotation for
self
in method(ANN101)
40-40: Missing type annotation for function argument
value
(ANN001)
40-40: Missing type annotation for function argument
bit_length
(ANN001)
44-44: Missing return type annotation for private function
store_uint8
(ANN202)
44-44: Missing type annotation for
self
in method(ANN101)
44-44: Missing type annotation for function argument
value
(ANN001)
48-48: Missing return type annotation for private function
store_int
(ANN202)
48-48: Missing type annotation for
self
in method(ANN101)
48-48: Missing type annotation for function argument
value
(ANN001)
48-48: Missing type annotation for function argument
bit_length
(ANN001)
core/src/apps/ton/layout.py (4)
69-73: 🧹 Nitpick (assertive)
建议清理注释掉的代码
如果不需要显示 wei 值的功能,建议删除相关注释代码。如果这是未来要实现的功能,建议添加 TODO 注释说明原因。
建议执行以下操作之一:
- 删除注释代码
- 添加说明性的 TODO 注释
54-54: 🛠️ Refactor suggestion
建议使用国际化字符串
当前代码中 "Ton" 是硬编码的字符串,应该使用国际化键值来支持多语言。
建议修改为:
- title=_(i18n_keys.TITLE__STR_TRANSACTION).format("Ton"), + title=_(i18n_keys.TITLE__STR_TRANSACTION).format(_(i18n_keys.CURRENCY__TON)),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.title=_(i18n_keys.TITLE__STR_TRANSACTION).format(_(i18n_keys.CURRENCY__TON)),
84-84: 🧹 Nitpick (assertive)
建议将图片路径定义为常量
硬编码的图片路径应该定义为模块级常量,以便于维护和重用。
建议在文件顶部添加:
+WARNING_ICON_PATH = "A:/res/shriek.png"
然后修改使用处:
- icon="A:/res/shriek.png", + icon=WARNING_ICON_PATH,Committable suggestion skipped: line range outside the PR's diff.
17-42: 🧹 Nitpick (assertive)
建议改进布尔参数的使用方式
is_raw_data
参数使用布尔值作为位置参数可能会导致代码可读性降低。建议使用枚举类型或具名参数来提高代码的清晰度。建议按以下方式重构:
+from enum import Enum, auto + +class DataType(Enum): + NORMAL = auto() + RAW = auto() def require_confirm_fee( ctx: Context, from_address: str | None = None, to_address: str | None = None, value: int = 0, gas_price: int = 0, gas_limit: int = 0, token: tokens.TokenInfo | None = None, raw_data: bytes | None = None, - is_raw_data: bool = False, + data_type: DataType = DataType.NORMAL, ) -> Awaitable[None]:Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
26-26: Boolean-typed positional argument in function definition
(FBT001)
26-26: Boolean default positional argument in function definition
(FBT002)
core/embed/firmware/memory_H.ld (1)
55-55: 🧹 Nitpick (assertive)
建议:考虑字体文件的必要性
新增的48号粗体字体似乎是为TON功能添加的。建议:
- 确认是否可以复用现有的36号字体
- 评估是否所有TON相关界面都需要使用48号字体
core/src/apps/ton/tonsdk/contract/token/ft/jetton_wallet.py (4)
14-36: 🛠️ Refactor suggestion
建议改进代码结构和类型安全性
- 操作码应该定义为类常量
- 需要添加参数验证
- 使用 Optional 类型注解
+from typing import Optional + class JettonWallet(Contract): + # 操作码常量 + OP_TRANSFER = 0xF8A7EA5 + def create_transfer_body( self, to_address: Address, jetton_amount: int, forward_amount: int = 0, - forward_payload: str = None, - response_address: Address = None, + forward_payload: Optional[str] = None, + response_address: Optional[Address] = None, query_id: int = 0, ) -> Cell: + """创建Jetton转账请求。 + + Args: + to_address: 接收方地址 + jetton_amount: Jetton数量 + forward_amount: 转发金额 + forward_payload: 转发载荷 + response_address: 响应地址 + query_id: 查询ID + + Returns: + Cell: 包含转账请求的cell对象 + + Raises: + ValueError: 当参数无效时抛出 + """ + if jetton_amount <= 0: + raise ValueError("Jetton数量必须大于0") + cell = Cell() - cell.bits.write_uint(0xF8A7EA5, 32) # request_transfer op + cell.bits.write_uint(self.OP_TRANSFER, 32)Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
15-15: Missing type annotation for
self
in method(ANN101)
19-19: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
9-12: 🧹 Nitpick (assertive)
需要添加类型注解和方法文档
构造函数缺少类型注解和文档字符串。添加这些将提高代码的可维护性。
- def __init__(self, **kwargs): + def __init__(self, **kwargs: Any) -> None: + """初始化Jetton钱包合约。 + + Args: + **kwargs: 合约参数,可以包含自定义的code参数来覆盖默认合约代码 + """ self.code = kwargs.get("code") or self.code kwargs["code"] = Cell.one_from_boc(self.code) super().__init__(**kwargs)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def __init__(self, **kwargs: Any) -> None: """初始化Jetton钱包合约。 Args: **kwargs: 合约参数,可以包含自定义的code参数来覆盖默认合约代码 """ self.code = kwargs.get("code") or self.code kwargs["code"] = Cell.one_from_boc(self.code) super().__init__(**kwargs)
🧰 Tools
🪛 Ruff
9-9: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
9-9: Missing type annotation for
self
in method(ANN101)
9-9: Missing type annotation for
**kwargs
(ANN003)
38-46: 🛠️ Refactor suggestion
需要与transfer方法保持一致的改进
建议对burn方法进行类似的改进,包括常量定义、参数验证和文档。
class JettonWallet(Contract): + OP_BURN = 0x595F07BC + def create_burn_body( self, jetton_amount: int, - response_address: Address = None, - query_id: int = 0 + response_address: Optional[Address] = None, + query_id: int = 0, ) -> Cell: + """创建Jetton销毁请求。 + + Args: + jetton_amount: 要销毁的Jetton数量 + response_address: 响应地址 + query_id: 查询ID + + Returns: + Cell: 包含销毁请求的cell对象 + + Raises: + ValueError: 当参数无效时抛出 + """ + if jetton_amount <= 0: + raise ValueError("销毁数量必须大于0") + cell = Cell() - cell.bits.write_uint(0x595F07BC, 32) # burn OP + cell.bits.write_uint(self.OP_BURN, 32)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.OP_BURN = 0x595F07BC def create_burn_body( self, jetton_amount: int, response_address: Optional[Address] = None, query_id: int = 0, ) -> Cell: """创建Jetton销毁请求。 Args: jetton_amount: 要销毁的Jetton数量 response_address: 响应地址 query_id: 查询ID Returns: Cell: 包含销毁请求的cell对象 Raises: ValueError: 当参数无效时抛出 """ if jetton_amount <= 0: raise ValueError("销毁数量必须大于0") cell = Cell() cell.bits.write_uint(self.OP_BURN, 32) cell.bits.write_uint(query_id, 64) cell.bits.write_grams(jetton_amount) cell.bits.write_address(response_address) return cell
🧰 Tools
🪛 Ruff
39-39: Missing type annotation for
self
in method(ANN101)
39-39: Trailing comma missing
Add trailing comma
(COM812)
6-7: 🧹 Nitpick (assertive)
需要为合约代码添加文档注释
建议为
code
常量添加文档字符串,说明此合约代码的用途和来源。这将帮助其他开发者理解代码的功能。class JettonWallet(Contract): + """TON Jetton钱包合约实现。 + + code: 合约的字节码,用于在区块链上部署和执行Jetton钱包功能。 + """ code = "B5EE9C7241021201000328000114FF00F4A413F4BCF2C80B..."📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.class JettonWallet(Contract): """TON Jetton钱包合约实现。 code: 合约的字节码,用于在区块链上部署和执行Jetton钱包功能。 """ code = "B5EE9C7241021201000328000114FF00F4A413F4BCF2C80B0102016202030202CC0405001BA0F605DA89A1F401F481F481A8610201D40607020148080900BB0831C02497C138007434C0C05C6C2544D7C0FC02F83E903E900C7E800C5C75C87E800C7E800C00B4C7E08403E29FA954882EA54C4D167C0238208405E3514654882EA58C511100FC02780D60841657C1EF2EA4D67C02B817C12103FCBC2000113E910C1C2EBCB853600201200A0B020120101101F500F4CFFE803E90087C007B51343E803E903E90350C144DA8548AB1C17CB8B04A30BFFCB8B0950D109C150804D50500F214013E809633C58073C5B33248B232C044BD003D0032C032483E401C1D3232C0B281F2FFF274013E903D010C7E801DE0063232C1540233C59C3E8085F2DAC4F3208405E351467232C7C6600C03F73B51343E803E903E90350C0234CFFE80145468017E903E9014D6F1C1551CDB5C150804D50500F214013E809633C58073C5B33248B232C044BD003D0032C0327E401C1D3232C0B281F2FFF274140371C1472C7CB8B0C2BE80146A2860822625A020822625A004AD822860822625A028062849F8C3C975C2C070C008E00D0E0F009ACB3F5007FA0222CF165006CF1625FA025003CF16C95005CC2391729171E25008A813A08208989680AA008208989680A0A014BCF2E2C504C98040FB001023C85004FA0258CF1601CF16CCC9ED5400705279A018A182107362D09CC8CB1F5230CB3F58FA025007CF165007CF16C9718018C8CB0524CF165006FA0215CB6A14CCC971FB0010241023000E10491038375F040076C200B08E218210D53276DB708010C8CB055008CF165004FA0216CB6A12CB1F12CB3FC972FB0093356C21E203C85004FA0258CF1601CF16CCC9ED5400DB3B51343E803E903E90350C01F4CFFE803E900C145468549271C17CB8B049F0BFFCB8B0A0822625A02A8005A805AF3CB8B0E0841EF765F7B232C7C572CFD400FE8088B3C58073C5B25C60063232C14933C59C3E80B2DAB33260103EC01004F214013E809633C58073C5B3327B55200083200835C87B51343E803E903E90350C0134C7E08405E3514654882EA0841EF765F784EE84AC7CB8B174CFCC7E800C04E81408F214013E809633C58073C5B3327B55205ECCF23D"
core/src/trezor/strings.py (1)
101-108: 🛠️ Refactor suggestion
建议优化错误处理逻辑
当前实现存在以下问题:
- 直接在异常处理中导入
binascii
模块不是最佳实践- 抽象的
raise UnicodeError
语句应该提供更具体的错误信息建议按如下方式修改:
+from binascii import hexlify + def format_customer_data(data: bytes | None) -> str: """ Returns human-friendly representation of a customer data. """ if data is None or len(data) == 0: return "" try: formatted = data.decode() if all((c <= 0x20 or c == 0x7F) for c in data[:33]): - raise UnicodeError # non-printable characters + raise UnicodeError("First 33 bytes contain only non-printable characters") except UnicodeError: # mp has no UnicodeDecodeError - from binascii import hexlify - formatted = f"0x{hexlify(data).decode()}" return formatted📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.try: formatted = data.decode() if all((c <= 0x20 or c == 0x7F) for c in data[:33]): raise UnicodeError("First 33 bytes contain only non-printable characters") except UnicodeError: # mp has no UnicodeDecodeError formatted = f"0x{hexlify(data).decode()}"
🧰 Tools
🪛 Ruff
104-104: Abstract
raise
to an inner function(TRY301)
core/src/trezor/ui/layouts/lvgl/altcoin.py (1)
165-178: 🛠️ Refactor suggestion
建议优化函数参数设计
存在以下问题:
is_raw_data
参数未被使用- 布尔类型参数
is_raw_data
作为位置参数可能导致调用时的混淆建议应用以下修改:
async def confirm_total_ton( ctx: wire.GenericContext, amount: str, gas_price: str | None, fee_max: str, from_address: str | None, to_address: str | None, total_amount: str | None, contract_addr: str | None = None, token_id: int | None = None, evm_chain_id: int | None = None, - raw_data: bytes | None = None, - is_raw_data: bool = False, + raw_data: bytes | None = None ) -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.async def confirm_total_ton( ctx: wire.GenericContext, amount: str, gas_price: str | None, fee_max: str, from_address: str | None, to_address: str | None, total_amount: str | None, contract_addr: str | None = None, token_id: int | None = None, evm_chain_id: int | None = None, raw_data: bytes | None = None ) -> None:
🧰 Tools
🪛 Ruff
177-177: Boolean-typed positional argument in function definition
(FBT001)
177-177: Boolean default positional argument in function definition
(FBT002)
177-177: Unused function argument:
is_raw_data
(ARG001)
core/src/trezor/enums/MessageType.py (1)
360-365: 🧹 Nitpick (assertive)
建议添加注释说明消息类型用途
为了提高代码可维护性,建议为每个TON相关的消息类型添加简短注释,说明其具体用途。
示例添加方式:
+ # Get TON address for given path TonGetAddress = 11901 + # Response with TON address TonAddress = 11902 + # Sign TON message TonSignMessage = 11903 + # Response with signed TON message TonSignedMessage = 11904 + # Sign TON proof TonSignProof = 11905 + # Response with signed TON proof TonSignedProof = 11906📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.# Get TON address for given path TonGetAddress = 11901 # Response with TON address TonAddress = 11902 # Sign TON message TonSignMessage = 11903 # Response with signed TON message TonSignedMessage = 11904 # Sign TON proof TonSignProof = 11905 # Response with signed TON proof TonSignedProof = 11906
core/src/trezor/enums/__init__.py (1)
696-702: 🧹 Nitpick (assertive)
建议为枚举类添加文档注释
TonWalletVersion
和TonWorkChain
的实现逻辑正确,但建议添加类级别的文档注释来说明:
- V4R2版本号为什么是3
- BASECHAIN和MASTERCHAIN的具体用途
建议添加如下文档注释:
+ """TON wallet version enum. + + V4R2: Version 4 Release 2 of the TON wallet contract + """ class TonWalletVersion(IntEnum): V4R2 = 3 + """TON blockchain work chain identifiers. + + BASECHAIN: The main TON blockchain (workchain_id = 0) + MASTERCHAIN: The master chain of TON (workchain_id = 1) + """ class TonWorkChain(IntEnum): BASECHAIN = 0 MASTERCHAIN = 1📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements."""TON wallet version enum. V4R2: Version 4 Release 2 of the TON wallet contract """ class TonWalletVersion(IntEnum): V4R2 = 3 """TON blockchain work chain identifiers. BASECHAIN: The main TON blockchain (workchain_id = 0) MASTERCHAIN: The master chain of TON (workchain_id = 1) """ class TonWorkChain(IntEnum): BASECHAIN = 0 MASTERCHAIN = 1
common/protob/messages.proto (1)
524-529: 🧹 Nitpick (assertive)
建议添加消息类型的注释说明
为了提高代码可读性和维护性,建议为每个 TON 相关的消息类型添加简要说明。
示例:
+ // Get TON address for given path MessageType_TonGetAddress = 11901 [(wire_in) = true]; + // Response with TON address MessageType_TonAddress = 11902 [(wire_out) = true]; + // Sign TON message MessageType_TonSignMessage = 11903 [(wire_in) = true];Committable suggestion skipped: line range outside the PR's diff.
core/src/all_modules.py (1)
798-849: 🧹 Nitpick (assertive)
SDK模块结构完整!
TON SDK模块划分合理,包含了:
- BOC(Bag of Cells)处理
- 合约管理(钱包、代币等)
- 工具函数
建议:考虑添加SDK版本注释,便于后续升级维护。
core/SConscript.firmware (1)
916-920: 🧹 Nitpick (assertive)
建议优化 Glob 模式的深度
当前的 Glob 模式支持最多 5 层目录深度。考虑到其他区块链实现通常只使用 2-3 层目录结构,建议减少不必要的 Glob 模式以提高构建性能。
- SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ton/*.py')) - SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ton/*/*.py')) - SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ton/*/*/*.py')) - SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ton/*/*/*/*.py')) - SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ton/*/*/*/*/*.py')) + SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ton/**/*.py'))📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/ton/**/*.py'))
core/src/trezor/ui/layouts/lvgl/__init__.py (3)
971-1002: 🧹 Nitpick (assertive)
代码结构良好,但需要一些改进
建议进行以下优化:
- 添加返回类型注解
- 在 interact 调用中添加尾随逗号
-async def confirm_ton_signverify( +async def confirm_ton_signverify( + ctx: wire.GenericContext, + coin: str, + message: str, + address: str, + domain: str, + verify: bool, +) -> None: # 在第1001行 ButtonRequestType.Other, - ) + ),Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
977-977: Boolean-typed positional argument in function definition
(FBT001)
1001-1001: Trailing comma missing
Add trailing comma
(COM812)
1905-1918: 🧹 Nitpick (assertive)
函数实现正确,建议添加返回类型注解
-def confirm_unknown_token_transfer( +def confirm_unknown_token_transfer( ctx: wire.GenericContext, address: str, -): +) -> Awaitable[None]:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def confirm_unknown_token_transfer( ctx: wire.GenericContext, address: str, ) -> Awaitable[None]: return confirm_address( ctx, _(i18n_keys.TITLE__UNKNOWN_TOKEN), address, description=_(i18n_keys.LIST_KEY__CONTRACT_ADDRESS__COLON), br_type="unknown_token", icon="A:/res/warning.png", icon_color=ui.ORANGE, br_code=ButtonRequestType.SignTx, )
🧰 Tools
🪛 Ruff
1905-1905: Missing return type annotation for public function
confirm_unknown_token_transfer
(ANN201)
2073-2086: 🧹 Nitpick (assertive)
函数实现完整,但需要一些改进
建议进行以下优化:
- 添加返回类型注解
- 在 interact 调用中添加尾随逗号
-async def confirm_ton_transfer( +async def confirm_ton_transfer( ctx: wire.GenericContext, from_addr: str, to_addr: str, amount: str, memo: str | None, -): +) -> None: # 在第2085行 interact(ctx, screen, "confirm_ton_transfer", ButtonRequestType.ProtectCall) - ) + ),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.async def confirm_ton_transfer( ctx: wire.GenericContext, from_addr: str, to_addr: str, amount: str, memo: str | None, ) -> None: from trezor.lvglui.scrs.template import TonTransfer screen = TonTransfer(from_addr, to_addr, amount, memo, ctx.primary_color) await raise_if_cancelled( interact(ctx, screen, "confirm_ton_transfer", ButtonRequestType.ProtectCall), )
🧰 Tools
🪛 Ruff
2073-2073: Missing return type annotation for public function
confirm_ton_transfer
Add return type annotation:
None
(ANN201)
2085-2085: Trailing comma missing
Add trailing comma
(COM812)
core/src/trezor/lvglui/scrs/template.py (3)
923-1070: 🛠️ Refactor suggestion
需要清理未使用的参数和注释代码
- 多个参数未被使用,建议移除
- 存在已注释的代码块,建议清理
- 缺少类型注解
建议按如下方式修改:
- def __init__( - self, - title, - address_from, - address_to, - amount, - fee_max, - is_eip1559=False, - gas_price=None, - max_priority_fee_per_gas=None, - max_fee_per_gas=None, - total_amount=None, - primary_color=lv_colors.ONEKEY_GREEN, - contract_addr=None, - token_id=None, - evm_chain_id=None, - raw_data=None, - is_raw_data=False, - sub_icon_path=None, - striped=False, - ): + def __init__( + self, + title: str, + address_from: str, + address_to: str, + amount: str, + raw_data: str | None = None, + contract_addr: str | None = None, + token_id: str | None = None, + primary_color: int = lv_colors.ONEKEY_GREEN, + ) -> None:移除这些注释掉的代码:
- # if total_amount is None: - # if not contract_addr: # token transfer - # total_amount = f"{amount}\n{fee_max}" - # else: # nft transfer - # total_amount = f"{fee_max}" - # self.item6 = DisplayItemNoBgc( - # self.container, - # _(i18n_keys.LIST_KEY__TOTAL_AMOUNT__COLON), - # total_amount, - # )Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
924-924: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
925-925: Missing type annotation for
self
in method(ANN101)
926-926: Missing type annotation for function argument
title
(ANN001)
927-927: Missing type annotation for function argument
address_from
(ANN001)
928-928: Missing type annotation for function argument
address_to
(ANN001)
929-929: Missing type annotation for function argument
amount
(ANN001)
930-930: Missing type annotation for function argument
fee_max
(ANN001)
930-930: Unused method argument:
fee_max
(ARG002)
931-931: Boolean default positional argument in function definition
(FBT002)
931-931: Missing type annotation for function argument
is_eip1559
(ANN001)
931-931: Unused method argument:
is_eip1559
(ARG002)
932-932: Missing type annotation for function argument
gas_price
(ANN001)
932-932: Unused method argument:
gas_price
(ARG002)
933-933: Missing type annotation for function argument
max_priority_fee_per_gas
(ANN001)
933-933: Unused method argument:
max_priority_fee_per_gas
(ARG002)
934-934: Missing type annotation for function argument
max_fee_per_gas
(ANN001)
934-934: Unused method argument:
max_fee_per_gas
(ARG002)
935-935: Missing type annotation for function argument
total_amount
(ANN001)
935-935: Unused method argument:
total_amount
(ARG002)
936-936: Missing type annotation for function argument
primary_color
(ANN001)
937-937: Missing type annotation for function argument
contract_addr
(ANN001)
938-938: Missing type annotation for function argument
token_id
(ANN001)
939-939: Missing type annotation for function argument
evm_chain_id
(ANN001)
939-939: Unused method argument:
evm_chain_id
(ARG002)
940-940: Missing type annotation for function argument
raw_data
(ANN001)
941-941: Boolean default positional argument in function definition
(FBT002)
941-941: Missing type annotation for function argument
is_raw_data
(ANN001)
941-941: Unused method argument:
is_raw_data
(ARG002)
942-942: Missing type annotation for function argument
sub_icon_path
(ANN001)
942-942: Unused method argument:
sub_icon_path
(ARG002)
943-943: Boolean default positional argument in function definition
(FBT002)
943-943: Missing type annotation for function argument
striped
(ANN001)
943-943: Unused method argument:
striped
(ARG002)
1056-1056: Missing return type annotation for public function
on_click
Add return type annotation:
None
(ANN201)
1056-1056: Missing type annotation for
self
in method(ANN101)
1056-1056: Missing type annotation for function argument
event_obj
(ANN001)
1059-1060: Use a single
if
statement instead of nestedif
statementsCombine
if
statements usingand
(SIM102)
2279-2308: 🧹 Nitpick (assertive)
实现清晰,建议添加类型注解
代码结构良好,但建议添加类型注解以提高可维护性。
建议按如下方式修改:
- def __init__( - self, - address_from, - address_to, - amount, - memo, - primary_color=None, - ): + def __init__( + self, + address_from: str, + address_to: str, + amount: str, + memo: str | None, + primary_color: int | None = None, + ) -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.class TonTransfer(FullSizeWindow): def __init__( self, address_from: str, address_to: str, amount: str, memo: str | None, primary_color: int | None = None, ) -> None: super().__init__( _(i18n_keys.TITLE__SIGN_STR_TRANSACTION).format("TON"), None, _(i18n_keys.BUTTON__CONTINUE), _(i18n_keys.BUTTON__REJECT), primary_color=primary_color, ) self.container = ContainerFlexCol(self.content_area, self.title, pos=(0, 40)) self.item1 = DisplayItemNoBgc( self.container, _(i18n_keys.LIST_KEY__AMOUNT__COLON), amount ) self.item2 = DisplayItemNoBgc( self.container, _(i18n_keys.LIST_KEY__TO__COLON), address_to ) self.item3 = DisplayItemNoBgc( self.container, _(i18n_keys.LIST_KEY__FROM__COLON), address_from ) if memo: self.item4 = DisplayItemNoBgc( self.container, _(i18n_keys.LIST_KEY__MEMO__COLON), memo )
🧰 Tools
🪛 Ruff
2280-2280: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
2281-2281: Missing type annotation for
self
in method(ANN101)
2282-2282: Missing type annotation for function argument
address_from
(ANN001)
2283-2283: Missing type annotation for function argument
address_to
(ANN001)
2284-2284: Missing type annotation for function argument
amount
(ANN001)
2285-2285: Missing type annotation for function argument
memo
(ANN001)
2286-2286: Missing type annotation for function argument
primary_color
(ANN001)
2297-2297: Trailing comma missing
Add trailing comma
(COM812)
2300-2300: Trailing comma missing
Add trailing comma
(COM812)
2303-2303: Trailing comma missing
Add trailing comma
(COM812)
2307-2307: Trailing comma missing
Add trailing comma
(COM812)
853-921: 🧹 Nitpick (assertive)
代码结构清晰,但需要添加类型注解
建议添加类型注解以提高代码可维护性。另外,建议移除已注释的代码。
建议按如下方式修改:
-def __init__( +def __init__( + self, + title: str, + address: str, + message: str, + domain: str | None, + primary_color: int, + icon_path: str, + verify: bool = False, +) -> None: -def eventhandler(self, event_obj): +def eventhandler(self, event_obj: lv.event_t) -> None:另外移除这些注释掉的代码:
- # self.show_full_message = NormalButton( - # self, _(i18n_keys.BUTTON__VIEW_FULL_MESSAGE) - # ) - # self.show_full_message.align_to(self.item2, lv.ALIGN.OUT_BOTTOM_MID, 0, 32) - # self.show_full_message.add_event_cb(self.on_click, lv.EVENT.CLICKED, None)Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
854-854: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
855-855: Missing type annotation for
self
in method(ANN101)
856-856: Missing type annotation for function argument
title
(ANN001)
857-857: Missing type annotation for function argument
address
(ANN001)
858-858: Missing type annotation for function argument
message
(ANN001)
859-859: Missing type annotation for function argument
domain
(ANN001)
860-860: Missing type annotation for function argument
primary_color
(ANN001)
861-861: Missing type annotation for function argument
icon_path
(ANN001)
862-862: Boolean-typed positional argument in function definition
(FBT001)
862-862: Boolean default positional argument in function definition
(FBT002)
875-875: Trailing comma missing
Add trailing comma
(COM812)
884-884: Trailing comma missing
Add trailing comma
(COM812)
898-898: Trailing comma missing
Add trailing comma
(COM812)
901-901: Missing return type annotation for public function
eventhandler
Add return type annotation:
None
(ANN201)
901-901: Missing type annotation for
self
in method(ANN101)
901-901: Missing type annotation for function argument
event_obj
(ANN001)
python/src/trezorlib/messages.py (5)
10292-10307: 🧹 Nitpick (assertive)
需要改进类型注解
类结构简单清晰,但同样需要改进类型注解:
- 使用
typing.ClassVar
注解FIELDS
- 为
__init__
添加self
类型注解🧰 Tools
🪛 Ruff
10294-10297: Mutable class attributes should be annotated with
typing.ClassVar
(RUF012)
10300-10300: Missing type annotation for
self
in method(ANN101)
10309-10384: 🧹 Nitpick (assertive)
建议重构以提高可维护性
该类功能完整但过于复杂:
- 参数列表过长,建议拆分成多个专门的消息类型
- 需要改进类型注解
建议考虑:
- 将 Jetton 相关字段拆分到单独的消息类型
- 创建共享的基础消息类型
- 使用
typing.ClassVar
注解FIELDS
- 为
__init__
添加self
类型注解示例重构方向:
class TonBaseMessage(protobuf.MessageType): # 基础字段... class TonTokenTransfer(TonBaseMessage): # Token 相关字段... class TonSignMessage(TonBaseMessage): # TON 特定字段...🧰 Tools
🪛 Ruff
10311-10334: Mutable class attributes should be annotated with
typing.ClassVar
(RUF012)
10337-10337: Missing type annotation for
self
in method(ANN101)
10362-10362: Remove quotes from type annotation
Remove quotes
(UP037)
10363-10363: Remove quotes from type annotation
Remove quotes
(UP037)
10364-10364: Remove quotes from type annotation
Remove quotes
(UP037)
10365-10365: Remove quotes from type annotation
Remove quotes
(UP037)
10403-10439: 🧹 Nitpick (assertive)
结构良好,建议改进类型注解
类的设计和字段组织合理,仅需改进类型注解:
- 使用
typing.ClassVar
注解FIELDS
- 为
__init__
添加self
类型注解🧰 Tools
🪛 Ruff
10405-10415: Mutable class attributes should be annotated with
typing.ClassVar
(RUF012)
10418-10418: Missing type annotation for
self
in method(ANN101)
10430-10430: Remove quotes from type annotation
Remove quotes
(UP037)
10386-10401:
⚠️ Potential issue需要修复字段名拼写错误
字段 "signning_message" 拼写错误,应为 "signing_message"。
FIELDS = { - 2: protobuf.Field("signning_message", "bytes", repeated=False, required=False), + 2: protobuf.Field("signing_message", "bytes", repeated=False, required=False), }Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
10388-10391: Mutable class attributes should be annotated with
typing.ClassVar
(RUF012)
10394-10394: Missing type annotation for
self
in method(ANN101)
10260-10290: 🧹 Nitpick (assertive)
建议改进类型注解
类的整体结构良好,但有以下建议:
- 建议使用
typing.ClassVar
注解FIELDS
类属性- 为
__init__
方法的self
参数添加类型注解建议按如下方式修改:
+ from typing import ClassVar class TonGetAddress(protobuf.MessageType): MESSAGE_WIRE_TYPE = 11901 - FIELDS = { + FIELDS: ClassVar[dict] = { # ... } - def __init__( + def __init__( + self: "TonGetAddress", *, address_n: Optional[Sequence[int]] = None, # ... ) -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from typing import ClassVar class TonGetAddress(protobuf.MessageType): MESSAGE_WIRE_TYPE = 11901 FIELDS: ClassVar[dict] = { 1: protobuf.Field("address_n", "uint32", repeated=True, required=False), 2: protobuf.Field("show_display", "bool", repeated=False, required=False), 3: protobuf.Field("wallet_version", "TonWalletVersion", repeated=False, required=False), 4: protobuf.Field("is_bounceable", "bool", repeated=False, required=False), 5: protobuf.Field("is_testnet_only", "bool", repeated=False, required=False), 6: protobuf.Field("workchain", "TonWorkChain", repeated=False, required=False), 7: protobuf.Field("wallet_id", "uint32", repeated=False, required=False), } def __init__( self: "TonGetAddress", *, address_n: Optional[Sequence["int"]] = None, show_display: Optional["bool"] = None, wallet_version: Optional["TonWalletVersion"] = TonWalletVersion.V4R2, is_bounceable: Optional["bool"] = False, is_testnet_only: Optional["bool"] = False, workchain: Optional["TonWorkChain"] = TonWorkChain.BASECHAIN, wallet_id: Optional["int"] = 698983191, ) -> None: self.address_n: Sequence["int"] = address_n if address_n is not None else [] self.show_display = show_display self.wallet_version = wallet_version self.is_bounceable = is_bounceable self.is_testnet_only = is_testnet_only self.workchain = workchain self.wallet_id = wallet_id
🧰 Tools
🪛 Ruff
10262-10270: Mutable class attributes should be annotated with
typing.ClassVar
(RUF012)
10273-10273: Missing type annotation for
self
in method(ANN101)
10283-10283: Remove quotes from type annotation
Remove quotes
(UP037)
core/src/apps/ton/get_address.py (2)
21-21: 🧹 Nitpick (assertive)
建议在参数列表末尾添加逗号。
在参数列表的最后一个参数后添加一个逗号,有助于在以后添加新参数时减少代码改动。
- ctx: Context, msg: TonGetAddress, keychain: Keychain + ctx: Context, msg: TonGetAddress, keychain: Keychain,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.ctx: Context, msg: TonGetAddress, keychain: Keychain,
🧰 Tools
🪛 Ruff
21-21: Trailing comma missing
Add trailing comma
(COM812)
37-37: 🧹 Nitpick (assertive)
建议在参数列表末尾添加逗号。
在参数列表的最后一个参数后添加一个逗号,有助于在以后添加新参数时减少代码改动。
- public_key=public_key, wallet_id=msg.wallet_id, wc=workchain + public_key=public_key, wallet_id=msg.wallet_id, wc=workchain,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.public_key=public_key, wallet_id=msg.wallet_id, wc=workchain,
🧰 Tools
🪛 Ruff
37-37: Trailing comma missing
Add trailing comma
(COM812)
core/src/apps/ton/tonsdk/contract/wallet/_wallet_contract_v3.py (4)
6-6: 🛠️ Refactor suggestion
建议添加类型注解
方法
create_data_cell
缺少返回类型注解,添加类型注解有助于提高代码的可读性和可维护性。可以这样修改:
-def create_data_cell(self): +def create_data_cell(self) -> Cell:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def create_data_cell(self) -> Cell:
🧰 Tools
🪛 Ruff
6-6: Missing return type annotation for private function
create_data_cell
(ANN202)
6-6: Missing type annotation for
self
in method(ANN101)
28-28: 🧹 Nitpick (assertive)
完善构造函数的类型注解
__init__
方法的参数缺少类型注解,建议为**kwargs
添加类型注解。可以这样修改:
-def __init__(self, **kwargs) -> None: +def __init__(self, **kwargs: Any) -> None:注意:需要导入
from typing import Any
。Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
28-28: Missing type annotation for
self
in method(ANN101)
28-28: Missing type annotation for
**kwargs
(ANN003)
37-37: 🧹 Nitpick (assertive)
完善构造函数的类型注解
同样地,为
WalletV3ContractR2
的__init__
方法添加参数类型注解。可以这样修改:
-def __init__(self, **kwargs) -> None: +def __init__(self, **kwargs: Any) -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def __init__(self, **kwargs: Any) -> None:
🧰 Tools
🪛 Ruff
37-37: Missing type annotation for
self
in method(ANN101)
37-37: Missing type annotation for
**kwargs
(ANN003)
13-13: 🛠️ Refactor suggestion
补充方法的类型注解
方法
create_signing_message
缺少参数和返回类型注解,建议添加。可以这样修改:
-def create_signing_message(self, expiration_time, seqno=None): +def create_signing_message(self, expiration_time: int, seqno: Optional[int] = None) -> Cell:注意:需要导入
from typing import Optional
。Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
13-13: Missing return type annotation for private function
create_signing_message
(ANN202)
13-13: Missing type annotation for
self
in method(ANN101)
13-13: Missing type annotation for function argument
expiration_time
(ANN001)
13-13: Missing type annotation for function argument
seqno
(ANN001)
core/src/apps/ton/sign_proof.py (3)
38-38: 🧹 Nitpick (assertive)
建议在多行参数列表中添加尾随逗号
在多行参数中,建议在最后一个参数后添加逗号,以提高代码的可维护性和一致性。
public_key=public_key, wallet_id=msg.wallet_id, wc=workchain, )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.public_key=public_key, wallet_id=msg.wallet_id, wc=workchain,
🧰 Tools
🪛 Ruff
38-38: Trailing comma missing
Add trailing comma
(COM812)
65-73:
⚠️ Potential issue在构建消息时,应检查
msg.comment
是否为 None直接使用
msg.comment
可能会在其为 None 时引发错误。建议在使用前检查,确保安全。+ msg.expire_at.to_bytes(8, "little") - + msg.comment + + (msg.comment if msg.comment else b'')📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.message = ( ton_proof_prefix.encode("utf-8") + workchain.to_bytes(4, "big") + wallet.address.get_hash_part() + len(msg.appdomain).to_bytes(4, "little") + msg.appdomain + msg.expire_at.to_bytes(8, "little") + (msg.comment if msg.comment else b'') )
22-22: 🧹 Nitpick (assertive)
建议在多行参数列表中添加尾随逗号
在多行参数列表中,最后一个参数后添加逗号可以提高代码可读性,方便后续添加新参数。
async def sign_proof( ctx: Context, msg: TonSignProof, keychain: Keychain, ) -> TonSignedProof:Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
22-22: Trailing comma missing
Add trailing comma
(COM812)
core/src/apps/ton/tonsdk/contract/token/nft/nft_item.py (3)
37-37: 🧹 Nitpick (assertive)
在函数调用中使用关键字参数以提升可读性
直接传递布尔值
False
作为位置参数可能降低代码的可读性。建议在调用cell.bits.write_bit
时使用关键字参数,使代码更加明确。建议修改如下:
-cell.bits.write_bit(False) # null custom_payload +cell.bits.write_bit(value=False) # null custom_payload -cell.bits.write_bit(False) # forward_payload in this slice, not separate cell +cell.bits.write_bit(value=False) # forward_payload in this slice, not separate cellAlso applies to: 39-39
🧰 Tools
🪛 Ruff
37-37: Boolean positional value in function call
(FBT003)
9-9: 🧹 Nitpick (assertive)
请为
__init__
方法添加返回类型注解
__init__
方法缺少返回类型注解。根据PEP 484,应添加-> None
来明确返回类型。建议修改如下:
-def __init__(self, **kwargs): +def __init__(self, **kwargs) -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def __init__(self, **kwargs) -> None:
🧰 Tools
🪛 Ruff
9-9: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
9-9: Missing type annotation for
self
in method(ANN101)
9-9: Missing type annotation for
**kwargs
(ANN003)
29-29: 🛠️ Refactor suggestion
修正类型注解以避免隐式的
Optional
参数
forward_payload
的默认值为None
,但类型注解为bytes
。根据PEP 484,应使用Optional[bytes]
来显式表示可接受None
。建议修改如下:
- forward_payload: bytes = None, + forward_payload: Optional[bytes] = None,并在文件开头添加:
+from typing import Optional
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
29-29: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
core/src/apps/ton/tonsdk/contract/token/ft/jetton_minter.py (5)
43-45: 🧹 Nitpick (assertive)
建议:在参数后添加逗号以符合代码规范
在多行函数调用中,最后一个参数后建议添加逗号,符合代码风格规范。
transfer_body.bits.write_bit( 0 + , ) # forward_payload in this slice, not separate cell
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.transfer_body.bits.write_bit( 0, ) # forward_payload in this slice, not separate cell
🧰 Tools
🪛 Ruff
44-44: Trailing comma missing
Add trailing comma
(COM812)
51-52: 🧹 Nitpick (assertive)
建议:在多行参数列表的最后一项后添加逗号
在方法
create_change_admin_body
的参数列表中,最后一个参数后添加逗号,符合代码风格规范。def create_change_admin_body( self, new_admin_address: Address, query_id: int = 0 + , ) -> Cell:
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
51-51: Missing type annotation for
self
in method(ANN101)
51-51: Trailing comma missing
Add trailing comma
(COM812)
60-61: 🧹 Nitpick (assertive)
建议:在多行参数列表的最后一项后添加逗号
在方法
create_edit_content_body
的参数列表中,最后一个参数后添加逗号,符合代码风格规范。def create_edit_content_body( self, jetton_content_uri: str, query_id: int = 0 + , ) -> Cell:
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
60-60: Missing type annotation for
self
in method(ANN101)
60-60: Trailing comma missing
Add trailing comma
(COM812)
15-15: 🧹 Nitpick (assertive)
建议:为方法添加类型注解,以提高代码可读性
方法
create_data_cell
缺少对self
的类型注解。添加类型注解有助于代码的维护和理解。- def create_data_cell(self) -> Cell: + def create_data_cell(self) -> Cell:Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
15-15: Missing type annotation for
self
in method(ANN101)
10-13: 🧹 Nitpick (assertive)
建议:为
__init__
方法添加返回类型注解缺少返回类型注解
None
。添加返回类型注解有助于提高代码的可读性和类型检查的准确性。- def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def __init__(self, **kwargs) -> None: self.code = kwargs.get("code") or self.code kwargs["code"] = Cell.one_from_boc(self.code) super().__init__(**kwargs)
🧰 Tools
🪛 Ruff
10-10: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
10-10: Missing type annotation for
self
in method(ANN101)
10-10: Missing type annotation for
**kwargs
(ANN003)
core/src/apps/ton/tonsdk/utils/_utils.py (10)
5-6: 🛠️ Refactor suggestion
建议为函数添加类型注解
为函数
concat_bytes(a, b)
添加参数和返回值的类型注解,可以提高代码的可读性和可维护性。🧰 Tools
🪛 Ruff
5-5: Missing return type annotation for private function
concat_bytes
(ANN202)
5-5: Missing type annotation for function argument
a
(ANN001)
5-5: Missing type annotation for function argument
b
(ANN001)
65-65: 🧹 Nitpick (assertive)
发现 TODO 注释,需要检查错误
代码中存在
# TODO: check mistakes
注释,请检查crc32c
函数的实现是否正确。需要我协助检查并修复可能的问题吗?
27-28: 🧹 Nitpick (assertive)
合并嵌套的
if
语句可以将嵌套的
if
条件合并为一个,以简化代码结构,提高可读性。建议修改如下:
-if parent_hash: - if index_hashmap[parent_hash] > index_hashmap[cell_hash]: +if parent_hash and index_hashmap[parent_hash] > index_hashmap[cell_hash]:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.if parent_hash and index_hashmap[parent_hash] > index_hashmap[cell_hash]:
🧰 Tools
🪛 Ruff
27-28: Use a single
if
statement instead of nestedif
statements(SIM102)
100-100:
⚠️ Potential issue直接比较字节对象
将字节对象转换为字符串再比较可能导致不必要的错误。建议直接比较字节对象。
建议修改如下:
-return str(bytes_1) == str(bytes_2) # why str? +return bytes_1 == bytes_2📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.return bytes_1 == bytes_2
111-111: 🧹 Nitpick (assertive)
改进异常处理方式
建议使用内置的
ValueError
异常来替代通用的Exception
,以提供更明确的错误信息。建议修改如下:
-raise Exception("Invalid size") +raise ValueError("Invalid size")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.raise ValueError("Invalid size")
🧰 Tools
🪛 Ruff
111-111: Create your own exception
(TRY002)
111-111: Avoid specifying long messages outside the exception class
(TRY003)
38-38: 🧹 Nitpick (assertive)
缺少尾随逗号
在函数调用的参数列表中,最后一个参数后添加逗号有助于代码维护。
建议修改如下:
sub_cell, topological_order_arr, index_hashmap, cell_hash -) +),Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
38-38: Trailing comma missing
Add trailing comma
(COM812)
19-19: 🧹 Nitpick (assertive)
缺少尾随逗号
在函数调用参数列表的最后一个参数后添加逗号,可以简化版本控制中的差异展示。
建议修改如下:
index_hashmap, topological_order_arr = move_to_end( index_hashmap, topological_order_arr, sub_cell.bytes_hash() -) +),Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
19-19: Trailing comma missing
Add trailing comma
(COM812)
30-30: 🧹 Nitpick (assertive)
缺少尾随逗号
在多行参数列表的最后一个参数后添加逗号,可以减少未来修改时的代码差异。
建议修改如下:
index_hashmap, topological_order_arr, cell_hash -) +),Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
30-30: Trailing comma missing
Add trailing comma
(COM812)
103-117:
⚠️ Potential issue修复
string_to_bytes
函数中的逻辑错误函数
string_to_bytes
在将字符串转换为字节数组时可能存在问题:
- 在循环中,
buf[i] = c
可能会引发类型错误,应该使用ord(c)
将字符转换为整数。- 已注释的代码
# buf[i] = ord(c)
可以启用。建议修改如下:
# buf[i] = ord(c) buf[i] = c # ? +buf[i] = ord(c)Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
103-103: Missing return type annotation for private function
string_to_bytes
(ANN202)
103-103: Missing type annotation for function argument
string
(ANN001)
103-103: Missing type annotation for function argument
size
(ANN001)
111-111: Create your own exception
(TRY002)
111-111: Avoid specifying long messages outside the exception class
(TRY003)
120-132: 🛠️ Refactor suggestion
使用内置函数简化代码
Python 提供了内置的
hex()
函数,可以直接将整数转换为十六进制字符串,简化代码。建议修改如下:
-def int_to_hex(n): - if n == 0: - return "0" - - hex_digits = "0123456789abcdef" - hex_string = "" - - while n > 0: - remainder = n % 16 - hex_string = hex_digits[remainder] + hex_string - n = n // 16 - - return hex_string +def int_to_hex(n): + return hex(n)[2:]Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
120-120: Missing return type annotation for private function
int_to_hex
(ANN202)
120-120: Missing type annotation for function argument
n
(ANN001)
python/src/trezorlib/ton.py (7)
12-12: 🧹 Nitpick (assertive)
为函数
get_address
添加返回类型注解请为公共函数
get_address
添加返回类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
12-12: Missing return type annotation for public function
get_address
(ANN201)
16-17: 🛠️ Refactor suggestion
避免在函数定义中使用布尔类型的定位参数
布尔类型的定位参数可能在调用时引起混淆。建议将参数
bounceable
、test_only
和show_display
修改为仅关键字参数。应用以下修改来更新函数签名:
def get_address(client: "TrezorClient", n: "Address", version: messages.TonWalletVersion=messages.TonWalletVersion.V4R2, workchain: messages.TonWorkChain=messages.TonWorkChain.BASECHAIN, + *, bounceable: bool = False, test_only: bool = False, wallet_id: int = 698983191, show_display: bool = False):
Also applies to: 19-19
🧰 Tools
🪛 Ruff
16-16: Boolean-typed positional argument in function definition
(FBT001)
16-16: Boolean default positional argument in function definition
(FBT002)
17-17: Boolean-typed positional argument in function definition
(FBT001)
17-17: Boolean default positional argument in function definition
(FBT002)
33-33: 🧹 Nitpick (assertive)
为函数
sign_message
添加返回类型注解请为公共函数
sign_message
添加返回类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
33-33: Missing return type annotation for public function
sign_message
(ANN201)
46-47: 🛠️ Refactor suggestion
避免在函数定义中使用布尔类型的定位参数
布尔类型的定位参数可能在调用时引起混淆。建议将参数
is_raw_data
、bounceable
和test_only
修改为仅关键字参数。应用以下修改来更新函数签名:
def sign_message(client: "TrezorClient", n: "Address", destination: str, jetton_master_address: str, jetton_wallet_address: str, ton_amount: int, jetton_amount: int, jetton_amount_bytes: str, fwd_fee: int, mode: int, seqno: int, expire_at: int, comment: str = "", + *, is_raw_data: bool = False, version: messages.TonWalletVersion = messages.TonWalletVersion.V4R2, wallet_id: int = 698983191, workchain: messages.TonWorkChain = messages.TonWorkChain.BASECHAIN, bounceable: bool = False, test_only: bool = False, ext_destination: list[str] = None, ext_ton_amount: list[int] = None, ext_payload: list[str] = None, signing_message_hash: str = None ):
Also applies to: 50-51
🧰 Tools
🪛 Ruff
46-46: Boolean-typed positional argument in function definition
(FBT001)
46-46: Boolean default positional argument in function definition
(FBT002)
91-91: 🧹 Nitpick (assertive)
为函数
sign_proof
添加返回类型注解请为公共函数
sign_proof
添加返回类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
91-91: Missing return type annotation for public function
sign_proof
(ANN201)
99-100: 🛠️ Refactor suggestion
避免在函数定义中使用布尔类型的定位参数
布尔类型的定位参数可能在调用时引起混淆。建议将参数
bounceable
和test_only
修改为仅关键字参数。应用以下修改来更新函数签名:
def sign_proof(client: "TrezorClient", n: "Address", expire_at: int, appdomain: str, comment: str, version: messages.TonWalletVersion=messages.TonWalletVersion.V4R2, wallet_id: int = 698983191, workchain: messages.TonWorkChain=messages.TonWorkChain.BASECHAIN, + *, bounceable: bool = False, test_only: bool = False):
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.bounceable: bool = False, test_only: bool = False): ``` ↓ ```suggestion *, bounceable: bool = False, test_only: bool = False):
🧰 Tools
🪛 Ruff
99-99: Boolean-typed positional argument in function definition
(FBT001)
99-99: Boolean default positional argument in function definition
(FBT002)
100-100: Boolean-typed positional argument in function definition
(FBT001)
100-100: Boolean default positional argument in function definition
(FBT002)
52-55: 🧹 Nitpick (assertive)
显式使用
Optional
类型定义可选参数根据 PEP 484,建议将可能为
None
的参数类型显式定义为Optional[T]
。请将参数ext_destination
、ext_ton_amount
、ext_payload
和signing_message_hash
的类型修改为Optional
。应用以下修改:
+ from typing import Optional def sign_message(client: "TrezorClient", n: "Address", destination: str, jetton_master_address: str, jetton_wallet_address: str, ton_amount: int, jetton_amount: int, jetton_amount_bytes: str, fwd_fee: int, mode: int, seqno: int, expire_at: int, comment: str = "", *, is_raw_data: bool = False, version: messages.TonWalletVersion = messages.TonWalletVersion.V4R2, wallet_id: int = 698983191, workchain: messages.TonWorkChain = messages.TonWorkChain.BASECHAIN, bounceable: bool = False, test_only: bool = False, - ext_destination: list[str] = None, - ext_ton_amount: list[int] = None, - ext_payload: list[str] = None, - signing_message_hash: str = None + ext_destination: Optional[list[str]] = None, + ext_ton_amount: Optional[list[int]] = None, + ext_payload: Optional[list[str]] = None, + signing_message_hash: Optional[str] = None ):📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.ext_destination: Optional[list[str]] = None, ext_ton_amount: Optional[list[int]] = None, ext_payload: Optional[list[str]] = None, signing_message_hash: Optional[str] = None
🧰 Tools
🪛 Ruff
52-52: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
53-53: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
54-54: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
55-55: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
55-55: Trailing comma missing
Add trailing comma
(COM812)
core/src/apps/ton/tonsdk/contract/wallet/_wallet_contract_v4.py (5)
1-1: 🧹 Nitpick (assertive)
移除可执行权限或添加 shebang
该文件具有可执行权限,但缺少 shebang(
#!/usr/bin/env python3
)。如果该文件不是可执行脚本,建议移除可执行权限;如果是脚本,请添加适当的 shebang。🧰 Tools
🪛 Ruff
1-1: The file is executable but no shebang is present
(EXE002)
6-6: 🛠️ Refactor suggestion
添加缺少的类型注解
方法
create_data_cell
缺少返回类型注解,参数self
也没有类型注解。建议为方法和参数添加适当的类型注解,以提高代码的清晰度和可维护性。🧰 Tools
🪛 Ruff
6-6: Missing return type annotation for private function
create_data_cell
(ANN202)
6-6: Missing type annotation for
self
in method(ANN101)
14-14: 🛠️ Refactor suggestion
完善方法的参数和返回类型注解
方法
create_signing_message
缺少返回类型注解,参数self
、expiration_time
、seqno
和without_op
均缺少类型注解。为增强代码的可读性和类型检查,建议为这些参数和返回值添加适当的类型注解。此外,避免在函数定义中使用布尔值作为默认位置参数,建议将without_op
参数的位置调整到参数列表末尾,或在调用时显式指定参数名。🧰 Tools
🪛 Ruff
14-14: Missing return type annotation for private function
create_signing_message
(ANN202)
14-14: Missing type annotation for
self
in method(ANN101)
14-14: Missing type annotation for function argument
expiration_time
(ANN001)
14-14: Missing type annotation for function argument
seqno
(ANN001)
14-14: Boolean default positional argument in function definition
(FBT002)
14-14: Missing type annotation for function argument
without_op
(ANN001)
32-32: 🧹 Nitpick (assertive)
为构造函数添加类型注解
在
__init__
方法中,参数self
和**kwargs
缺少类型注解。建议为这些参数添加适当的类型注解,以提高代码的清晰度和可维护性。🧰 Tools
🪛 Ruff
32-32: Missing type annotation for
self
in method(ANN101)
32-32: Missing type annotation for
**kwargs
(ANN003)
41-41: 🧹 Nitpick (assertive)
为构造函数添加类型注解
在
__init__
方法中,参数self
和**kwargs
缺少类型注解。建议为这些参数添加适当的类型注解,以提高代码的清晰度和可维护性。🧰 Tools
🪛 Ruff
41-41: Missing type annotation for
self
in method(ANN101)
41-41: Missing type annotation for
**kwargs
(ANN003)
core/src/apps/ton/tonsdk/contract/wallet/_wallet_contract.py (5)
42-121: 🧹 Nitpick (assertive)
重构
create_transaction_digest
方法以降低复杂度方法
create_transaction_digest
的复杂度过高,建议将复杂逻辑拆分为多个辅助方法,以提高代码的可读性和可维护性。🧰 Tools
🪛 Ruff
42-42:
create_transaction_digest
is too complex (12 > 10)(C901)
42-42: Missing return type annotation for private function
create_transaction_digest
(ANN202)
43-43: Missing type annotation for
self
in method(ANN101)
49-49: Boolean-typed positional argument in function definition
(FBT001)
49-49: Boolean default positional argument in function definition
(FBT002)
49-49: Unused method argument:
is_raw_data
(ARG002)
50-50: Missing type annotation for function argument
send_mode
(ANN001)
51-51: Missing type annotation for function argument
state_init
(ANN001)
52-52: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
53-53: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
54-54: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
72-72: Trailing comma missing
Add trailing comma
(COM812)
81-83: Avoid specifying long messages outside the exception class
(TRY003)
82-82: Trailing comma missing
Add trailing comma
(COM812)
110-110: Trailing comma missing
Add trailing comma
(COM812)
113-113: Trailing comma missing
Add trailing comma
(COM812)
30-35: 🧹 Nitpick (assertive)
为
create_data_cell
方法添加返回类型注解缺少返回类型注解,建议为方法
create_data_cell
添加返回类型Cell
,以提高代码的可读性和类型检查。应用以下修改:
def create_data_cell(self) -> Cell: cell = Cell() cell.bits.write_uint(0, 32) cell.bits.write_bytes(self.options["public_key"]) return cell📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def create_data_cell(self) -> Cell: cell = Cell() cell.bits.write_uint(0, 32) cell.bits.write_bytes(self.options["public_key"]) return cell
🧰 Tools
🪛 Ruff
30-30: Missing return type annotation for private function
create_data_cell
(ANN202)
30-30: Missing type annotation for
self
in method(ANN101)
36-41: 🧹 Nitpick (assertive)
为
create_signing_message
方法添加类型注解缺少参数和返回类型注解,建议为方法
create_signing_message
的参数_expiration_time
和seqno
添加类型注解,并指定返回类型Cell
。应用以下修改:
def create_signing_message(self, _expiration_time: int, seqno: int = None) -> Cell: seqno = seqno or 0 cell = Cell() cell.bits.write_uint(seqno, 32) return cell📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def create_signing_message(self, _expiration_time: int, seqno: int = None) -> Cell: seqno = seqno or 0 cell = Cell() cell.bits.write_uint(seqno, 32) return cell
🧰 Tools
🪛 Ruff
36-36: Missing return type annotation for private function
create_signing_message
(ANN202)
36-36: Missing type annotation for
self
in method(ANN101)
36-36: Missing type annotation for function argument
_expiration_time
(ANN001)
36-36: Missing type annotation for function argument
seqno
(ANN001)
25-28: 🛠️ Refactor suggestion
在
__init__
方法中添加返回类型注解并使用自定义异常缺少返回类型注解,建议在
__init__
方法后添加-> None
。此外,直接抛出Exception
不够具体,建议创建并使用自定义异常类,以提供更明确的错误信息。应用以下修改:
+class WalletContractError(Exception): + pass class WalletContract(Contract): - def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None: if "public_key" not in kwargs: - raise Exception("WalletContract required publicKey in options") + raise WalletContractError("WalletContract requires 'public_key' in options") super().__init__(**kwargs)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.class WalletContractError(Exception): pass class WalletContract(Contract): def __init__(self, **kwargs) -> None: if "public_key" not in kwargs: raise WalletContractError("WalletContract requires 'public_key' in options") super().__init__(**kwargs)
🧰 Tools
🪛 Ruff
25-25: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
25-25: Missing type annotation for
self
in method(ANN101)
25-25: Missing type annotation for
**kwargs
(ANN003)
27-27: Create your own exception
(TRY002)
27-27: Avoid specifying long messages outside the exception class
(TRY003)
42-55: 🛠️ Refactor suggestion
为
create_transaction_digest
方法添加类型注解并删除未使用的参数缺少返回类型和部分参数的类型注解,建议补充完整。此外,参数
is_raw_data
未被使用,建议移除。应用以下修改:
+from typing import Optional, Tuple, Any def create_transaction_digest( self, to_addr: str, amount: int, seqno: int, expire_at: int, payload: Union[Cell, str, bytes, None] = None, - is_raw_data: bool = False, send_mode: int = SendModeEnum.ignore_errors | SendModeEnum.pay_gas_separately, state_init: Any = None, ext_to: Optional[List[str]] = None, ext_amount: Optional[List[int]] = None, ext_payload: Optional[List[Union[Cell, str, bytes, None]]] = None, ) -> Tuple[bytes, bytes]: # 方法体保持不变📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from typing import Optional, Tuple, Any def create_transaction_digest( self, to_addr: str, amount: int, seqno: int, expire_at: int, payload: Union[Cell, str, bytes, None] = None, send_mode: int = SendModeEnum.ignore_errors | SendModeEnum.pay_gas_separately, state_init: Any = None, ext_to: Optional[List[str]] = None, ext_amount: Optional[List[int]] = None, ext_payload: Optional[List[Union[Cell, str, bytes, None]]] = None, ) -> Tuple[bytes, bytes]:
🧰 Tools
🪛 Ruff
42-42:
create_transaction_digest
is too complex (12 > 10)(C901)
42-42: Missing return type annotation for private function
create_transaction_digest
(ANN202)
43-43: Missing type annotation for
self
in method(ANN101)
49-49: Boolean-typed positional argument in function definition
(FBT001)
49-49: Boolean default positional argument in function definition
(FBT002)
49-49: Unused method argument:
is_raw_data
(ARG002)
50-50: Missing type annotation for function argument
send_mode
(ANN001)
51-51: Missing type annotation for function argument
state_init
(ANN001)
52-52: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
53-53: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
54-54: PEP 484 prohibits implicit
Optional
Convert to
Optional[T]
(RUF013)
core/src/apps/ton/tonsdk/boc/dict/serialize_dict.py (5)
26-26: 🛠️ Refactor suggestion
使用显式异常替代
assert
代码在第26、35、36、41、50行使用了
assert
进行参数检查。assert
在生产环境可能被优化掉,建议使用显式异常提高可靠性。示例修改:
- assert len(src) > 0, "Internal inconsistency" + if not src: + raise ValueError("Internal inconsistency")Also applies to: 35-36, 41-41, 50-50
🧰 Tools
🪛 Ruff
26-26: Use of
assert
detected(S101)
125-129: 🧹 Nitpick (assertive)
简化判断元素一致性的逻辑
第125-129行的循环可用
all
函数替代,简化代码。修改如下:
- for e in src[1:]: - if e != src[0]: - return False - return True + return all(e == src[0] for e in src[1:])📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.return all(e == src[0] for e in src[1:])
🧰 Tools
🪛 Ruff
125-129: Use
return all(e == src[0] for e in src[1:])
instead offor
loopReplace with
return all(e == src[0] for e in src[1:])
(SIM110)
17-17: 🧹 Nitpick (assertive)
移除不必要的
else
语句第16行已有
return
语句,后续的else
是多余的。移除else
可以简化代码结构。修改如下:
if length == 0: return src - else: res = {}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.if length == 0: return src res = {}
🧰 Tools
🪛 Ruff
17-17: Unnecessary
else
afterreturn
statementRemove unnecessary
else
(RET505)
43-43: 🧹 Nitpick (assertive)
优化获取字典第一个值的方法
第43行使用
list(src.values())[0]
获取值,效率较低。建议改为next(iter(src.values()))
。修改如下:
- return {"type": "leaf", "value": list(src.values())[0]} + return {"type": "leaf", "value": next(iter(src.values()))}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.return {"type": "leaf", "value": next(iter(src.values()))}
🧰 Tools
🪛 Ruff
43-43: Prefer
next(iter(src.values()))
over single element sliceReplace with
next(iter(src.values()))
(RUF015)
14-22: 🧹 Nitpick (assertive)
为函数
remove_prefix_map
添加类型注解函数
remove_prefix_map
缺少参数src
和length
的类型注解,以及返回值的类型注解。添加类型注解可以提高代码的可读性和可维护性。建议修改如下:
-def remove_prefix_map(src, length): +def remove_prefix_map(src: Dict[str, Any], length: int) -> Dict[str, Any]:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def remove_prefix_map(src: Dict[str, Any], length: int) -> Dict[str, Any]: if length == 0: return src else: res = {} for k in src: res[k[length:]] = src[k] return res
🧰 Tools
🪛 Ruff
14-14: Missing return type annotation for public function
remove_prefix_map
(ANN201)
14-14: Missing type annotation for function argument
src
(ANN001)
14-14: Missing type annotation for function argument
length
(ANN001)
17-17: Unnecessary
else
afterreturn
statementRemove unnecessary
else
(RET505)
core/src/apps/ton/tonsdk/utils/_address.py (17)
1-1: 🧹 Nitpick (assertive)
文件被标记为可执行但缺少 shebang
文件被设置为可执行,但缺少 shebang 行。若非脚本文件,请移除可执行权限;若为脚本,请添加适当的 shebang 行。
🧰 Tools
🪛 Ruff
1-1: The file is executable but no shebang is present
(EXE002)
6-6: 🧹 Nitpick (assertive)
为函数添加类型注解
请为函数
parse_friendly_address
添加参数addr_str
的类型注解和返回值的类型注解,以提升代码的可读性和可靠性。🧰 Tools
🪛 Ruff
6-6: Missing return type annotation for private function
parse_friendly_address
(ANN202)
6-6: Missing type annotation for function argument
addr_str
(ANN001)
8-8: 🧹 Nitpick (assertive)
使用更具体的异常类型
在抛出异常时,避免使用通用的
Exception
。建议使用更具体的内置异常类型,如ValueError
,以提供更明确的错误信息。🧰 Tools
🪛 Ruff
8-8: Create your own exception
(TRY002)
8-8: Avoid specifying long messages outside the exception class
(TRY003)
14-14: 🧹 Nitpick (assertive)
使用更具体的异常类型
同样地,在此处抛出异常时,建议使用更具体的异常类型,如
ValueError
,而不是通用的Exception
。🧰 Tools
🪛 Ruff
14-14: Create your own exception
(TRY002)
14-14: Avoid specifying long messages outside the exception class
(TRY003)
20-20: 🧹 Nitpick (assertive)
使用更具体的异常类型
请考虑使用更具体的异常类型来代替通用的
Exception
,以便更好地描述错误情况。🧰 Tools
🪛 Ruff
20-20: Create your own exception
(TRY002)
20-20: Avoid specifying long messages outside the exception class
(TRY003)
29-29: 🧹 Nitpick (assertive)
使用更具体的异常类型
在抛出异常时,使用更具体的异常类型可以提高代码的可读性和错误处理的准确性。
🧰 Tools
🪛 Ruff
29-29: Create your own exception
(TRY002)
29-29: Avoid specifying long messages outside the exception class
(TRY003)
38-38: 🧹 Nitpick (assertive)
使用更具体的异常类型
再次建议使用更具体的异常类型,如
ValueError
,以替代通用的Exception
。🧰 Tools
🪛 Ruff
38-38: Create your own exception
(TRY002)
38-38: Avoid specifying long messages outside the exception class
(TRY003)
54-54: 🧹 Nitpick (assertive)
为方法添加类型注解
请为
__init__
方法的参数self
和any_form
添加类型注解,并为返回值添加类型注解(应为None
)。🧰 Tools
🪛 Ruff
54-54: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
54-54: Missing type annotation for
self
in method(ANN101)
54-54: Missing type annotation for function argument
any_form
(ANN001)
56-56: 🧹 Nitpick (assertive)
使用更具体的异常类型
在此处抛出异常时,建议使用
ValueError
或自定义异常类,以提供更明确的错误信息。🧰 Tools
🪛 Ruff
56-56: Create your own exception
(TRY002)
56-56: Avoid specifying long messages outside the exception class
(TRY003)
81-81: 🧹 Nitpick (assertive)
使用更具体的异常类型
避免使用通用的
Exception
,请使用更具体的异常类型,提升错误处理的准确性。🧰 Tools
🪛 Ruff
81-81: Create your own exception
(TRY002)
81-81: Avoid specifying long messages outside the exception class
(TRY003)
85-85: 🧹 Nitpick (assertive)
使用更具体的异常类型
同样地,建议使用更具体的异常类型,而非通用的
Exception
。🧰 Tools
🪛 Ruff
85-85: Create your own exception
(TRY002)
85-85: Avoid specifying long messages outside the exception class
(TRY003)
89-89: 🧹 Nitpick (assertive)
使用更具体的异常类型
建议在此处使用更具体的异常类型,以提高代码的可读性和维护性。
🧰 Tools
🪛 Ruff
89-89: Create your own exception
(TRY002)
89-89: Avoid specifying long messages outside the exception class
(TRY003)
104-104: 🧹 Nitpick (assertive)
为方法添加类型注解
请为方法
to_string
添加参数和返回值的类型注解,以提升代码质量。🧰 Tools
🪛 Ruff
104-104: Missing return type annotation for private function
to_string
(ANN202)
144-144: 🧹 Nitpick (assertive)
为方法添加类型注解
请为方法
get_hash_part
添加参数self
和返回值的类型注解。🧰 Tools
🪛 Ruff
144-144: Missing return type annotation for private function
get_hash_part
(ANN202)
144-144: Missing type annotation for
self
in method(ANN101)
147-147: 🧹 Nitpick (assertive)
为方法添加类型注解
请为方法
to_buffer
的参数self
和返回值添加类型注解。🧰 Tools
🪛 Ruff
147-147: Missing return type annotation for private function
to_buffer
(ANN202)
147-147: Missing type annotation for
self
in method(ANN101)
33-36: 🧹 Nitpick (assertive)
简化条件赋值
可以使用三元运算符简化
workchain
的赋值,使代码更简洁。建议修改为:
- if addr[1] == 0xFF: - workchain = -1 - else: - workchain = addr[1] + workchain = -1 if addr[1] == 0xFF else addr[1]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.workchain = -1 if addr[1] == 0xFF else addr[1]
🧰 Tools
🪛 Ruff
33-36: Use ternary operator
workchain = -1 if addr[1] == 255 else addr[1]
instead ofif
-else
-blockReplace
if
-else
-block withworkchain = -1 if addr[1] == 255 else addr[1]
(SIM108)
122-122: 🧹 Nitpick (assertive)
移除不必要的
else
在前面的
return
语句后,else
分支是不必要的,可以移除以简化代码。建议修改为:
- else: - return f"{self.wc}:{self.hash_part.hex()}" + return f"{self.wc}:{self.hash_part.hex()}"Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
122-122: Unnecessary
else
afterreturn
statementRemove unnecessary
else
(RET505)
common/protob/messages-ton.proto (2)
9-11: 🧹 Nitpick (assertive)
移除注释的枚举值
TonWalletVersion
枚举中,V3R1
、V3R2
、V4R1
被注释掉了。如果不再需要,建议删除这些注释,保持代码整洁。
81-81:
⚠️ Potential issue修正字段名拼写错误
字段名
signning_message
拼写错误,应为signing_message
。建议修改:
- optional bytes signning_message = 2; // message to sign + optional bytes signing_message = 2; // message to sign📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.optional bytes signing_message = 2; // message to sign
core/src/apps/ton/tonsdk/contract/token/nft/nft_collection.py (12)
13-13: 🧹 Nitpick (assertive)
为
__init__
方法添加类型注解建议为
__init__
方法的参数self
、**kwargs
和返回类型-> None
添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
13-13: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
13-13: Missing type annotation for
self
in method(ANN101)
13-13: Missing type annotation for
**kwargs
(ANN003)
22-22: 🧹 Nitpick (assertive)
为
create_content_cell
方法添加类型注解建议为方法参数
self
、params
和返回类型添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
22-22: Missing type annotation for
self
in method(ANN101)
22-22: Missing type annotation for function argument
params
(ANN001)
35-35: 🧹 Nitpick (assertive)
为
create_royalty_cell
方法添加类型注解建议为方法参数
self
、params
和返回类型添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
35-35: Missing type annotation for
self
in method(ANN101)
35-35: Missing type annotation for function argument
params
(ANN001)
42-42: 🧹 Nitpick (assertive)
为
create_data_cell
方法添加类型注解建议为方法参数
self
和返回类型添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
42-42: Missing type annotation for
self
in method(ANN101)
52-58: 🧹 Nitpick (assertive)
为
create_mint_body
方法添加缺失的类型注解建议为方法参数
self
、item_index
、new_owner_address
、item_content_uri
、amount
、query_id
和返回类型添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
52-52: Missing type annotation for
self
in method(ANN101)
73-78: 🧹 Nitpick (assertive)
为
create_batch_mint_body
方法添加缺失的类型注解建议为方法参数
self
、from_item_index
、contents_and_owners
、amount_per_one
、query_id
和返回类型添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
73-73: Missing type annotation for
self
in method(ANN101)
96-96: 🧹 Nitpick (assertive)
为
create_get_royalty_params_body
方法添加类型注解建议为方法参数
self
、query_id
和返回类型添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
96-96: Missing type annotation for
self
in method(ANN101)
103-103: 🧹 Nitpick (assertive)
为
create_change_owner_body
方法添加类型注解建议为方法参数
self
、new_owner_address
、query_id
和返回类型添加类型注解,并在参数列表末尾添加逗号,提升代码的可读性和一致性。🧰 Tools
🪛 Ruff
103-103: Missing type annotation for
self
in method(ANN101)
103-103: Trailing comma missing
Add trailing comma
(COM812)
111-111: 🧹 Nitpick (assertive)
为
create_edit_content_body
方法添加类型注解建议为方法参数
self
、params
和返回类型添加类型注解,以提高代码的可读性和类型检查的准确性。🧰 Tools
🪛 Ruff
111-111: Missing type annotation for
self
in method(ANN101)
111-111: Missing type annotation for function argument
params
(ANN001)
113-113: 🧹 Nitpick (assertive)
使用自定义异常替代通用
Exception
建议创建并使用自定义异常类替代通用的
Exception
,提供更明确的错误信息和更好的异常处理。可以定义一个自定义异常类,例如:
class RoyaltyValueError(Exception): pass然后在代码中修改为:
- raise Exception("royalty must be less than 1") + raise RoyaltyValueError("royalty must be less than 1")🧰 Tools
🪛 Ruff
113-113: Create your own exception
(TRY002)
113-113: Avoid specifying long messages outside the exception class
(TRY003)
24-24: 🧹 Nitpick (assertive)
在多行函数调用中添加缺失的逗号
在多行函数调用的参数列表中,建议在最后一行后添加逗号,增强代码一致性和可读性。例如:
collection_content_cell = create_offchain_uri_cell( params["collection_content_uri"] - ) + ),Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
24-24: Trailing comma missing
Add trailing comma
(COM812)
28-28: 🧹 Nitpick (assertive)
在多行函数调用中添加缺失的逗号
在多行函数调用的参数列表中,建议在最后一行后添加逗号,增强代码一致性和可读性。例如:
common_content_cell.bits.write_bytes( serialize_uri(params["nft_item_content_base_uri"]) - ) + ),Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
28-28: Trailing comma missing
Add trailing comma
(COM812)
core/src/apps/ton/tonsdk/contract/__init__.py (7)
40-41: 🛠️ Refactor suggestion
建议:使用自定义异常类,避免直接抛出通用异常
在多个地方直接抛出
Exception
,不利于异常的精确捕获和处理。建议定义一个专用的异常类,并在这些地方使用。可考虑如下修改:
+ class ContractError(Exception): + pass def create_code_cell(self) -> Cell: if "code" not in self.options or self.options["code"] is None: - raise Exception("Contract: options.code is not defined") + raise ContractError("options.code 未定义") return self.options["code"] def create_internal_message_header(...): if currency_collection: - raise Exception("Currency collections are not implemented yet") + raise ContractError("当前未实现货币集合") def __create_state_init(...): if library or split_depth or ticktock: - raise Exception("Library/SplitDepth/Ticktock in state init is not implemented") + raise ContractError("初始化状态中未实现 Library/SplitDepth/Ticktock")Also applies to: 99-100, 143-145
🧰 Tools
🪛 Ruff
40-40: Create your own exception
(TRY002)
40-40: Avoid specifying long messages outside the exception class
(TRY003)
76-78: 🛠️ Refactor suggestion
建议:为函数参数添加类型注解
create_internal_message_header
方法中的多个参数缺少类型注解,建议为这些参数添加类型注解,提升代码的可读性和类型安全性。Also applies to: 81-84
🧰 Tools
🪛 Ruff
76-76: Boolean default positional argument in function definition
(FBT002)
76-76: Missing type annotation for function argument
ihr_disabled
(ANN001)
77-77: Missing type annotation for function argument
bounce
(ANN001)
78-78: Boolean default positional argument in function definition
(FBT002)
78-78: Missing type annotation for function argument
bounced
(ANN001)
28-28: 🧹 Nitpick (assertive)
建议:在多行结构中添加逗号以符合编码规范
在行尾缺少逗号可能导致代码合并时出现问题,建议在多行结构的最后一行添加逗号。
可考虑如下修改:
address = Address( str(self.options["wc"]) + ":" + hexlify(state_init_hash).decode() + ) raise ContractError("初始化状态中未实现 Library/SplitDepth/Ticktock" + ) [ bool(split_depth), bool(ticktock), bool(code), bool(data), bool(library) + ],Also applies to: 144-144, 159-159
🧰 Tools
🪛 Ruff
28-28: Trailing comma missing
Add trailing comma
(COM812)
127-127: 🧹 Nitpick (assertive)
建议:移除多余的注释代码
第 127 行的
# if False:
似乎是多余的,建议删除以提高代码的清晰度。可考虑如下修改:
- # if False:
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
15-19: 🛠️ Refactor suggestion
建议:为
address
属性添加类型注解缺少类型注解会降低代码的可读性和可维护性。建议为返回值添加类型注解。
可考虑如下修改:
@property - def address(self): + def address(self) -> Address: if self._address is None: self._address = self.create_state_init()["address"] return self._addressCommittable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
15-15: Missing return type annotation for public function
address
(ANN201)
15-15: Missing type annotation for
self
in method(ANN101)
38-42: 🛠️ Refactor suggestion
建议:为
create_code_cell
方法添加类型注解缺少类型注解会降低代码的可读性和可维护性。建议为返回值添加类型注解。
可考虑如下修改:
def create_code_cell(self): + -> Cell: if "code" not in self.options or self.options["code"] is None: raise Exception("Contract: options.code is not defined") return self.options["code"]
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
38-38: Missing return type annotation for public function
create_code_cell
(ANN201)
38-38: Missing type annotation for
self
in method(ANN101)
40-40: Create your own exception
(TRY002)
40-40: Avoid specifying long messages outside the exception class
(TRY003)
8-13: 🛠️ Refactor suggestion
建议:为
__init__
方法添加类型注解缺少类型注解会降低代码的可读性和可维护性。建议为参数和返回值添加类型注解。
可考虑如下修改:
+ from typing import Any class Contract: - def __init__(self, **kwargs): + def __init__(self, **kwargs: Any) -> None: self.options = kwargs self._address = Address(kwargs["address"]) if "address" in kwargs else None if "wc" not in kwargs: kwargs["wc"] = self._address.wc if self._address is not None else 0📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from typing import Any def __init__(self, **kwargs: Any) -> None: self.options = kwargs self._address = Address(kwargs["address"]) if "address" in kwargs else None if "wc" not in kwargs: kwargs["wc"] = self._address.wc if self._address is not None else 0
🧰 Tools
🪛 Ruff
8-8: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
8-8: Missing type annotation for
self
in method(ANN101)
8-8: Missing type annotation for
**kwargs
(ANN003)
core/src/apps/ton/sign_message.py (12)
25-25: 🧹 Nitpick (assertive)
建议在参数列表末尾添加逗号
为提高代码可读性,请在函数参数列表末尾添加一个逗号。
🧰 Tools
🪛 Ruff
25-25: Trailing comma missing
Add trailing comma
(COM812)
38-38: 🧹 Nitpick (assertive)
避免在异常中直接使用长消息
建议在异常类中定义错误消息,或使用预定义的错误消息常量。
🧰 Tools
🪛 Ruff
38-38: Avoid specifying long messages outside the exception class
(TRY003)
43-43: 🧹 Nitpick (assertive)
建议在参数列表末尾添加逗号
为提高代码可读性,请在函数参数列表末尾添加一个逗号。
🧰 Tools
🪛 Ruff
43-43: Trailing comma missing
Add trailing comma
(COM812)
59-59:
⚠️ Potential issue避免捕获通用异常
直接捕获
Exception
可能会隐藏其他未预料的异常。建议捕获更具体的异常类型。🧰 Tools
🪛 Ruff
59-59: Do not catch blind exception:
Exception
(BLE001)
70-70: 🧹 Nitpick (assertive)
避免在异常中直接使用长消息
建议在异常类中定义错误消息,或使用预定义的错误消息常量。
🧰 Tools
🪛 Ruff
70-70: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
70-70: Avoid specifying long messages outside the exception class
(TRY003)
81-81: 🧹 Nitpick (assertive)
避免在异常中直接使用长消息
建议在异常类中定义错误消息,或使用预定义的错误消息常量。
🧰 Tools
🪛 Ruff
81-81: Avoid specifying long messages outside the exception class
(TRY003)
86-86: 🧹 Nitpick (assertive)
避免在异常中直接使用长消息
建议在异常类中定义错误消息,或使用预定义的错误消息常量。
🧰 Tools
🪛 Ruff
86-86: Avoid specifying long messages outside the exception class
(TRY003)
109-109: 🧹 Nitpick (assertive)
建议在参数列表末尾添加逗号
为提高代码可读性,请在参数列表末尾添加一个逗号。
🧰 Tools
🪛 Ruff
109-109: Trailing comma missing
Add trailing comma
(COM812)
172-172: 🧹 Nitpick (assertive)
避免在异常中直接使用长消息
建议在异常类中定义错误消息,或使用预定义的错误消息常量。
🧰 Tools
🪛 Ruff
172-172: Avoid specifying long messages outside the exception class
(TRY003)
166-166: 🛠️ Refactor suggestion
移除
return
后不必要的elif
在
return
之后,elif
可以简化为if
,以提高代码简洁性。- elif msg.jetton_amount_bytes is not None and msg.jetton_master_address is not None: + if msg.jetton_amount_bytes is not None and msg.jetton_master_address is not None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.if msg.jetton_amount_bytes is not None and msg.jetton_master_address is not None:
🧰 Tools
🪛 Ruff
166-166: Unnecessary
elif
afterreturn
statementRemove unnecessary
elif
(RET505)
73-73: 🧹 Nitpick (assertive)
在函数调用中显式指定布尔参数
直接传递布尔值可能降低代码可读性,建议显式指定参数名称。
- recipient = Address(msg.destination).to_string(True, True) + recipient = Address(msg.destination).to_string(is_user_friendly=True, is_url_safe=True)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.recipient = Address(msg.destination).to_string(is_user_friendly=True, is_url_safe=True)
🧰 Tools
🪛 Ruff
73-73: Boolean positional value in function call
(FBT003)
73-73: Boolean positional value in function call
(FBT003)
69-69: 🛠️ Refactor suggestion
移除
return
后不必要的else
return
后的else
语句是多余的,建议移除以简化代码。- else: + # 移除多余的 elseCommittable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
69-69: Unnecessary
else
afterreturn
statementRemove unnecessary
else
(RET505)
python/src/trezorlib/cli/ton.py (12)
21-21:
⚠️ Potential issue移除未使用的
time
导入模块
time
未在代码中使用,建议删除。应用以下差异来删除未使用的导入:
- import time
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
🧰 Tools
🪛 Ruff
21-21:
time
imported but unusedRemove unused import:
time
(F401)
60-60: 🛠️ Refactor suggestion
添加缺失的尾随逗号
在参数列表中,缺少尾随逗号,建议在最后一个参数后添加逗号。
应用以下差异添加尾随逗号:
- show_display: bool + show_display: bool,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.show_display: bool,
🧰 Tools
🪛 Ruff
60-60: Boolean-typed positional argument in function definition
(FBT001)
60-60: Trailing comma missing
Add trailing comma
(COM812)
146-146:
⚠️ Potential issue修正变量名拼写错误
signning_message
变量名应为
signing_message
,请修正拼写错误。应用以下差异修正拼写错误:
- return resp.signature.hex(), resp.signning_message.hex() + return resp.signature.hex(), resp.signing_message.hex()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.return resp.signature.hex(), resp.signing_message.hex()
40-40:
⚠️ Potential issue为函数
cli
添加返回类型注解缺少返回类型注解,建议添加
-> None
。应用以下差异来添加返回类型注解:
- def cli(): + def cli() -> None:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def cli() -> None:
🧰 Tools
🪛 Ruff
40-40: Missing return type annotation for public function
cli
Add return type annotation:
None
(ANN201)
115-115: 🛠️ Refactor suggestion
添加缺失的尾随逗号
在参数列表中,缺少尾随逗号,建议在最后一个参数后添加逗号。
应用以下差异添加尾随逗号:
- signing_message_hash: str + signing_message_hash: str,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.signing_message_hash: str,
🧰 Tools
🪛 Ruff
115-115: Trailing comma missing
Add trailing comma
(COM812)
167-167: 🛠️ Refactor suggestion
添加缺失的尾随逗号
在参数列表中,缺少尾随逗号,建议在最后一个参数后添加逗号。
应用以下差异添加尾随逗号:
- test_only: bool + test_only: bool,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.test_only: bool,
🧰 Tools
🪛 Ruff
167-167: Boolean-typed positional argument in function definition
(FBT001)
167-167: Trailing comma missing
Add trailing comma
(COM812)
53-61: 🛠️ Refactor suggestion
将布尔类型参数设为仅限关键字
函数
get_address
中的布尔参数应设为仅限关键字,以提高可读性并防止调用时的混淆。应用以下差异将布尔参数设为仅限关键字:
def get_address(client: "TrezorClient", address: str, + *, bounceable: bool, test_only: bool, wallet_id: int, version: messages.TonWalletVersion, workchain: messages.TonWorkChain, show_display: bool) -> dict:
Committable suggestion skipped: line range outside the PR's diff.
🧰 Tools
🪛 Ruff
55-55: Boolean-typed positional argument in function definition
(FBT001)
56-56: Boolean-typed positional argument in function definition
(FBT001)
60-60: Boolean-typed positional argument in function definition
(FBT001)
60-60: Trailing comma missing
Add trailing comma
(COM812)
53-66:
⚠️ Potential issue函数
get_address
的返回类型与实际返回值不匹配函数声明的返回类型为
str
,但实际返回了一个dict
。建议修改返回类型注解以匹配实际返回值。应用以下差异修正返回类型注解:
- ) -> str: + ) -> dict:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def get_address(client: "TrezorClient", address: str, bounceable: bool, test_only: bool, wallet_id: int, version: messages.TonWalletVersion, workchain: messages.TonWorkChain, show_display: bool ) -> dict: """Get Ton address for specified path.""" address_n = tools.parse_path(address) resp = ton.get_address(client, address_n, version, workchain, bounceable, test_only, wallet_id, show_display) public_key = resp.public_key.hex() return {"public_key": f"{public_key}", "address": f"{resp.address}"}
🧰 Tools
🪛 Ruff
55-55: Boolean-typed positional argument in function definition
(FBT001)
56-56: Boolean-typed positional argument in function definition
(FBT001)
60-60: Boolean-typed positional argument in function definition
(FBT001)
60-60: Trailing comma missing
Add trailing comma
(COM812)
93-116: 🛠️ Refactor suggestion
将布尔类型参数设为仅限关键字
函数
sign_message
中的布尔参数应设为仅限关键字,以提高可读性并防止调用时的混淆。应用以下差异将布尔参数设为仅限关键字:
def sign_message(client: "TrezorClient", address: str, destination: str, jetton_master_address: str, jetton_wallet_address: str, ton_amount: int, jetton_amount: int, jetton_amount_bytes: str, fwd_fee: int, mode: int, seqno: int, expire_at: int, comment: str, + *, is_raw_data: bool, version: messages.TonWalletVersion, wallet_id: int, workchain: messages.TonWorkChain, bounceable: bool, test_only: bool, ext_destination: tuple[str, ...], ext_ton_amount: tuple[int, ...], ext_payload: tuple[str, ...], signing_message_hash: str) -> bytes:
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def sign_message(client: "TrezorClient", address: str, destination: str, jetton_master_address: str, jetton_wallet_address: str, ton_amount: int, jetton_amount: int, jetton_amount_bytes: str, fwd_fee: int, mode: int, seqno: int, expire_at: int, comment: str, *, is_raw_data: bool, version: messages.TonWalletVersion, wallet_id: int, workchain: messages.TonWorkChain, bounceable: bool, test_only: bool, ext_destination: tuple[str, ...], ext_ton_amount: tuple[int, ...], ext_payload: tuple[str, ...], signing_message_hash: str) -> bytes:
🧰 Tools
🪛 Ruff
106-106: Boolean-typed positional argument in function definition
(FBT001)
110-110: Boolean-typed positional argument in function definition
(FBT001)
111-111: Boolean-typed positional argument in function definition
(FBT001)
115-115: Trailing comma missing
Add trailing comma
(COM812)
158-186: 🛠️ Refactor suggestion
将布尔类型参数设为仅限关键字
函数
sign_proof
中的布尔参数应设为仅限关键字,以提高可读性并防止调用时的混淆。应用以下差异将布尔参数设为仅限关键字:
def sign_proof(client: "TrezorClient", address: str, appdomain: str, comment: str, + *, version: messages.TonWalletVersion, wallet_id: int, workchain: messages.TonWorkChain, bounceable: bool, test_only: bool) -> dict:
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def sign_proof(client: "TrezorClient", address: str, # expire_at: int, appdomain: str, comment: str, *, version: messages.TonWalletVersion, wallet_id: int, workchain: messages.TonWorkChain, bounceable: bool, test_only: bool ) -> dict: """Sign Ton Proof.""" address_n = tools.parse_path(address) # expire_at = int(time.time()) + 300 expire_at = 1979465599 signature = ton.sign_proof( client, address_n, expire_at, appdomain, comment, version, wallet_id, workchain, bounceable, test_only ).signature.hex() return {"signature": f"0x{signature}"}
🧰 Tools
🪛 Ruff
166-166: Boolean-typed positional argument in function definition
(FBT001)
167-167: Boolean-typed positional argument in function definition
(FBT001)
167-167: Trailing comma missing
Add trailing comma
(COM812)
183-183: Trailing comma missing
Add trailing comma
(COM812)
158-186:
⚠️ Potential issue函数
sign_proof
的返回类型与实际返回值不匹配函数声明的返回类型为
bytes
,但实际返回了一个包含签名的字典。建议修改返回类型注解以匹配实际返回值。应用以下差异修正返回类型注解:
- ) -> bytes: + ) -> dict:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def sign_proof(client: "TrezorClient", address: str, # expire_at: int, appdomain: str, comment: str, version: messages.TonWalletVersion, wallet_id: int, workchain: messages.TonWorkChain, bounceable: bool, test_only: bool ) -> dict: """Sign Ton Proof.""" address_n = tools.parse_path(address) # expire_at = int(time.time()) + 300 expire_at = 1979465599 signature = ton.sign_proof( client, address_n, expire_at, appdomain, comment, version, wallet_id, workchain, bounceable, test_only ).signature.hex() return {"signature": f"0x{signature}"}
🧰 Tools
🪛 Ruff
166-166: Boolean-typed positional argument in function definition
(FBT001)
167-167: Boolean-typed positional argument in function definition
(FBT001)
167-167: Trailing comma missing
Add trailing comma
(COM812)
183-183: Trailing comma missing
Add trailing comma
(COM812)
93-146:
⚠️ Potential issue函数
sign_message
的返回类型与实际返回值不匹配函数声明的返回类型为
bytes
,但实际返回了两个十六进制字符串。建议修改返回类型注解,或调整返回值以匹配注解。如果返回的是两个字符串,建议修改返回类型注解:
- ) -> bytes: + ) -> Tuple[str, str]:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.def sign_message(client: "TrezorClient", address: str, destination: str, jetton_master_address: str, jetton_wallet_address: str, ton_amount: int, jetton_amount: int, jetton_amount_bytes: str, fwd_fee: int, mode: int, seqno: int, expire_at: int, comment: str, is_raw_data: bool, version: messages.TonWalletVersion, wallet_id: int, workchain: messages.TonWorkChain, bounceable: bool, test_only: bool, ext_destination: tuple[str, ...], ext_ton_amount: tuple[int, ...], ext_payload: tuple[str, ...], signing_message_hash: str ) -> Tuple[str, str]: """Sign Ton Transaction.""" address_n = tools.parse_path(address) # expire_at = int(time.time()) + 300 resp = ton.sign_message( client, address_n, destination, jetton_master_address, jetton_wallet_address, ton_amount, jetton_amount, jetton_amount_bytes, fwd_fee, mode, seqno, expire_at, comment, is_raw_data, version, wallet_id, workchain, bounceable, test_only, list(ext_destination), list(ext_ton_amount), list(ext_payload), signing_message_hash ) return resp.signature.hex(), resp.signning_message.hex()
🧰 Tools
🪛 Ruff
106-106: Boolean-typed positional argument in function definition
(FBT001)
110-110: Boolean-typed positional argument in function definition
(FBT001)
111-111: Boolean-typed positional argument in function definition
(FBT001)
115-115: Trailing comma missing
Add trailing comma
(COM812)
143-143: Trailing comma missing
Add trailing comma
(COM812)
core/src/apps/ton/tonsdk/boc/_cell.py (11)
22-22: 🛠️ Refactor suggestion
缺少类型注解
为特殊方法
__init__
添加返回类型注解-> None
,有助于提高代码的可读性和可维护性。🧰 Tools
🪛 Ruff
22-22: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
22-22: Missing type annotation for
self
in method(ANN101)
27-27: 🛠️ Refactor suggestion
__repr__
方法缺少返回类型注解建议为
__repr__
方法添加返回类型注解-> str
,以明确返回值类型。🧰 Tools
🪛 Ruff
27-27: Missing return type annotation for special method
__repr__
Add return type annotation:
str
(ANN204)
27-27: Missing type annotation for
self
in method(ANN101)
74-74: 🧹 Nitpick (assertive)
添加尾随逗号
在多行语句的最后一行添加尾随逗号,有助于减少代码变更时的误差。
🧰 Tools
🪛 Ruff
74-74: Trailing comma missing
Add trailing comma
(COM812)
184-184: 🧹 Nitpick (assertive)
🛠️ Refactor suggestion
避免使用通用异常
建议创建自定义异常类代替使用
Exception
,以便更精确地捕获和处理特定的异常情况。🧰 Tools
🪛 Ruff
184-184: Create your own exception
(TRY002)
184-184: Avoid specifying long messages outside the exception class
(TRY003)
221-221: 🧹 Nitpick (assertive)
函数过于复杂
parse_boc_header
函数的复杂度较高(16 > 10)。考虑将其拆分成更小的函数或模块,提高代码的可读性和维护性。🧰 Tools
🪛 Ruff
221-221:
parse_boc_header
is too complex (16 > 10)(C901)
221-221: Missing return type annotation for private function
parse_boc_header
(ANN202)
221-221: Missing type annotation for function argument
serialized_boc
(ANN001)
189-189: 🛠️ Refactor suggestion
缺少类型注解
为函数
deserialize_cell_data
添加返回类型注解,可以使代码更加清晰,便于他人理解和维护。🧰 Tools
🪛 Ruff
189-189: Missing return type annotation for private function
deserialize_cell_data
(ANN202)
189-189: Missing type annotation for function argument
cell_data
(ANN001)
189-189: Missing type annotation for function argument
reference_index_size
(ANN001)
191-191: 🧹 Nitpick (assertive)
🛠️ Refactor suggestion
避免使用通用异常
抛出异常时,建议使用自定义异常类,避免使用
Exception
,以提供更具体的错误信息。🧰 Tools
🪛 Ruff
191-191: Create your own exception
(TRY002)
191-191: Avoid specifying long messages outside the exception class
(TRY003)
211-211: 🧹 Nitpick (assertive)
添加尾随逗号
在
set_top_upped_array
方法调用的参数列表末尾添加尾随逗号,有助于代码的一致性。🧰 Tools
🪛 Ruff
211-211: Trailing comma missing
Add trailing comma
(COM812)
292-296: 🛠️ Refactor suggestion
改进CRC校验错误处理
当校验和不匹配时,建议抛出自定义异常,并提供明确的错误消息,便于调试。
🧰 Tools
🪛 Ruff
292-292: Create your own exception
(TRY002)
292-292: Avoid specifying long messages outside the exception class
(TRY003)
296-296: Create your own exception
(TRY002)
296-296: Avoid specifying long messages outside the exception class
(TRY003)
301-301: 🛠️ Refactor suggestion
避免使用通用异常
在处理BoC序列化时,建议使用自定义异常类,以提供更精确的错误处理。
🧰 Tools
🪛 Ruff
301-301: Create your own exception
(TRY002)
301-301: Avoid specifying long messages outside the exception class
(TRY003)
28-28: 🧹 Nitpick (assertive)
使用显式转换标志
在第28行的f-string中,建议使用显式转换标志,提高代码可读性。例如:
-return f"<Cell refs_num: {len(self.refs)}, {repr(self.bits)}>" +return f"<Cell refs_num: {len(self.refs)}, {self.bits!r}>"📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.return f"<Cell refs_num: {len(self.refs)}, {self.bits!r}>"
🧰 Tools
🪛 Ruff
28-28: Use explicit conversion flag
Replace with conversion flag
(RUF010)
core/src/trezor/messages.py (1)
65-66:
⚠️ Potential issue移除多余的
noqa
指令第65和66行的
# noqa: F401
指令是多余的,因为导入的模块已被使用。请删除这些指令。可以使用以下修改来修复:
- from trezor.enums import TonWalletVersion # noqa: F401 + from trezor.enums import TonWalletVersion - from trezor.enums import TonWorkChain # noqa: F401 + from trezor.enums import TonWorkChain📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.from trezor.enums import TonWalletVersion from trezor.enums import TonWorkChain
🧰 Tools
🪛 Ruff
65-65: Unused
noqa
directive (unused:F401
)Remove unused
noqa
directive(RUF100)
66-66: Unused
noqa
directive (unused:F401
)Remove unused
noqa
directive(RUF100)
core/src/apps/ton/tonsdk/boc/_bit_string.py (29)
7-10: 🛠️ Refactor suggestion
添加缺失的类型注解
__init__
方法缺少返回类型注解-> None
,并且self
参数缺少类型注解。请补充这些注解以提高代码的可读性。🧰 Tools
🪛 Ruff
7-7: Missing return type annotation for special method
__init__
Add return type annotation:
None
(ANN204)
7-7: Missing type annotation for
self
in method(ANN101)
12-14: 🛠️ Refactor suggestion
完善方法的类型注解
__repr__
方法缺少返回类型注解-> str
,并且self
参数缺少类型注解。建议添加这些注解。🧰 Tools
🪛 Ruff
12-12: Missing return type annotation for special method
__repr__
Add return type annotation:
str
(ANN204)
12-12: Missing type annotation for
self
in method(ANN101)
15-18: 🛠️ Refactor suggestion
补充迭代器方法的类型注解
__iter__
方法缺少返回类型注解和self
参数的类型注解。为了明确方法的返回值类型,请添加相应的注解。🧰 Tools
🪛 Ruff
15-15: Missing return type annotation for special method
__iter__
(ANN204)
15-15: Missing type annotation for
self
in method(ANN101)
19-34: 🛠️ Refactor suggestion
完善获取项方法的类型注解
__getitem__
方法缺少返回类型注解,self
和参数key
的类型注解也缺失。请补充这些注解以提高代码的类型安全性。🧰 Tools
🪛 Ruff
19-19: Missing return type annotation for special method
__getitem__
(ANN204)
19-19: Missing type annotation for
self
in method(ANN101)
19-19: Missing type annotation for function argument
key
(ANN001)
26-26: Unnecessary
elif
afterreturn
statementRemove unnecessary
elif
(RET505)
30-30: Avoid specifying long messages outside the exception class
(TRY003)
33-33: Avoid specifying long messages outside the exception class
(TRY003)
35-37: 🛠️ Refactor suggestion
为
__len__
方法添加类型注解
__len__
方法缺少返回类型注解和self
参数的类型注解。请添加返回类型注解-> int
。🧰 Tools
🪛 Ruff
35-35: Missing return type annotation for special method
__len__
Add return type annotation:
int
(ANN204)
35-35: Missing type annotation for
self
in method(ANN101)
38-41: 🛠️ Refactor suggestion
补充
get
方法的类型注解
get
方法缺少返回类型注解,self
和参数n
的类型注解也未提供。请完善这些注解。🧰 Tools
🪛 Ruff
38-38: Missing return type annotation for private function
get
(ANN202)
38-38: Missing type annotation for
self
in method(ANN101)
42-46: 🛠️ Refactor suggestion
添加
off
方法的类型注解
off
方法缺少返回类型注解-> None
,self
和参数n
的类型注解也缺失。请补充。🧰 Tools
🪛 Ruff
42-42: Missing return type annotation for private function
off
Add return type annotation:
None
(ANN202)
42-42: Missing type annotation for
self
in method(ANN101)
42-42: Missing type annotation for function argument
n
(ANN001)
47-51: 🛠️ Refactor suggestion
完善
on
方法的类型注解
on
方法缺少返回类型注解-> None
,self
和参数n
的类型注解需要添加。🧰 Tools
🪛 Ruff
47-47: Missing return type annotation for private function
on
Add return type annotation:
None
(ANN202)
47-47: Missing type annotation for
self
in method(ANN101)
47-47: Missing type annotation for function argument
n
(ANN001)
52-56: 🛠️ Refactor suggestion
使用自定义异常代替通用异常
在第55行,直接抛出了通用的
Exception("BitString overflow")
。建议创建自定义异常类,如BitStringOverflowError
,以提高异常处理的准确性。🧰 Tools
🪛 Ruff
52-52: Missing type annotation for
self
in method(ANN101)
55-55: Create your own exception
(TRY002)
55-55: Avoid specifying long messages outside the exception class
(TRY003)
57-64: 🛠️ Refactor suggestion
完善
set_top_upped_array
方法的类型注解
set_top_upped_array
方法缺少返回类型注解-> None
,self
、参数array
和fullfilled_bytes
的类型注解也缺失。且布尔类型的参数fullfilled_bytes
应该作为关键字参数。🧰 Tools
🪛 Ruff
57-57: Missing return type annotation for private function
set_top_upped_array
Add return type annotation:
None
(ANN202)
57-57: Missing type annotation for
self
in method(ANN101)
57-57: Boolean default positional argument in function definition
(FBT002)
57-57: Missing type annotation for function argument
fullfilled_bytes
(ANN001)
65-74: 🧹 Nitpick (assertive)
移除不必要的
else
语句在第65行,前面的代码块已经有返回,
else
可以省略,直接写后续代码,简化代码结构。🧰 Tools
🪛 Ruff
65-65: Unnecessary
else
afterreturn
statementRemove unnecessary
else
(RET505)
76-77: 🛠️ Refactor suggestion
使用自定义异常代替通用异常
第76行抛出了通用的异常。建议定义自定义异常,例如
InvalidTopUppedArrayError
,以提供更明确的错误信息。🧰 Tools
🪛 Ruff
76-76: Create your own exception
(TRY002)
76-76: Avoid specifying long messages outside the exception class
(TRY003)
93-96: 🛠️ Refactor suggestion
为
get_free_bits
方法添加类型注解
get_free_bits
方法缺少返回类型注解和self
参数的类型注解。请添加返回类型注解-> int
。🧰 Tools
🪛 Ruff
93-93: Missing type annotation for
self
in method(ANN101)
97-99: 🛠️ Refactor suggestion
补充
get_used_bits
方法的类型注解
get_used_bits
方法缺少返回类型注解和self
参数的类型注解。请完善这些注解。🧰 Tools
🪛 Ruff
97-97: Missing return type annotation for private function
get_used_bits
(ANN202)
97-97: Missing type annotation for
self
in method(ANN101)
100-104: 🛠️ Refactor suggestion
完善
write_bit_array
方法的类型注解
write_bit_array
方法缺少返回类型注解-> None
,self
和参数ba
的类型注解也需要补充。🧰 Tools
🪛 Ruff
100-100: Missing return type annotation for private function
write_bit_array
Add return type annotation:
None
(ANN202)
100-100: Missing type annotation for
self
in method(ANN101)
105-115: 🛠️ Refactor suggestion
添加
write_bit
方法的类型注解
write_bit
方法缺少返回类型注解-> None
,self
和参数b
的类型注解未提供。请补充。🧰 Tools
🪛 Ruff
105-105: Missing return type annotation for private function
write_bit
Add return type annotation:
None
(ANN202)
105-105: Missing type annotation for
self
in method(ANN101)
105-105: Missing type annotation for function argument
b
(ANN001)
112-112: Create your own exception
(TRY002)
112-112: Avoid specifying long messages outside the exception class
(TRY003)
112-113: 🛠️ Refactor suggestion
使用自定义异常代替通用异常
第112行抛出了通用的
Exception("BitString can only write 1 or 0")
。建议创建自定义异常以提高错误处理的清晰度。🧰 Tools
🪛 Ruff
112-112: Create your own exception
(TRY002)
112-112: Avoid specifying long messages outside the exception class
(TRY003)
116-132: 🛠️ Refactor suggestion
完善
write_uint
方法的类型注解
write_uint
方法缺少返回类型注解-> None
,self
、参数number
和bit_length
的类型注解需要添加。🧰 Tools
🪛 Ruff
116-116: Missing return type annotation for private function
write_uint
Add return type annotation:
None
(ANN202)
116-116: Missing type annotation for
self
in method(ANN101)
121-123: Create your own exception
(TRY002)
121-123: Avoid specifying long messages outside the exception class
(TRY003)
122-122: Trailing comma missing
Add trailing comma
(COM812)
122-123: 🛠️ Refactor suggestion
使用自定义异常代替通用异常
在第122行,抛出了通用异常。请考虑定义自定义异常,例如
BitLengthTooSmallError
。🧰 Tools
🪛 Ruff
121-123: Create your own exception
(TRY002)
121-123: Avoid specifying long messages outside the exception class
(TRY003)
122-122: Trailing comma missing
Add trailing comma
(COM812)
133-136: 🛠️ Refactor suggestion
添加
write_uint8
方法的类型注解
write_uint8
方法缺少返回类型注解-> None
,self
和参数ui8
的类型注解未提供。🧰 Tools
🪛 Ruff
133-133: Missing return type annotation for private function
write_uint8
Add return type annotation:
None
(ANN202)
133-133: Missing type annotation for
self
in method(ANN101)
137-156: 🛠️ Refactor suggestion
完善
write_int
方法的类型注解
write_int
方法缺少返回类型注解-> None
,self
、参数number
和bit_length
的类型注解需要补充。🧰 Tools
🪛 Ruff
137-137: Missing return type annotation for private function
write_int
Add return type annotation:
None
(ANN202)
137-137: Missing type annotation for
self
in method(ANN101)
147-147: Create your own exception
(TRY002)
147-147: Avoid specifying long messages outside the exception class
(TRY003)
148-148: Unnecessary
else
afterraise
statementRemove unnecessary
else
(RET506)
147-148: 🧹 Nitpick (assertive)
移除不必要的
else
语句第148行的
else
语句在前面已经抛出异常的情况下是多余的,建议移除以简化代码。🧰 Tools
🪛 Ruff
147-147: Create your own exception
(TRY002)
147-147: Avoid specifying long messages outside the exception class
(TRY003)
148-148: Unnecessary
else
afterraise
statementRemove unnecessary
else
(RET506)
147-148: 🛠️ Refactor suggestion
使用自定义异常代替通用异常
第147行直接抛出了通用的异常。建议定义特定的异常类型,更好地描述错误。
🧰 Tools
🪛 Ruff
147-147: Create your own exception
(TRY002)
147-147: Avoid specifying long messages outside the exception class
(TRY003)
148-148: Unnecessary
else
afterraise
statementRemove unnecessary
else
(RET506)
157-159: 🛠️ Refactor suggestion
补充
write_string
方法的类型注解
write_string
方法缺少返回类型注解-> None
,self
和参数value
的类型注解也需要添加。🧰 Tools
🪛 Ruff
157-157: Missing return type annotation for private function
write_string
Add return type annotation:
None
(ANN202)
157-157: Missing type annotation for
self
in method(ANN101)
160-163: 🛠️ Refactor suggestion
完善
write_bytes
方法的类型注解
write_bytes
方法缺少返回类型注解-> None
,self
和参数ui8_array
的类型注解未提供。🧰 Tools
🪛 Ruff
160-160: Missing return type annotation for private function
write_bytes
Add return type annotation:
None
(ANN202)
160-160: Missing type annotation for
self
in method(ANN101)
164-167: 🛠️ Refactor suggestion
添加
write_bit_string
方法的类型注解
write_bit_string
方法缺少返回类型注解-> None
,self
和参数another_bit_string
的类型注解需要补充。🧰 Tools
🪛 Ruff
164-164: Missing return type annotation for private function
write_bit_string
Add return type annotation:
None
(ANN202)
164-164: Missing type annotation for
self
in method(ANN101)
168-177: 🛠️ Refactor suggestion
完善
write_address
方法的类型注解
write_address
方法缺少返回类型注解-> None
,self
和参数address
的类型注解也需要添加。🧰 Tools
🪛 Ruff
168-168: Missing return type annotation for private function
write_address
Add return type annotation:
None
(ANN202)
168-168: Missing type annotation for
self
in method(ANN101)
178-186: 🛠️ Refactor suggestion
补充
write_grams
方法的类型注解
write_grams
方法缺少返回类型注解-> None
,self
和参数amount
的类型注解未提供。🧰 Tools
🪛 Ruff
178-178: Missing return type annotation for private function
write_grams
Add return type annotation:
None
(ANN202)
178-178: Missing type annotation for
self
in method(ANN101)
183-183: Ambiguous variable name:
l
(E741)
183-183: 🛠️ Refactor suggestion
避免使用模糊的变量名
在第183行,变量
l
容易与数字1
或大写字母I
混淆。建议使用更明确的变量名,如length
或byte_length
。🧰 Tools
🪛 Ruff
183-183: Ambiguous variable name:
l
(E741)
Cell.one_from_boc(msg.comment) | ||
except Exception: | ||
if msg.signing_message_hash is not None: | ||
digest = msg.signing_message_hash |
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.
这种实现方式是风险最高的,目前咱们的盲签很少会使用这种方式!
Summary by CodeRabbit
版本更新说明
新功能
修复
文档