|
3 | 3 | from hiero_sdk_python.file.file_contents_query import FileContentsQuery |
4 | 4 | from hiero_sdk_python.file.file_create_transaction import FileCreateTransaction |
5 | 5 | from hiero_sdk_python.file.file_id import FileId |
| 6 | +from hiero_sdk_python.file.file_info import FileInfo |
| 7 | +from hiero_sdk_python.file.file_info_query import FileInfoQuery |
6 | 8 | from hiero_sdk_python.hbar import Hbar |
7 | 9 | from hiero_sdk_python.response_code import ResponseCode |
8 | 10 | from hiero_sdk_python.timestamp import Timestamp |
9 | 11 | from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt |
10 | 12 | from tck.errors import JsonRpcError |
11 | 13 | from tck.handlers.registry import rpc_method |
12 | | -from tck.param.file import CreateFileParams, GetFileContentsParams |
13 | | -from tck.response.file import CreateFileResponse, GetFileContentsResponse |
| 14 | +from tck.param.file import CreateFileParams, GetFileContentsParams, GetFileInfoParams |
| 15 | +from tck.response.file import CreateFileResponse, GetFileContentsResponse, GetFileInfoResponse |
14 | 16 | from tck.util.client_utils import get_client |
15 | 17 | from tck.util.constants import DEFAULT_GRPC_TIMEOUT |
16 | | -from tck.util.key_utils import get_key_from_string |
| 18 | +from tck.util.key_utils import get_key_from_string, key_to_string |
17 | 19 | from tck.util.param_utils import to_int |
18 | 20 |
|
19 | 21 |
|
@@ -76,3 +78,31 @@ def get_file_contents(params: GetFileContentsParams) -> GetFileContentsResponse: |
76 | 78 | decoded_contents = contents.decode("utf-8", errors="replace") if isinstance(contents, bytes) else str(contents) |
77 | 79 |
|
78 | 80 | return GetFileContentsResponse(contents=decoded_contents) |
| 81 | + |
| 82 | + |
| 83 | +def _build_file_info_response(info: FileInfo) -> GetFileInfoResponse: |
| 84 | + """Build a GetFileResponse from a FileInfo object.""" |
| 85 | + |
| 86 | + keys = [key_to_string(k) for k in info.keys] if info.keys else [] |
| 87 | + |
| 88 | + return GetFileInfoResponse( |
| 89 | + fileId=str(info.file_id) if info.file_id is not None else None, |
| 90 | + size=str(info.size) if info.size is not None else None, |
| 91 | + expirationTime=str(info.expiration_time.seconds) if info.expiration_time is not None else None, |
| 92 | + isDeleted=info.is_deleted, |
| 93 | + keys=keys, |
| 94 | + memo=info.file_memo, |
| 95 | + ledgerId=info.ledger_id.hex() if info.ledger_id is not None else None, |
| 96 | + ) |
| 97 | + |
| 98 | + |
| 99 | +@rpc_method("getFileInfo") |
| 100 | +def get_file_info(params: GetFileInfoParams) -> GetFileInfoResponse: |
| 101 | + client = get_client(params.sessionId) |
| 102 | + query = FileInfoQuery().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT) |
| 103 | + |
| 104 | + if params.fileId is not None: |
| 105 | + query.set_file_id(FileId.from_string(params.fileId)) |
| 106 | + |
| 107 | + info = query.execute(client) |
| 108 | + return _build_file_info_response(info) |
0 commit comments