Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Module 0x1::randomness_api_v0_config

use 0x1::chain_status;
use 0x1::config_buffer;
use 0x1::option;
use 0x1::system_addresses;

Resource RequiredGasDeposit

struct RequiredGasDeposit has drop, store, key
Fields
gas_amount: option::Option<u64>

Resource AllowCustomMaxGasFlag

If this flag is set, max_gas specified inside #[randomness()] will be used as the required deposit.

struct AllowCustomMaxGasFlag has drop, store, key
Fields
value: bool

Function initialize

Only used in genesis.

fun initialize(framework: &signer, required_amount: randomness_api_v0_config::RequiredGasDeposit, allow_custom_max_gas_flag: randomness_api_v0_config::AllowCustomMaxGasFlag)
Implementation
fun initialize(framework: &signer, required_amount: RequiredGasDeposit, allow_custom_max_gas_flag: AllowCustomMaxGasFlag) {
    system_addresses::assert_aptos_framework(framework);
    chain_status::assert_genesis();
    move_to(framework, required_amount);
    move_to(framework, allow_custom_max_gas_flag);
}

Function set_for_next_epoch

This can be called by on-chain governance to update RequiredGasDeposit for the next epoch.

public fun set_for_next_epoch(framework: &signer, gas_amount: option::Option<u64>)
Implementation
public fun set_for_next_epoch(framework: &signer, gas_amount: Option<u64>) {
    system_addresses::assert_aptos_framework(framework);
    config_buffer::upsert(RequiredGasDeposit { gas_amount });
}

Function set_allow_max_gas_flag_for_next_epoch

This can be called by on-chain governance to update AllowCustomMaxGasFlag for the next epoch.

public fun set_allow_max_gas_flag_for_next_epoch(framework: &signer, value: bool)
Implementation
public fun set_allow_max_gas_flag_for_next_epoch(framework: &signer, value: bool) {
    system_addresses::assert_aptos_framework(framework);
    config_buffer::upsert(AllowCustomMaxGasFlag { value } );
}

Function on_new_epoch

Only used in reconfigurations to apply the pending RequiredGasDeposit, if there is any.

public fun on_new_epoch(framework: &signer)
Implementation
public fun on_new_epoch(framework: &signer) acquires RequiredGasDeposit, AllowCustomMaxGasFlag {
    system_addresses::assert_aptos_framework(framework);
    if (config_buffer::does_exist<RequiredGasDeposit>()) {
        let new_config = config_buffer::extract_v2<RequiredGasDeposit>();
        if (exists<RequiredGasDeposit>(@aptos_framework)) {
            *borrow_global_mut<RequiredGasDeposit>(@aptos_framework) = new_config;
        } else {
            move_to(framework, new_config);
        }
    };
    if (config_buffer::does_exist<AllowCustomMaxGasFlag>()) {
        let new_config = config_buffer::extract_v2<AllowCustomMaxGasFlag>();
        if (exists<AllowCustomMaxGasFlag>(@aptos_framework)) {
            *borrow_global_mut<AllowCustomMaxGasFlag>(@aptos_framework) = new_config;
        } else {
            move_to(framework, new_config);
        }
    }
}

Specification

pragma verify = false;