Skip to content

Latest commit

 

History

History
386 lines (183 loc) · 12 KB

module_store.md

File metadata and controls

386 lines (183 loc) · 12 KB

Module 0x2::module_store

module_store provide object to manage packages and modules.

Resource Allowlist

Allowlist for module function invocation

struct Allowlist has store, key

Resource ModuleStore

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

Resource Package

Used to store modules. Modules are the Package's dynamic fields, with the module name as the key.

struct Package has key

Struct PackageData

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

Resource UpgradeCap

Package upgrade capability

struct UpgradeCap has store, key

Struct UpgradeEvent

Event for package upgrades. New published modules will also trigger this event.

struct UpgradeEvent has copy, drop, store

Constants

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;

Function module_store_id

Function init_module_store

Create a new module object space

public(friend) fun init_module_store()

Function issue_upgrade_cap_by_system

Issue an UpgradeCap for any package by the system accounts.

public fun issue_upgrade_cap_by_system(system: &signer, package_id: address, owner: address)

Function issue_upgrade_cap

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)

Function is_upgrade_cap_issued

public fun is_upgrade_cap_issued(package_id: address): bool

Function borrow_module_store

Function borrow_mut_module_store

Function package_obj_id

public fun package_obj_id(package_id: address): object::ObjectID

Function exists_package

public fun exists_package(package_id: address): bool

Function exists_module

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

Function publish_package_entry

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>)

Function package_version

public fun package_version(package_id: address): u64

Function publish_modules_internal

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

Function freeze_package

Function add_to_allowlist

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)

Function remove_from_allowlist

Remove a package id from the allowlist.

public fun remove_from_allowlist(account: &signer, package_id: address)

Function is_in_allowlist

Check if a package id is in the allowlist.

public fun is_in_allowlist(package_id: address): bool

Function has_upgrade_permission

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

Function ensure_upgrade_permission

Ensure the account has the permission to upgrade the package with the package_id.

public fun ensure_upgrade_permission(package_id: address, account: &signer)