Skip to content

Commit 02d3111

Browse files
committed
Create ChunkedTransaction class
Signed-off-by: MonaaEid <monaa_eid@hotmail.com>
1 parent 2b44b6f commit 02d3111

2 files changed

Lines changed: 10 additions & 26 deletions

File tree

src/hiero_sdk_python/transaction/chunked_transaction.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
from hiero_sdk_python.transaction.transaction_response import TransactionResponse
1313

1414

15-
if TYPE_CHECKING:
16-
pass
17-
18-
1915
class ChunkedTransaction(Transaction, ABC):
2016
"""
2117
Abstract base class for transactions that support chunking.
@@ -43,17 +39,6 @@ def __init__(self) -> None:
4339
self.chunk_size: int = 1024
4440
self.max_chunks: int = 20
4541

46-
@abstractmethod
47-
def get_required_chunks(self) -> int:
48-
"""
49-
Returns the number of chunks required for the current content.
50-
51-
Subclasses must implement this based on their content type.
52-
53-
Returns:
54-
int: Number of chunks required.
55-
"""
56-
pass
5742

5843
@abstractmethod
5944
def _build_proto_body(self):
@@ -148,10 +133,9 @@ def freeze_with(self, client: Client) -> ChunkedTransaction:
148133
if self._transaction_body_bytes:
149134
return self
150135

151-
self._validate_chunking()
152136
self._resolve_transaction_id(client)
153137

154-
if self.transaction_id is None or self.transaction_id.valid_start is None:
138+
if self.transaction_id.valid_start is None:
155139
raise ValueError("Transaction ID with valid_start must be set before freezing chunked transaction.")
156140

157141
# Generate transaction IDs for all chunks if not already done
@@ -265,11 +249,10 @@ def execute_all(
265249
List[TransactionReceipt]: If wait_for_receipt is True (default)
266250
List[TransactionResponse]: If wait_for_receipt is False
267251
"""
268-
self._validate_chunking()
269-
270-
required_chunks = self.get_required_chunks()
252+
self._validate_chunking() # Moved here
271253

272-
if required_chunks == 1:
254+
# For single-chunk transactions, delegate to the standard execution flow.
255+
if self.get_required_chunks() == 1:
273256
return [
274257
super().execute(
275258
client,
@@ -279,13 +262,14 @@ def execute_all(
279262
)
280263
]
281264

282-
# Ensure the initial transaction ID and chunk transaction IDs exist.
283-
if not self._transaction_ids:
265+
# For multi-chunk transactions, ensure we are frozen before proceeding.
266+
if not self._transaction_body_bytes:
284267
self.freeze_with(client)
285268

286269
responses = []
270+
required_chunks = self.get_required_chunks()
287271

288-
for chunk_index in range(required_chunks):
272+
for chunk_index in range(self.get_required_chunks()):
289273
self._current_chunk_index = chunk_index
290274

291275
if chunk_index < len(self._transaction_ids):

tests/integration/topic_message_submit_transaction_e2e_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_topic_message_submit_transaction_fails_if_max_chunks_less_than_requied(
108108
message_tx = TopicMessageSubmitTransaction().set_topic_id(topic_id).set_message(message).set_max_chunks(2)
109109

110110
with pytest.raises(ValueError):
111-
message_tx.freeze_with(env.client)
111+
message_tx.execute(env.client)
112112

113113
delete_topic(env.client, topic_id)
114114

@@ -289,7 +289,7 @@ def test_integration_topic_message_submit_transaction_fails_if_required_chunk_gr
289289
with pytest.raises(
290290
ValueError, match="Message requires 4 chunks but max_chunks=2. Increase limit with set_max_chunks()."
291291
):
292-
message_transaction.freeze_with(env.client)
292+
message_transaction.execute(env.client)
293293

294294
delete_topic(env.client, topic_id)
295295

0 commit comments

Comments
 (0)