|
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.file.file_update_transaction import FileUpdateTransaction |
7 | 9 | from hiero_sdk_python.hbar import Hbar |
8 | 10 | from hiero_sdk_python.response_code import ResponseCode |
9 | 11 | from hiero_sdk_python.timestamp import Timestamp |
10 | 12 | from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt |
11 | 13 | from tck.errors import JsonRpcError |
12 | 14 | from tck.handlers.registry import rpc_method |
13 | | -from tck.param.file import CreateFileParams, GetFileContentsParams, UpdateFileParams |
| 15 | +from tck.param.file import ( |
| 16 | + CreateFileParams, |
| 17 | + GetFileContentsParams, |
| 18 | + GetFileInfoParams, |
| 19 | + UpdateFileParams, |
| 20 | +) |
14 | 21 | from tck.response.file import ( |
15 | 22 | CreateFileResponse, |
16 | 23 | GetFileContentsResponse, |
| 24 | + GetFileInfoResponse, |
17 | 25 | UpdateFileResponse, |
18 | 26 | ) |
19 | 27 | from tck.util.client_utils import get_client |
20 | 28 | from tck.util.constants import DEFAULT_GRPC_TIMEOUT |
21 | | -from tck.util.key_utils import get_key_from_string |
| 29 | +from tck.util.key_utils import get_key_from_string, key_to_string |
22 | 30 | from tck.util.param_utils import to_int |
23 | 31 |
|
24 | 32 |
|
@@ -84,21 +92,13 @@ def get_file_contents(params: GetFileContentsParams) -> GetFileContentsResponse: |
84 | 92 |
|
85 | 93 |
|
86 | 94 | def _build_update_file_transaction(params: UpdateFileParams) -> FileUpdateTransaction: |
87 | | - """Build a FileUpdateTransaction from parsed params. |
88 | | -
|
89 | | - Each setter is called only when the corresponding field is not None so that |
90 | | - omitted fields are left unchanged on-network. contents is pre-normalized so |
91 | | - that the exact empty string ("") from JSON-RPC params maps to None, therefore |
92 | | - set_contents is never invoked when the caller intends "leave unchanged". |
93 | | - """ |
| 95 | + """Build a FileUpdateTransaction from parsed params.""" |
94 | 96 | transaction = FileUpdateTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT) |
95 | 97 |
|
96 | 98 | if params.fileId is not None: |
97 | | - # ValueError from FileId.from_string propagates as an SDK/internal error. |
98 | 99 | transaction.set_file_id(FileId.from_string(params.fileId)) |
99 | 100 |
|
100 | 101 | if params.keys is not None: |
101 | | - # Threshold-key rejection is enforced by the network, not client-side. |
102 | 102 | transaction.set_keys([get_key_from_string(k) for k in params.keys]) |
103 | 103 |
|
104 | 104 | if params.contents is not None: |
@@ -130,3 +130,31 @@ def update_file(params: UpdateFileParams) -> UpdateFileResponse: |
130 | 130 | receipt: TransactionReceipt = response.get_receipt(client, validate_status=True) |
131 | 131 |
|
132 | 132 | return UpdateFileResponse(status=ResponseCode(receipt.status).name) |
| 133 | + |
| 134 | + |
| 135 | +def _build_file_info_response(info: FileInfo) -> GetFileInfoResponse: |
| 136 | + """Build a GetFileResponse from a FileInfo object.""" |
| 137 | + |
| 138 | + keys = [key_to_string(k) for k in info.keys] if info.keys else [] |
| 139 | + |
| 140 | + return GetFileInfoResponse( |
| 141 | + fileId=str(info.file_id) if info.file_id is not None else None, |
| 142 | + size=str(info.size) if info.size is not None else None, |
| 143 | + expirationTime=str(info.expiration_time.seconds) if info.expiration_time is not None else None, |
| 144 | + isDeleted=info.is_deleted, |
| 145 | + keys=keys, |
| 146 | + memo=info.file_memo, |
| 147 | + ledgerId=info.ledger_id.hex() if info.ledger_id is not None else None, |
| 148 | + ) |
| 149 | + |
| 150 | + |
| 151 | +@rpc_method("getFileInfo") |
| 152 | +def get_file_info(params: GetFileInfoParams) -> GetFileInfoResponse: |
| 153 | + client = get_client(params.sessionId) |
| 154 | + query = FileInfoQuery().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT) |
| 155 | + |
| 156 | + if params.fileId is not None: |
| 157 | + query.set_file_id(FileId.from_string(params.fileId)) |
| 158 | + |
| 159 | + info = query.execute(client) |
| 160 | + return _build_file_info_response(info) |
0 commit comments