@@ -36,18 +36,8 @@ def setup_client():
3636
3737 return client
3838
39- def file_append ():
40- """
41- Demonstrates appending content to a file on the network by:
42- 1. Setting up client with operator account
43- 2. Creating a file with initial content
44- 3. Appending additional content to the file
45- """
46- client = setup_client ()
47-
48- file_private_key = PrivateKey .generate_ed25519 ()
49-
50- # Step 1: Create a file with initial content
39+ def create_file (client , file_private_key ):
40+ """Create a file with initial content"""
5141 print ("Creating file with initial content..." )
5242 create_receipt = (
5343 FileCreateTransaction ()
@@ -66,7 +56,10 @@ def file_append():
6656 file_id = create_receipt .file_id
6757 print (f"File created successfully with ID: { file_id } " )
6858
69- # Step 2: Append content to the file (single chunk)
59+ return file_id
60+
61+ def append_file_single (client , file_id , file_private_key ):
62+ """Append content to the file (single chunk)"""
7063 print ("\n Appending content to file (single chunk)..." )
7164 append_receipt = (
7265 FileAppendTransaction ()
@@ -82,8 +75,9 @@ def file_append():
8275 sys .exit (1 )
8376
8477 print ("Content appended successfully!" )
85-
86- # Step 3: Append large content (multi-chunk)
78+
79+ def append_file_large (client , file_id , file_private_key ):
80+ """Append large content to the file (multi-chunk)"""
8781 print ("\n Appending large content (multi-chunk)..." )
8882 large_content = b"Large content that will be split into multiple chunks. " * 100
8983
@@ -105,5 +99,25 @@ def file_append():
10599 print ("Large content appended successfully!" )
106100 print (f"Total chunks used: { FileAppendTransaction ().set_contents (large_content ).get_required_chunks ()} " )
107101
102+ def main ():
103+ """
104+ Demonstrates appending content to a file on the network by:
105+ 1. Setting up client with operator account
106+ 2. Creating a file with initial content
107+ 3. Appending additional content to the file
108+ """
109+ client = setup_client ()
110+
111+ file_private_key = PrivateKey .generate_ed25519 ()
112+
113+ # Step 1: Create a file with initial content
114+ file_id = create_file (client , file_private_key )
115+
116+ # Step 2: Append content to the file (single chunk)
117+ append_file_single (client , file_id , file_private_key )
118+
119+ # Step 3: Append large content (multi-chunk)
120+ append_file_large (client , file_id , file_private_key )
121+
108122if __name__ == "__main__" :
109- file_append ()
123+ main ()
0 commit comments