From c90328a5c3b2f361beaaf2e9f726b3ec8cb90405 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 9 Apr 2025 12:59:26 +0800 Subject: [PATCH] fix: add to_header_id conversion --- src/libs/common.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libs/common.py b/src/libs/common.py index 678f9f5..e42db8a 100644 --- a/src/libs/common.py +++ b/src/libs/common.py @@ -32,21 +32,28 @@ def generate_log_prefix(): def to_index(n: int) -> list: - if n < 0: - raise ValueError("Input must be an unsigned integer (non-negative)") - return list(n.to_bytes(8, byteorder="big")) + return to_byte_list(n, 8) def to_app_id(n: int) -> list: - if n < 0: - raise ValueError("Input must be an unsigned integer (non-negative)") - return list(n.to_bytes(32, byteorder="big")) + return to_byte_list(n, 32) def to_blob_id(n: int) -> list: + return to_byte_list(n, 32) + + +def to_header_id(n: int) -> list: + return to_byte_list(n, 32) + + +def to_byte_list(n: int, l: int) -> list: if n < 0: raise ValueError("Input must be an unsigned integer (non-negative)") - return list(n.to_bytes(32, byteorder="big")) + if l < 1: + raise ValueError("Length must be an unsigned integer greater than 0") + + return list(n.to_bytes(l, byteorder="big")) def random_divide_k(n, k):