dev@locazia: add blockchain routes, edit resolve content system to cid class, add web2 docs

This commit is contained in:
user committed 2024-02-28 23:29:18 +03:00
1 parent 78a4a84c2b
commit d7ebc26bce
14 files changed
+314 -61

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
from app.core.content.content_id import ContentId
def resolve_content(content_id): # -> [content, error]
try:
return ContentId.deserialize(content_id), None
except BaseException as e:
return None, f"{e}"
+11
View File
@@ -0,0 +1,11 @@
def string_to_bytes_fixed_size(src: str, size: int, encoding='utf-8') -> bytes:
assert type(src) is str, "src must be a string"
src_bin = src.encode(encoding)
assert len(src_bin) <= size, "src is too long"
return src_bin + b'\x00' * (size - len(src_bin))
def bytes_to_string(src: bytes, encoding='utf-8') -> str:
assert type(src) is bytes, "src must be bytes"
return src.decode(encoding).rstrip('\x00')