starcoin-framework

Module 0x1::ModuleUpgradeScripts

use 0x1::Config;
use 0x1::Errors;
use 0x1::Option;
use 0x1::PackageTxnManager;
use 0x1::Signer;
use 0x1::UpgradeModuleDaoProposal;
use 0x1::Version;

Constants

const ERR_WRONG_UPGRADE_STRATEGY: u64 = 100;

Function propose_module_upgrade_v2

public entry fun propose_module_upgrade_v2<Token: copy, drop, store>(signer: signer, module_address: address, package_hash: vector<u8>, version: u64, exec_delay: u64, enforced: bool)
Implementation
public entry fun propose_module_upgrade_v2<Token: copy + drop + store>(
    signer: signer,
    module_address: address,
    package_hash: vector<u8>,
    version: u64,
    exec_delay: u64,
    enforced: bool,
) {
    UpgradeModuleDaoProposal::propose_module_upgrade_v2<Token>(
        &signer,
        module_address,
        package_hash,
        version,
        exec_delay,
        enforced
    );
}

Function update_module_upgrade_strategy

Update sender’s module upgrade strategy to strategy

public entry fun update_module_upgrade_strategy(sender: signer, strategy: u8)
Implementation
public entry fun update_module_upgrade_strategy(
    sender: signer,
    strategy: u8,
) {
    // 1. check version
    if (strategy == PackageTxnManager::get_strategy_two_phase()) {
        if (!Config::config_exist_by_address<Version::Version>(Signer::address_of(&sender))) {
            Config::publish_new_config<Version::Version>(&sender, Version::new_version(1));
        }
    };

    // 2. update strategy
    PackageTxnManager::update_module_upgrade_strategy(
        &sender,
        strategy,
        Option::none<u64>(),
    );
}

Function update_module_upgrade_strategy_with_min_time

Update sender’s module upgrade strategy to strategy with min_time_limit. This can only be invoked when strategy is STRATEGY_TWO_PHASE.

public entry fun update_module_upgrade_strategy_with_min_time(sender: signer, strategy: u8, min_time_limit: u64)
Implementation
public entry fun update_module_upgrade_strategy_with_min_time(
    sender: signer,
    strategy: u8,
    min_time_limit: u64,
){
    // 1. check version
    assert!(strategy == PackageTxnManager::get_strategy_two_phase(), Errors::invalid_argument(ERR_WRONG_UPGRADE_STRATEGY));
    // 2. update strategy
    PackageTxnManager::update_module_upgrade_strategy(
        &sender,
        strategy,
        Option::some<u64>(min_time_limit),
    );
}

Function submit_module_upgrade_plan

a alias of execute_module_upgrade_plan_propose, will deprecated in the future.

public entry fun submit_module_upgrade_plan<Token: copy, drop, store>(sender: signer, proposer_address: address, proposal_id: u64)
Implementation
public entry fun submit_module_upgrade_plan<Token: copy + drop + store>(
    sender: signer,
    proposer_address: address,
    proposal_id: u64,
) {
    Self::execute_module_upgrade_plan_propose<Token>(sender, proposer_address, proposal_id);
}

Function execute_module_upgrade_plan_propose

Execute module upgrade plan propose by submit module upgrade plan, the propose must been agreed, and anyone can execute this function.

public entry fun execute_module_upgrade_plan_propose<Token: copy, drop, store>(_sender: signer, proposer_address: address, proposal_id: u64)
Implementation
public entry fun execute_module_upgrade_plan_propose<Token: copy + drop + store>(
    _sender: signer,
    proposer_address: address,
    proposal_id: u64,
) {
    UpgradeModuleDaoProposal::submit_module_upgrade_plan<Token>(proposer_address, proposal_id);
}
Specification
pragma verify = false;

Function submit_upgrade_plan

Directly submit a upgrade plan, the sender’s module upgrade plan must been PackageTxnManager::STRATEGY_TWO_PHASE and have UpgradePlanCapability

public entry fun submit_upgrade_plan(sender: signer, package_hash: vector<u8>, version: u64, enforced: bool)
Implementation
public entry fun submit_upgrade_plan(sender: signer, package_hash: vector<u8>, version:u64, enforced: bool) {
    PackageTxnManager::submit_upgrade_plan_v2(&sender, package_hash, version, enforced);
}
Specification
pragma verify = false;

Function cancel_upgrade_plan

Cancel current upgrade plan, the sender must have UpgradePlanCapability.

public entry fun cancel_upgrade_plan(signer: signer)
Implementation
public entry fun cancel_upgrade_plan(
    signer: signer,
) {
    PackageTxnManager::cancel_upgrade_plan(&signer);
}
Specification
pragma verify = false;

Module Specification

pragma verify = false;
pragma aborts_if_is_partial = false;
pragma aborts_if_is_strict = true;