|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from hiero_sdk_python.file.file_append_transaction import FileAppendTransaction |
3 | 4 | from hiero_sdk_python.file.file_contents_query import FileContentsQuery |
4 | 5 | from hiero_sdk_python.file.file_create_transaction import FileCreateTransaction |
5 | 6 | from hiero_sdk_python.file.file_delete_transaction import FileDeleteTransaction |
|
9 | 10 | from hiero_sdk_python.hbar import Hbar |
10 | 11 | from hiero_sdk_python.response_code import ResponseCode |
11 | 12 | from hiero_sdk_python.timestamp import Timestamp |
| 13 | +from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt |
12 | 14 | from tck.errors import JsonRpcError |
13 | 15 | from tck.handlers.registry import rpc_method |
14 | | -from tck.param.file import CreateFileParams, DeleteFileParams, GetFileContentsParams, GetFileInfoParams |
| 16 | +from tck.param.file import ( |
| 17 | + AppendFileParams, |
| 18 | + CreateFileParams, |
| 19 | + DeleteFileParams, |
| 20 | + GetFileContentsParams, |
| 21 | + GetFileInfoParams, |
| 22 | +) |
| 23 | +from tck.response.base import StatusOnlyResponse |
15 | 24 | from tck.response.file import CreateFileResponse, DeleteFileResponse, GetFileContentsResponse, GetFileInfoResponse |
16 | 25 | from tck.util.client_utils import get_client |
17 | 26 | from tck.util.constants import DEFAULT_GRPC_TIMEOUT |
@@ -60,6 +69,40 @@ def create_file(params: CreateFileParams) -> CreateFileResponse: |
60 | 69 | return CreateFileResponse(file_id, ResponseCode(receipt.status).name) |
61 | 70 |
|
62 | 71 |
|
| 72 | +def _build_append_file_transaction(params: AppendFileParams) -> FileAppendTransaction: |
| 73 | + transaction = FileAppendTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT) |
| 74 | + |
| 75 | + # Default to 0.0.0 so a missing fileId is rejected by the network with |
| 76 | + # INVALID_FILE_ID rather than raising a client-side ValueError (TCK FileId #5). |
| 77 | + transaction.set_file_id(FileId.from_string(params.fileId) if params.fileId is not None else FileId()) |
| 78 | + |
| 79 | + if params.contents is not None: |
| 80 | + transaction.set_contents(params.contents) |
| 81 | + |
| 82 | + if params.chunkSize is not None: |
| 83 | + transaction.set_chunk_size(params.chunkSize) |
| 84 | + |
| 85 | + if params.maxChunks is not None: |
| 86 | + transaction.set_max_chunks(params.maxChunks) |
| 87 | + |
| 88 | + return transaction |
| 89 | + |
| 90 | + |
| 91 | +@rpc_method("appendFile") |
| 92 | +def append_file(params: AppendFileParams) -> StatusOnlyResponse: |
| 93 | + """Append contents to a file.""" |
| 94 | + client = get_client(params.sessionId) |
| 95 | + |
| 96 | + transaction = _build_append_file_transaction(params) |
| 97 | + |
| 98 | + if params.commonTransactionParams is not None: |
| 99 | + params.commonTransactionParams.apply_common_params(transaction, client) |
| 100 | + |
| 101 | + receipts: list[TransactionReceipt] = transaction.execute_all(client, wait_for_receipt=True, validate_status=True) |
| 102 | + |
| 103 | + return StatusOnlyResponse(ResponseCode(receipts[-1].status).name) |
| 104 | + |
| 105 | + |
63 | 106 | @rpc_method("getFileContents") |
64 | 107 | def get_file_contents(params: GetFileContentsParams) -> GetFileContentsResponse: |
65 | 108 | client = get_client(params.sessionId) |
|
0 commit comments