module_store
provide object to manage packages and modules.
- Resource
Allowlist
- Resource
ModuleStore
- Resource
Package
- Struct
PackageData
- Resource
UpgradeCap
- Struct
UpgradeEvent
- Constants
- Function
module_store_id
- Function
init_module_store
- Function
issue_upgrade_cap_by_system
- Function
issue_upgrade_cap
- Function
is_upgrade_cap_issued
- Function
borrow_module_store
- Function
borrow_mut_module_store
- Function
package_obj_id
- Function
exists_package
- Function
exists_module
- Function
publish_package_entry
- Function
package_version
- Function
publish_modules_internal
- Function
freeze_package
- Function
add_to_allowlist
- Function
remove_from_allowlist
- Function
is_in_allowlist
- Function
has_upgrade_permission
- Function
ensure_upgrade_permission
use 0x1::string;
use 0x1::vector;
use 0x2::bcs;
use 0x2::core_addresses;
use 0x2::event;
use 0x2::features;
use 0x2::move_module;
use 0x2::object;
use 0x2::signer;
use 0x2::tx_context;
Allowlist for module function invocation
struct Allowlist has store, key
Used to store packages. A package is an Object, and the package id is the module address. Packages are child objects of ModuleStore.
struct ModuleStore has key
Used to store modules. Modules are the Package's dynamic fields, with the module name as the key.
struct Package has key
This is a data struct to store package data, which is the same with the Rust definition. When building package, the package data will be stored in this struct and be serialized, we then deserialize package in Move.
#[data_struct]
struct PackageData has copy, drop, store
Package upgrade capability
struct UpgradeCap has store, key
Event for package upgrades. New published modules will also trigger this event.
struct UpgradeEvent has copy, drop, store
Have no permission to upgrade package
const ErrorNoUpgradePermission: u64 = 2;
Not allow to publish module
const ErrorNotAllowToPublish: u64 = 1;
Upgrade cap issued already
const ErrorUpgradeCapIssued: u64 = 3;
public fun module_store_id(): object::ObjectID
Create a new module object space
public(friend) fun init_module_store()
Issue an UpgradeCap for any package by the system accounts.
public fun issue_upgrade_cap_by_system(system: &signer, package_id: address, owner: address)
Issue an UpgradeCap for package under the sender's account. Then transfer the ownership to the owner. This is used to issue an upgrade cap before first publishing.
public fun issue_upgrade_cap(sender: &signer, owner: address)
public fun is_upgrade_cap_issued(package_id: address): bool
public fun borrow_module_store(): &object::Object<module_store::ModuleStore>
public fun borrow_mut_module_store(): &mut object::Object<module_store::ModuleStore>
public fun package_obj_id(package_id: address): object::ObjectID
public fun exists_package(package_id: address): bool
Check if module exists package_id: the address of the package name: the name of the module
public fun exists_module(package_id: address, name: string::String): bool
Entry function to publish package The order of modules must be sorted by dependency order.
public entry fun publish_package_entry(account: &signer, package_bytes: vector<u8>)
public fun package_version(package_id: address): u64
Publish modules to the module object's storage Return true if the modules are upgraded
public(friend) fun publish_modules_internal(module_store_object: &mut object::Object<module_store::ModuleStore>, package_id: address, modules: vector<move_module::MoveModule>): bool
public fun freeze_package(package: object::Object<module_store::Package>)
Add a package id to the allowlist. Only package id in allowlist can publish modules. This is only valid when module_publishing_allowlist_enabled feature is enabled.
public fun add_to_allowlist(account: &signer, package_id: address)
Remove a package id from the allowlist.
public fun remove_from_allowlist(account: &signer, package_id: address)
Check if a package id is in the allowlist.
public fun is_in_allowlist(package_id: address): bool
Check if the account has the permission to upgrade the package with the package_id.
public fun has_upgrade_permission(package_id: address, account: address): bool
Ensure the account has the permission to upgrade the package with the package_id.
public fun ensure_upgrade_permission(package_id: address, account: &signer)