Module 0xf0b20e8fe3907b72b00d66e898e508b1f652eaa67f4defd99346123ea5ee8afd::large_packages
@title Large Packages Uploader
@author Aptos
@notice This provides a framework for uploading large packages to standard accounts or objects.
In each pass, the caller pushes more code by calling stage_code_chunk
.
In the final call, the caller can use stage_code_chunk_and_publish_to_account
, stage_code_chunk_and_publish_to_object
, or
stage_code_chunk_and_upgrade_object_code
to upload the final data chunk and publish or upgrade the package on-chain.
Note that code_indices
must not have gaps. For example, if code_indices
are provided as [0, 1, 3]
(skipping index 2), the inline function assemble_module_code
will abort. This is because StagingArea.last_module_idx
is set to the maximum value from code_indices
. When assemble_module_code
iterates over the range from 0 to
StagingArea.last_module_idx
, it expects each index to be present in the StagingArea.code
SmartTable.
Any missing index in this range will cause the function to fail.
- Resource
StagingArea
- Constants
- Function
stage_code_chunk
- Function
stage_code_chunk_and_publish_to_account
- Function
stage_code_chunk_and_publish_to_object
- Function
stage_code_chunk_and_upgrade_object_code
- Function
cleanup_staging_area
use 0x1::code;
use 0x1::error;
use 0x1::object;
use 0x1::object_code_deployment;
use 0x1::signer;
use 0x1::smart_table;
use 0x1::vector;
Resource StagingArea
@notice Storage for staging package code before publishing
struct StagingArea has key
Constants
@notice Error code when code_indices and code_chunks have different lengths
const ECODE_MISMATCH: u64 = 1;
@notice Error code when object reference is missing when upgrading object code
const EMISSING_OBJECT_REFERENCE: u64 = 2;
Function stage_code_chunk
@notice Stages a chunk of code for later publishing @param owner The account that will store the staging area @param metadata_chunk Metadata for the package (or empty vector if not the first chunk) @param code_indices Indices indicating the position of each code chunk @param code_chunks The actual code chunks to stage
public entry fun stage_code_chunk(owner: &signer, metadata_chunk: vector<u8>, code_indices: vector<u16>, code_chunks: vector<vector<u8>>)
Function stage_code_chunk_and_publish_to_account
@notice Stages the final code chunk and publishes the package to an account @param owner The account that will own the package @param metadata_chunk Final metadata for the package (or empty vector) @param code_indices Indices indicating the position of each code chunk @param code_chunks The actual code chunks to stage
public entry fun stage_code_chunk_and_publish_to_account(owner: &signer, metadata_chunk: vector<u8>, code_indices: vector<u16>, code_chunks: vector<vector<u8>>)
Function stage_code_chunk_and_publish_to_object
@notice Stages the final code chunk and publishes the package to an object @param owner The account that will own the object @param metadata_chunk Final metadata for the package (or empty vector) @param code_indices Indices indicating the position of each code chunk @param code_chunks The actual code chunks to stage
public entry fun stage_code_chunk_and_publish_to_object(owner: &signer, metadata_chunk: vector<u8>, code_indices: vector<u16>, code_chunks: vector<vector<u8>>)
Function stage_code_chunk_and_upgrade_object_code
@notice Stages the final code chunk and upgrades an existing object package @param owner The account that owns the object @param metadata_chunk Final metadata for the package (or empty vector) @param code_indices Indices indicating the position of each code chunk @param code_chunks The actual code chunks to stage @param code_object The object with the PackageRegistry to upgrade
public entry fun stage_code_chunk_and_upgrade_object_code(owner: &signer, metadata_chunk: vector<u8>, code_indices: vector<u16>, code_chunks: vector<vector<u8>>, code_object: object::Object<code::PackageRegistry>)
Function cleanup_staging_area
@notice Cleans up the staging area after publishing or if aborting the process @param owner The account that owns the staging area
public entry fun cleanup_staging_area(owner: &signer)