|
1 | 1 | # Copyright © Aptos Foundation |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +""" |
| 5 | +This example demonstrates publishing large Move packages which cannot fit in a single transaction, using the most |
| 6 | +abstract method `compile_and_publish_move_package` from the `PackagePublisher` class. This method handles all necessary |
| 7 | +steps for compiling and publishing both regular and large packages. |
| 8 | +
|
| 9 | +Note: This method requires the presence of the Aptos CLI in `APTOS_CLI_PATH`. As an alternative, if you want finer |
| 10 | +control over the process or do not want to rely on the CLI, you may use `publish_package_in_path`, which is |
| 11 | +demonstrated in the `object_code_deployment.py` example. |
| 12 | +""" |
| 13 | + |
3 | 14 | import asyncio |
4 | 15 | import os |
5 | 16 | import sys |
6 | 17 |
|
7 | 18 | import aptos_sdk.cli as aptos_sdk_cli |
8 | 19 | from aptos_sdk.account import Account |
9 | 20 | from aptos_sdk.account_address import AccountAddress |
10 | | -from aptos_sdk.aptos_cli_wrapper import AptosCLIWrapper |
11 | 21 | from aptos_sdk.async_client import ClientConfig, FaucetClient, RestClient |
12 | | -from aptos_sdk.package_publisher import ( |
13 | | - MODULE_ADDRESS, |
14 | | - CompileHelper, |
15 | | - PackagePublisher, |
16 | | - PublishHelper, |
17 | | - PublishMode, |
18 | | -) |
| 22 | +from aptos_sdk.package_publisher import MODULE_ADDRESS, PackagePublisher, PublishMode |
19 | 23 |
|
20 | 24 | from .common import APTOS_CORE_PATH, FAUCET_URL, NODE_URL |
21 | 25 |
|
@@ -58,97 +62,32 @@ async def main( |
58 | 62 | # Name of the move module for the package to be published, containing artifacts larger than the MAX_CHUNK_SIZE |
59 | 63 | module_name = "large_package_example" |
60 | 64 |
|
61 | | - # Example 1. Account deployment |
| 65 | + # -- Example 1. Account deployment |
62 | 66 | print("=== Publishing large package to account ===") |
63 | 67 |
|
64 | | - if AptosCLIWrapper.does_cli_exist(): |
65 | | - AptosCLIWrapper.compile_package( |
66 | | - large_package_example_dir, {module_name: alice.address()} |
67 | | - ) |
68 | | - else: |
69 | | - input("\nUpdate the module with Alice's address, compile, and press Enter.") |
70 | | - |
71 | | - account_deploy_txn_hash = await publisher.publish_package_in_path( |
72 | | - alice, large_package_example_dir, large_packages_module_address |
| 68 | + account_deploy_txn_hash = await publisher.compile_and_publish_move_package( |
| 69 | + alice, large_package_example_dir, module_name, large_packages_module_address |
73 | 70 | ) |
74 | 71 |
|
75 | 72 | print(f"Tx submitted: {account_deploy_txn_hash[0]}") |
76 | 73 | await rest_client.wait_for_transaction(account_deploy_txn_hash[0]) |
77 | | - print(f"Package deployed to account {alice.address()}") |
| 74 | + print("Transaction completed.") |
78 | 75 |
|
79 | | - # Example 2. Object code deployment |
80 | | - # Note: Here we assume that we already know we should use the chunked publish mode, so we run a preliminary build. |
| 76 | + # ----- Example 2. Object code deployment |
81 | 77 | print("=== Publishing large package to object ===") |
82 | 78 |
|
83 | | - # Calculate the number of transactions needed for the chunked publish to predict the code object address. |
84 | | - # Start by deriving the address assuming a single transaction for a preliminary build to estimate artifact size. |
85 | | - code_object_address = await CompileHelper.derive_object_address( |
86 | | - rest_client, alice.address() |
87 | | - ) |
88 | | - |
89 | | - print("\nCompiling package as a preliminary build...") |
90 | | - if AptosCLIWrapper.does_cli_exist(): |
91 | | - AptosCLIWrapper.compile_package( |
92 | | - large_package_example_dir, {module_name: code_object_address} |
93 | | - ) |
94 | | - else: |
95 | | - print(f"Address of the object to be created: {code_object_address}") |
96 | | - input( |
97 | | - "\nUpdate the module with the derived code object address, compile, and press enter." |
98 | | - ) |
99 | | - |
100 | | - metadata, modules = PublishHelper.load_package_artifacts(large_package_example_dir) |
101 | | - |
102 | | - # Number of transactions required for the chunked publish. |
103 | | - required_txns = len( |
104 | | - PublishHelper.prepare_chunked_payloads( |
105 | | - metadata, |
106 | | - modules, |
107 | | - large_packages_module_address, |
108 | | - PublishMode.OBJECT_DEPLOY, |
109 | | - ) |
110 | | - ) |
111 | | - |
112 | | - if required_txns > 1: |
113 | | - code_object_address = await CompileHelper.derive_object_address( |
114 | | - rest_client, alice.address(), required_txns |
115 | | - ) |
116 | | - print("\nCompiling the package with updated object address...") |
117 | | - if AptosCLIWrapper.does_cli_exist(): |
118 | | - AptosCLIWrapper.compile_package( |
119 | | - large_package_example_dir, {module_name: code_object_address} |
120 | | - ) |
121 | | - else: |
122 | | - print(f"Address of the object to be created: {code_object_address}") |
123 | | - input( |
124 | | - "\nUpdate the module with the derived code object address, compile, and press enter." |
125 | | - ) |
126 | | - |
127 | | - object_deploy_txn_hash = await publisher.publish_package_in_path( |
| 79 | + object_deploy_txn_hash = await publisher.compile_and_publish_move_package( |
128 | 80 | alice, |
129 | 81 | large_package_example_dir, |
| 82 | + module_name, |
130 | 83 | large_packages_module_address, |
131 | 84 | PublishMode.OBJECT_DEPLOY, |
132 | 85 | ) |
133 | 86 |
|
134 | 87 | print(f"The last tx submitted: {object_deploy_txn_hash[-1]}") |
135 | 88 | await rest_client.wait_for_transaction(object_deploy_txn_hash[-1]) |
136 | | - print(f"Package deployed to object {code_object_address}") |
137 | | - |
138 | | - # Example 3. Object code upgrade |
139 | | - print("=== Upgrading large package object ===") |
140 | | - |
141 | | - object_upgrade_txn_hash = await publisher.publish_package_in_path( |
142 | | - alice, |
143 | | - large_package_example_dir, |
144 | | - large_packages_module_address, |
145 | | - PublishMode.OBJECT_UPGRADE, |
146 | | - code_object_address, |
147 | | - ) |
| 89 | + print("Transaction completed.") |
148 | 90 |
|
149 | | - print(f"The last tx submitted: {object_upgrade_txn_hash[-1]}") |
150 | | - await rest_client.wait_for_transaction(object_upgrade_txn_hash[-1]) |
151 | | - print(f"Package in object {code_object_address} upgraded") |
152 | 91 | await rest_client.close() |
153 | 92 |
|
154 | 93 |
|
|
0 commit comments