Skip to content

Commit 5961cce

Browse files
committed
Create ChunkedTransaction class
Signed-off-by: MonaaEid <monaa_eid@hotmail.com>
1 parent 8bb5594 commit 5961cce

5 files changed

Lines changed: 47 additions & 51 deletions

File tree

src/hiero_sdk_python/consensus/topic_message_submit_transaction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class TopicMessageSubmitTransaction(ChunkedTransaction):
2323
"""
2424

2525
def __init__(
26-
self,
27-
topic_id: TopicId | None = None,
28-
message: bytes | str | None = None,
29-
chunk_size: int | None = None,
30-
max_chunks: int | None = None,
26+
self,
27+
topic_id: TopicId | None = None,
28+
message: bytes | str | None = None,
29+
chunk_size: int | None = None,
30+
max_chunks: int | None = None,
3131
) -> None:
3232
"""
3333
Initializes a new TopicMessageSubmitTransaction instance.

src/hiero_sdk_python/file/file_append_transaction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929

3030
class FileAppendTransaction(ChunkedTransaction):
3131
def __init__(
32-
self,
33-
file_id: FileId | None = None,
34-
contents: str | bytes | None = None,
35-
max_chunks: int | None = None,
36-
chunk_size: int | None = None,
32+
self,
33+
file_id: FileId | None = None,
34+
contents: str | bytes | None = None,
35+
max_chunks: int | None = None,
36+
chunk_size: int | None = None,
3737
):
3838
super().__init__()
3939
self.file_id: FileId | None = file_id

src/hiero_sdk_python/transaction/chunked_transaction.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,10 @@ def freeze_with(self, client: Client) -> ChunkedTransaction:
172172
next_nanos = base_timestamp.nanos + i
173173

174174
chunk_valid_start = timestamp_pb2.Timestamp(
175-
seconds=base_timestamp.seconds + next_nanos // 1_000_000_000,
176-
nanos=next_nanos % 1_000_000_000
175+
seconds=base_timestamp.seconds + next_nanos // 1_000_000_000, nanos=next_nanos % 1_000_000_000
177176
)
178177
chunk_transaction_id = TransactionId(
179-
account_id=self.transaction_id.account_id,
180-
valid_start=chunk_valid_start
178+
account_id=self.transaction_id.account_id, valid_start=chunk_valid_start
181179
)
182180

183181
self._transaction_ids.append(chunk_transaction_id)
@@ -186,30 +184,30 @@ def freeze_with(self, client: Client) -> ChunkedTransaction:
186184

187185
@overload
188186
def execute(
189-
self,
190-
client: Client,
191-
timeout: int | float | None = None,
192-
wait_for_receipt: Literal[True] = True,
193-
validate_status: bool = False,
187+
self,
188+
client: Client,
189+
timeout: int | float | None = None,
190+
wait_for_receipt: Literal[True] = True,
191+
validate_status: bool = False,
194192
) -> TransactionReceipt:
195193
...
196194

197195
@overload
198196
def execute(
199-
self,
200-
client: Client,
201-
timeout: int | float | None = None,
202-
wait_for_receipt: Literal[False] = False,
203-
validate_status: bool = False,
197+
self,
198+
client: Client,
199+
timeout: int | float | None = None,
200+
wait_for_receipt: Literal[False] = False,
201+
validate_status: bool = False,
204202
) -> TransactionResponse:
205203
...
206204

207205
def execute(
208-
self,
209-
client: Client,
210-
timeout: int | float | None = None,
211-
wait_for_receipt: bool = True,
212-
validate_status: bool = False,
206+
self,
207+
client: Client,
208+
timeout: int | float | None = None,
209+
wait_for_receipt: bool = True,
210+
validate_status: bool = False,
213211
) -> TransactionReceipt | TransactionResponse:
214212
"""
215213
Executes the chunked transaction.
@@ -232,30 +230,30 @@ def execute(
232230

233231
@overload
234232
def execute_all(
235-
self,
236-
client: Client,
237-
timeout: int | float | None = None,
238-
wait_for_receipt: Literal[True] = True,
239-
validate_status: bool = False,
233+
self,
234+
client: Client,
235+
timeout: int | float | None = None,
236+
wait_for_receipt: Literal[True] = True,
237+
validate_status: bool = False,
240238
) -> list[TransactionReceipt]:
241239
...
242240

243241
@overload
244242
def execute_all(
245-
self,
246-
client: Client,
247-
timeout: int | float | None = None,
248-
wait_for_receipt: Literal[False] = False,
249-
validate_status: bool = False,
243+
self,
244+
client: Client,
245+
timeout: int | float | None = None,
246+
wait_for_receipt: Literal[False] = False,
247+
validate_status: bool = False,
250248
) -> list[TransactionResponse]:
251249
...
252250

253251
def execute_all(
254-
self,
255-
client: Client,
256-
timeout: int | float | None = None,
257-
wait_for_receipt: bool = True,
258-
validate_status: bool = False,
252+
self,
253+
client: Client,
254+
timeout: int | float | None = None,
255+
wait_for_receipt: bool = True,
256+
validate_status: bool = False,
259257
) -> list[TransactionReceipt] | list[TransactionResponse]:
260258
"""
261259
Executes all chunks of the transaction sequentially.

tests/integration/topic_message_submit_transaction_e2e_test.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ def test_topic_message_submit_transaction_fails_if_max_chunks_less_than_requied(
105105

106106
message = "A" * (1024 * 14) # message with (1024 * 14) bytes ie 14 chunks
107107

108-
message_tx = (
109-
TopicMessageSubmitTransaction()
110-
.set_topic_id(topic_id)
111-
.set_message(message)
112-
.set_max_chunks(2)
113-
)
108+
message_tx = TopicMessageSubmitTransaction().set_topic_id(topic_id).set_message(message).set_max_chunks(2)
114109

115110
with pytest.raises(ValueError):
116111
message_tx.freeze_with(env.client)

tests/unit/chunked_transaction_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def test_constructor_sets_default_chunk_configuration():
4949
assert tx._signing_keys == []
5050

5151

52-
@pytest.mark.parametrize("setter_name, value, message", [("set_chunk_size", 0, "chunk_size must be positive"), ("set_max_chunks", 0, "max_chunks must be positive")])
52+
@pytest.mark.parametrize(
53+
"setter_name, value, message",
54+
[("set_chunk_size", 0, "chunk_size must be positive"), ("set_max_chunks", 0, "max_chunks must be positive")],
55+
)
5356
def test_setters_reject_non_positive_values(mock_client, setter_name, value, message):
5457
tx = DummyChunkedTransaction()
5558

0 commit comments

Comments
 (0)