### start Source: https://aptos-labs.github.io/framework-book/aptos-framework/chunky_dkg.html Starts a new Chunky DKG session. ```APIDOC ## Function `start` ### Description Initiates a new Chunky DKG session. This function likely takes parameters to define the session's properties and participants. ### Specification (Specification details are not provided in the source text.) ``` -------------------------------- ### start Source: https://aptos-labs.github.io/framework-book/aptos-framework/chunky_dkg.html Starts a new Chunky DKG session. ```APIDOC ## Function `start` ### Description Starts a new Chunky DKG session. ### Signature ``` public(friend) fun start(dealer_epoch: u64, chunky_dkg_config: chunky_dkg_config::ChunkyDKGConfig, dealer_validator_set: vector, target_validator_set: vector) ``` ### Parameters - `dealer_epoch` (u64): The epoch of the dealers. - `chunky_dkg_config` (chunky_dkg_config::ChunkyDKGConfig): The configuration for the Chunky DKG session. - `dealer_validator_set` (vector): The set of dealer validators. - `target_validator_set` (vector): The set of target validators. ### Aborts - If `ChunkyDKGState` does not exist. - If a session has already been started for the given `dealer_epoch`. - If `timestamp::CurrentTimeMicroseconds` does not exist. ### Ensures - A session is started for the given `dealer_epoch`. - If a session was already started, the `ChunkyDKGState` remains unchanged. ``` -------------------------------- ### start Source: https://aptos-labs.github.io/framework-book/aptos-framework/dkg.html Starts a new DKG session. This function is intended for internal use by the Aptos framework. ```APIDOC ## Function `start` ### Description Starts a new DKG session. ### Signature ``` public(friend) fun start(dealer_epoch: u64, randomness_config: randomness_config::RandomnessConfig, dealer_validator_set: vector, target_validator_set: vector) ``` ### Behavior - Aborts if `DKGState` does not exist. - Aborts if a session has already been started for the given `dealer_epoch` and `DKGState` does not exist. - Ensures that a session is started for the `dealer_epoch` after execution. - Ensures that the `DKGState` remains unchanged if a session was already started for the `dealer_epoch`. ``` -------------------------------- ### Entry Function Invocation Examples Source: https://aptos-labs.github.io/move-book/functions.html Demonstrates that `entry` functions can be called from other Move functions, scripts, and even other modules. This highlights their role as potential starting points for execution. ```move address 0x42 { module m { public entry fun foo() {} fun calls_foo() { foo(); } // valid! } module n { fun calls_m_foo() { 0x42::m::foo(); // valid! } } module other { public entry fun calls_m_foo() { 0x42::m::foo(); // valid! } } } script { fun calls_m_foo() { 0x42::m::foo(); // valid! } } ``` -------------------------------- ### Get Move Prover Help Source: https://aptos-labs.github.io/move-book/print.html Run this command to see all available options for the Move prover CLI. ```bash aptos move prove --help ``` -------------------------------- ### Example Move Script Source: https://aptos-labs.github.io/move-book/modules-and-packages.html This example demonstrates a simple Move script with a use declaration, a constant, and a main function that performs addition and prints the result using the debug module. ```move script { // Import the debug module published at the named account address std. use std::debug; const ONE: u64 = 1; fun main(x: u64) { let sum = x + ONE; debug::print(&sum) } } ``` -------------------------------- ### Start DKG Session Source: https://aptos-labs.github.io/framework-book/aptos-framework/dkg.html Starts a new DKG session with the provided parameters. Includes pre- and post-conditions for session state and epoch. ```move __ **public**(**friend**) **fun** start(dealer_epoch: u64, randomness_config: randomness_config::RandomnessConfig, dealer_validator_set: vector, target_validator_set: vector) ``` ```move __ **aborts_if** !**exists**(@aptos_framework); **aborts_if** !spec_is_session_started(dealer_epoch) && !**exists**(@aptos_framework); **ensures** spec_is_session_started(dealer_epoch); **ensures** **old**(spec_is_session_started(dealer_epoch)) ==> **global**(@aptos_framework) == **old**(**global**(@aptos_framework)); ``` -------------------------------- ### General Let Binding Grammar in Move Source: https://aptos-labs.github.io/move-book/print.html Provides examples of the general grammar for `let` statements in Move, illustrating patterns, type annotations, and initializers. ```move script { fun example() { let (x, y): (u64, u64) = (0, 1); // ^ local-variable // ^ pattern // ^ local-variable // ^ pattern // ^ pattern-list // ^^^^ pattern-list // ^^^^^^ pattern-or-list // ^^^^^^^^^^^^ type-annotation // ^^^^^^^^ initializer // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ let-binding let Foo { f, g: x } = Foo { f: 0, g: 1 }; // ^^^ struct-type // ^ field // ^ field-binding // ^ field // ^ local-variable // ^ pattern // ^^^^ field-binding // ^^^^^^^ field-binding-list // ^^^^^^^^^^^^^^^ pattern // ^^^^^^^^^^^^^^^ pattern-or-list // ^^^^^^^^^^^^^^^^^^^^ initializer // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ let-binding } } ``` -------------------------------- ### on_reconfig_start Source: https://aptos-labs.github.io/framework-book/aptos-framework/reconfiguration_state.html Called at the start of a reconfiguration. Sets the state to active and records the start time. ```APIDOC ## Function `on_reconfig_start` ### Description Called at the start of a reconfiguration. Sets the state to active and records the start time. ### Signature ``` public(friend) fun on_reconfig_start() ``` ### Requires - exists(@aptos_framework) ### Ensures - (exists(@aptos_framework) && copyable_any::type_name(pre_state.variant).bytes == b"0x1::reconfiguration_state::StateInactive") ==> copyable_any::type_name(post_state.variant).bytes == b"0x1::reconfiguration_state::StateActive" - (exists(@aptos_framework) && copyable_any::type_name(pre_state.variant).bytes == b"0x1::reconfiguration_state::StateInactive") ==> post_state.variant == state - (exists(@aptos_framework) && copyable_any::type_name(pre_state.variant).bytes == b"0x1::reconfiguration_state::StateInactive") ==> from_bcs::deserializable(post_state.variant.data) ``` -------------------------------- ### Example Move Function Declaration Source: https://aptos-labs.github.io/move-book/functions.html A concrete example illustrating the Move function declaration syntax with type parameters, parameters, and a return type. ```move fun foo(x: u64, y: T1, z: T2): (T2, T1, u64) { (z, y, x) } ``` -------------------------------- ### Spec Get Reconfig Start Time Function Source: https://aptos-labs.github.io/framework-book/aptos-framework/stake.html Provides a specification for getting the reconfiguration start time, returning the configured start time or the current time if no reconfiguration state exists. ```move __ **fun** spec_get_reconfig_start_time_secs(): u64 { **if** (**exists**(@aptos_framework)) { reconfiguration_state::spec_start_time_secs() } **else** { timestamp::spec_now_seconds() } } ``` -------------------------------- ### Get EventHandle GUID Source: https://aptos-labs.github.io/framework-book/aptos-framework/event.html Returns a reference to the GUID associated with an `EventHandle`. This function is deprecated. ```move public fun guid(handle_ref: &EventHandle): &GUID { &handle_ref.guid } ``` -------------------------------- ### Universally Instantiating a Lemma with Triggers Source: https://aptos-labs.github.io/move-book/print.html Shows how to use `forall...apply` to instantiate a lemma universally for all values of quantified variables, essential for loops or recursive functions. Triggers are provided to guide the SMT solver. ```spec fun sum_up_to(n: u64): u64 { if (n == 0) { 0 } else { n + sum_up_to(n - 1) } } spec sum_up_to { aborts_if sum(n) > MAX_U64; ensures result == sum(n); } proof { forall x: num, y: num {sum(x), sum(y)} apply monotonicity(x, y); } ``` -------------------------------- ### Get GUID Function Signature Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Defines the public function to retrieve the ID from a GUID reference. ```move # __ **public** **fun** id(guid: &guid::GUID): guid::ID ``` -------------------------------- ### Get Session Start Time Source: https://aptos-labs.github.io/framework-book/aptos-framework/chunky_dkg.html Retrieves the start time of a ChunkyDKGSessionState in microseconds. This indicates when the session was initiated. ```move __ **public** **fun** session_start_time(session: &ChunkyDKGSessionState): u64 { session.start_time_us } ``` -------------------------------- ### Get Reconfig Start Time Function Signature Source: https://aptos-labs.github.io/framework-book/aptos-framework/stake.html Declares the `get_reconfig_start_time_secs` function, which returns the reconfiguration start time in seconds. ```move __ **fun** get_reconfig_start_time_secs(): u64 ``` -------------------------------- ### Specification and post-conditions for `on_reconfig_start` Source: https://aptos-labs.github.io/framework-book/aptos-framework/reconfiguration_state.html Specifies the behavior and post-conditions for `on_reconfig_start`, including state transitions and data serialization. ```move __ **aborts_if** **false**; **requires** **exists**(@aptos_framework); **let** state = Any { type_name: type_info::type_name(), data: bcs::serialize(StateActive { start_time_secs: timestamp::spec_now_seconds() }) }; **let** pre_state = **global**(@aptos_framework); **let** **post** post_state = **global**(@aptos_framework); **ensures** (**exists**(@aptos_framework) && copyable_any::type_name(pre_state.variant).bytes == b"0x1::reconfiguration_state::StateInactive") ==> copyable_any::type_name(post_state.variant).bytes == b"0x1::reconfiguration_state::StateActive"; **ensures** (**exists**(@aptos_framework) && copyable_any::type_name(pre_state.variant).bytes == b"0x1::reconfiguration_state::StateInactive") ==> post_state.variant == state; **ensures** (**exists**(@aptos_framework) && copyable_any::type_name(pre_state.variant).bytes == b"0x1::reconfiguration_state::StateInactive") ==> from_bcs::deserializable(post_state.variant.data); ``` -------------------------------- ### Initialize with Defaults Source: https://aptos-labs.github.io/framework-book/aptos-framework/jwks.html Initializes the JWKS system with default OIDC providers and patches. Requires a signer. ```move __ **public** **fun** initialize_with_defaults(fx: &signer, providers: vector, patches: vector) ``` ```move __ **pragma** verify = **false**; ``` -------------------------------- ### Get Creation Number from GUID Function Signature Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Defines the public function to retrieve the creation number from a GUID reference. ```move # __ **public** **fun** creation_num(guid: &guid::GUID): u64 ``` -------------------------------- ### Get Reconfiguration Start Time (Move) Source: https://aptos-labs.github.io/framework-book/aptos-framework/stake.html Retrieves the start time of an ongoing reconfiguration. Returns the current time if no reconfiguration is in progress. ```move ___ **fun** get_reconfig_start_time_secs(): u64 ``` __ **fun** get_reconfig_start_time_secs(): u64 { **if** (reconfiguration_state::is_in_progress()) { reconfiguration_state::start_time_secs() } **else** { timestamp::now_seconds() } } ``` ``` -------------------------------- ### Get Creator Address from GUID Function Signature Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Defines the public function to retrieve the creator's address from a GUID reference. ```move # __ **public** **fun** creator_address(guid: &guid::GUID): **address** ``` -------------------------------- ### Initialize Governance Framework Source: https://aptos-labs.github.io/framework-book/aptos-framework/aptos_governance.html Initializes the governance framework with specified parameters. Ensures that certain governance-related resources do not already exist and that the signer address is aptos_framework. Includes checks for account limits and initializes various governance resources. ```move __ **fun** initialize(aptos_framework: &signer, min_voting_threshold: u128, required_proposer_stake: u64, voting_duration_secs: u64) ``` ```move __ **pragma** aborts_if_is_partial; **let** addr = signer::address_of(aptos_framework); **let** register_account = **global**(addr); **aborts_if** **exists**>(addr); **aborts_if** !type_info::spec_is_struct(); **include** InitializeAbortIf; **ensures** **exists**>(addr); **ensures** **exists**(addr); **ensures** **exists**(addr); **ensures** **exists**(addr); **ensures** **exists**(addr); **ensures** **exists**(addr); ``` -------------------------------- ### Create and Fund Account Source: https://aptos-labs.github.io/framework-book/aptos-framework/genesis.html Creates an account if it does not exist, or returns a signer for an existing account. It also registers the account for APT and mints APT if the balance is zero. ```move __ **fun** create_account(aptos_framework: &signer, account_address: **address**, balance: u64): signer { **let** account = **if** (account::exists_at(account_address)) { create_signer(account_address) } **else** { account::create_account(account_address) }; **if** (coin::balance(account_address) == 0) { coin::register(&account); aptos_coin::mint(aptos_framework, account_address, balance); }; account } ``` -------------------------------- ### Get Event Handle GUID Source: https://aptos-labs.github.io/framework-book/aptos-framework/event.html Retrieve the unique GUID associated with an EventHandle. This function is deprecated but useful for identifying event sources. ```move #[deprecated] public fun guid(handle_ref: &event::EventHandle): &guid::GUID ``` ```move // This enforces high-level requirement 5: aborts_if false; ``` -------------------------------- ### Show aptos move test help Source: https://aptos-labs.github.io/move-book/print.html Run this command to see all available options for the `aptos move test` command. ```bash $ aptos move test -h ``` -------------------------------- ### Function `creation_num` Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Gets the creation number from a `guid::GUID`. ```APIDOC ## Function `creation_num` ### Signature ``` public fun creation_num(guid: &guid::GUID): u64 ``` ### Description Returns the `creation_num` (a u64) from a `guid::GUID`. ``` -------------------------------- ### session_start_time Source: https://aptos-labs.github.io/framework-book/aptos-framework/chunky_dkg.html Gets the start time of a Chunky DKG session. ```APIDOC ## Function `session_start_time` ### Description Returns the timestamp when a Chunky DKG session began. ### Specification (Specification details are not provided in the source text.) ``` -------------------------------- ### initialize_aptos_coin Source: https://aptos-labs.github.io/framework-book/aptos-framework/genesis.html Genesis step 2: Initializes the Aptos coin, creating mint and burn capabilities and configuring coin conversion maps and pairings. ```APIDOC ## Function `initialize_aptos_coin` ### Description Genesis step 2: Initialize Aptos coin. ### Signature ``` __ **fun** initialize_aptos_coin(aptos_framework: &signer) ``` ``` -------------------------------- ### Get GUID Next Creation Number Source: https://aptos-labs.github.io/framework-book/aptos-framework/account.html Retrieves the next GUID creation number for an account. This is a view function and requires the account to exist. ```move __ #[view] **public** **fun** get_guid_next_creation_num(addr: **address**): u64 ``` ```move __ **aborts_if** !**exists**(addr); **ensures** result == **global**(addr).guid_creation_num; ``` -------------------------------- ### initialize Source: https://aptos-labs.github.io/framework-book/aptos-framework/code.html Initializes the package registry for a new package owner, ensuring the framework address is valid. ```APIDOC ## Function `initialize` ### Signature ```move fun initialize(aptos_framework: &signer, package_owner: &signer, metadata: code::PackageMetadata) ``` ### Implementation ```move let aptos_addr = signer::address_of(aptos_framework); let owner_addr = signer::address_of(package_owner); aborts_if !system_addresses::is_aptos_framework_address(aptos_addr); ensures exists(owner_addr); ``` ``` -------------------------------- ### Get ID from GUID Function Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Retrieves the non-privileged ID associated with a given GUID. This function is public and returns the ID struct directly. ```move __ **public** **fun** id(guid: &guid::GUID): guid::ID Implementation ``` __ **public** **fun** id(guid: &GUID): ID { guid.id } ``` ``` -------------------------------- ### Function `init` Source: https://aptos-labs.github.io/framework-book/aptos-token-objects/property_map.html Initializes a new PropertyMap resource. ```APIDOC ## Function `init` ``` public fun init(ref: &object::ConstructorRef, container: property_map::PropertyMap) ``` Implementation ``` public fun init(ref: &ConstructorRef, container: PropertyMap) { let signer = ref.generate_signer(); move_to(&signer, container); } ``` ``` -------------------------------- ### Get Event Handle GUID Source: https://aptos-labs.github.io/framework-book/aptos-framework/event.html Retrieves the unique GUID associated with an event handle. This function is useful for identifying the source or type of events. ```APIDOC ## Function `guid` ### Description Returns a reference to the unique GUID associated with the given `EventHandle`. This function is part of requirement 5, ensuring that the GUID can always be retrieved for an existing handle. ### Signature ```aptos public fun guid(handle_ref: &event::EventHandle): &guid::GUID ``` ### Pragmas ```aptos // This enforces high-level requirement 5: aborts_if false; ``` ``` -------------------------------- ### Function `new_configuration` Implementation Source: https://aptos-labs.github.io/framework-book/aptos-framework/keyless_account.html Implements the creation of a keyless account configuration by initializing a struct with provided parameters. ```move __ **public** **fun** new_configuration( override_aud_val: vector, max_signatures_per_txn: u16, max_exp_horizon_secs: u64, training_wheels_pubkey: Option>, max_commited_epk_bytes: u16, max_iss_val_bytes: u16, max_extra_field_bytes: u16, max_jwt_header_b64_bytes: u32 ): Configuration { Configuration { override_aud_vals: override_aud_val, max_signatures_per_txn, max_exp_horizon_secs, training_wheels_pubkey, max_commited_epk_bytes, max_iss_val_bytes, max_extra_field_bytes, max_jwt_header_b64_bytes, } } ``` -------------------------------- ### Basic Vector Operations Example Source: https://aptos-labs.github.io/move-book/print.html Demonstrates the creation of an empty vector, adding elements using `push_back`, accessing elements using `borrow`, and removing elements using `pop_back`. Asserts are used to verify the expected values. ```move script { use std::vector; fun example() { let v = vector::empty(); vector::push_back(&mut v, 5); vector::push_back(&mut v, 6); assert!(*vector::borrow(&v, 0) == 5, 42); assert!(*vector::borrow(&v, 1) == 6, 42); assert!(vector::pop_back(&mut v) == 6, 42); assert!(vector::pop_back(&mut v) == 5, 42); } } ``` -------------------------------- ### Module Declaration and Usage Example Source: https://aptos-labs.github.io/move-book/coding-conventions.html Demonstrates how to declare a module with structs, constants, and functions, and how to import and use them in another module. Ensure types are imported at the top level and functions are used fully qualified. ```move module 0x1::foo { struct Foo { } const CONST_FOO: u64 = 0; public fun do_foo(): Foo { Foo{} } // ... } ``` ```move module 0x1::bar { use 0x1::foo::{Self, Foo}; public fun do_bar(x: u64): Foo { if (x == 10) { foo::do_foo() } else { abort 0 } } // ... } ``` -------------------------------- ### Get Creation Number from GUID Function Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Returns the creation number associated with a GUID. This function is public and accesses the 'creation_num' field of the nested ID struct. ```move __ **public** **fun** creation_num(guid: &guid::GUID): u64 Implementation ``` __ **public** **fun** creation_num(guid: &GUID): u64 { guid.id.creation_num } ``` ``` -------------------------------- ### Get Creator Address from GUID Function Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Returns the account address that originally created the GUID. This function is public and accesses the 'addr' field of the nested ID struct. ```move __ **public** **fun** creator_address(guid: &guid::GUID): **address** Implementation ``` __ **public** **fun** creator_address(guid: &GUID): **address** { guid.id.addr } ``` ``` -------------------------------- ### initialize Source: https://aptos-labs.github.io/framework-book/aptos-framework/reconfiguration.html Initializes the Configuration resource under the aptos_framework account with specific initial values. This function ensures that the framework account has the necessary configuration to start operating. ```APIDOC ## Function `initialize` ### Description Initializes the Configuration resource under the aptos_framework account. This function is called once during module initialization and sets up the initial state for system configuration. ### Signature ```aptos public(friend) fun initialize(aptos_framework: &signer) ``` ### Behavior - Requires the signer address to be aptos_framework. - Ensures that the Account resource exists at the aptos_framework address. - Aborts if the `guid_creation_num` of the Account resource is not 2. - Aborts if a Configuration resource already exists at the aptos_framework address. - Ensures that a Configuration resource exists after execution. - Sets the initial `epoch` to 0 and `last_reconfiguration_time` to 0. - Initializes the `events` handle with a counter of 0 and a specific GUID. ``` -------------------------------- ### Function initialize Source: https://aptos-labs.github.io/framework-book/aptos-framework/version.html Initializes the version resource during genesis. Publishes the initial version and grants the aptos_framework account the capability to set future versions. ```APIDOC ## Function `initialize` Only called during genesis. Publishes the Version config. ``` __ **public**(**friend**) **fun** initialize(aptos_framework: &signer, initial_version: u64) ``` Implementation ``` __ **public**(**friend**) **fun** initialize(aptos_framework: &signer, initial_version: u64) { system_addresses::assert_aptos_framework(aptos_framework); **move_to**(**aptos_framework**, Version { major: initial_version }); // Give aptos framework account capability **to** call set version. This allows on chain governance **to** do it through // control of the aptos framework account. **move_to**(**aptos_framework**, SetVersionCapability {}); } ``` ``` -------------------------------- ### Get Keys Paginated from SmartTable Source: https://aptos-labs.github.io/framework-book/aptos-stdlib/smart_table.html Retrieves a paginated list of keys from the SmartTable, starting from a specified bucket and vector index. Returns the keys and the next starting indices for pagination. ```move __ **public** **fun** keys_paginated(self: &smart_table::SmartTable, starting_bucket_index: u64, starting_vector_index: u64, num_keys_to_get: u64): (vector, option::Option, option::Option) ``` ```move __ **pragma** verify = **false**; ``` -------------------------------- ### Get Reconfiguration Start Time Source: https://aptos-labs.github.io/framework-book/aptos-framework/reconfiguration_state.html Retrieves the Unix timestamp of when the current reconfiguration started. This function will abort with an error if no reconfiguration is in progress. It requires read access to the `State` resource. ```move __ **public**(**friend**) **fun** start_time_secs(): u64 **acquires** State { **let** state = **borrow_global**(@aptos_framework); **let** variant_type_name = *state.variant.type_name().bytes(); **if** (variant_type_name == b"0x1::reconfiguration_state::StateActive") { **let** active = state.variant.unpack(); active.start_time_secs } **else** { **abort**(error::invalid_state(ERECONFIG_NOT_IN_PROGRESS)) } } ``` -------------------------------- ### initialize Source: https://aptos-labs.github.io/framework-book/aptos-framework/randomness.html Initializes the randomness module, ensuring the signer address is the Aptos framework address. ```APIDOC ## Function `initialize` ### Description Initializes the randomness module. ### Signature ``` public fun initialize(framework: &signer) ``` ``` -------------------------------- ### Move Module with Literal Address Source: https://aptos-labs.github.io/move-book/modules-and-packages.html An example of a Move module named 'example' published under the literal account address '0x42'. It includes a struct, a use declaration, a friend declaration, a constant, and a public function. ```move module 0x42::example { struct Example has copy, drop { i: u64 } use std::debug; friend 0x42::another_example; const ONE: u64 = 1; public fun print(x: u64) { let sum = x + ONE; let example = Example { i: sum }; debug::print(&sum) } } ``` -------------------------------- ### Import Aptos Math Utilities Source: https://aptos-labs.github.io/framework-book/aptos-stdlib/math_fixed.html Imports necessary modules for fixed-point arithmetic and math operations within the Aptos framework. ```move __ **use** 0x1::error; **use** 0x1::fixed_point32; **use** 0x1::math128; ``` -------------------------------- ### Get Next GUID Creation Number Source: https://aptos-labs.github.io/framework-book/aptos-framework/account.html Retrieves the next GUID creation number for an address. Returns 0 for non-existent accounts if the feature flag is enabled, otherwise aborts. ```move __ #[view] **public** **fun** get_guid_next_creation_num(addr: **address**): u64 ``` __ **public** **fun** get_guid_next_creation_num(addr: **address**): u64 **acquires** Account { **if** (resource_exists_at(addr)) { Account[addr].guid_creation_num } **else** **if** (features::is_default_account_resource_enabled()) { 0 } **else** { **abort** error::not_found(EACCOUNT_DOES_NOT_EXIST) } } ``` ``` -------------------------------- ### Initialize Aptos Framework Source: https://aptos-labs.github.io/framework-book/aptos-framework/genesis.html Initializes the Aptos framework with various configuration parameters. This function sets up essential system resources and configurations required for the blockchain's operation. ```move __ **fun** initialize(gas_schedule: vector, chain_id: u8, initial_version: u64, consensus_config: vector, execution_config: vector, epoch_interval_microsecs: u64, minimum_stake: u64, maximum_stake: u64, recurring_lockup_duration_secs: u64, allow_validator_set_change: bool, rewards_rate: u64, rewards_rate_denominator: u64, voting_power_increase_limit: u64) ``` ```move __ **pragma** aborts_if_is_partial; **include** InitalizeRequires; // This enforces high-level requirement 2: **aborts_if** **exists**(@0x0); **aborts_if** **exists**(@0x2); **aborts_if** **exists**(@0x3); **aborts_if** **exists**(@0x4); **aborts_if** **exists**(@0x5); **aborts_if** **exists**(@0x6); **aborts_if** **exists**(@0x7); **aborts_if** **exists**(@0x8); **aborts_if** **exists**(@0x9); **aborts_if** **exists**(@0xa); **ensures** **exists**(@0x0); **ensures** **exists**(@0x2); **ensures** **exists**(@0x3); **ensures** **exists**(@0x4); **ensures** **exists**(@0x5); **ensures** **exists**(@0x6); **ensures** **exists**(@0x7); **ensures** **exists**(@0x8); **ensures** **exists**(@0x9); **ensures** **exists**(@0xa); // This enforces high-level requirement 1: **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); **ensures** **exists**(@aptos_framework); ``` -------------------------------- ### Get Basepoint (Generator) Source: https://aptos-labs.github.io/framework-book/aptos-stdlib/ristretto255.html Returns the basepoint (generator) of the Ristretto255 group. This is a standard starting point for cryptographic operations. ```move public fun basepoint(): ristretto255::RistrettoPoint ``` ```move public fun basepoint(): RistrettoPoint { let (handle, _) = point_decompress_internal(BASE_POINT); RistrettoPoint { handle } } ``` -------------------------------- ### Coin Struct Example Source: https://aptos-labs.github.io/move-book/print.html Demonstrates a `Coin` struct with `store` ability but without `copy` or `drop`, suitable for representing assets. ```move module 0x2::m { struct Coin has store { value: u64, } public fun mint(value: u64): Coin { Coin { value } } public fun withdraw(coin: &mut Coin, amount: u64): Coin { assert!(coin.value >= amount, 1000); coin.value = coin.value - amount; Coin { value: amount } } public fun deposit(coin: &mut Coin, other: Coin) { let Coin { value } = other; coin.value = coin.value + value; } public fun split(coin: Coin, amount: u64): (Coin, Coin) { let other = withdraw(&mut coin, amount); (coin, other) } public fun merge(coin1: Coin, coin2: Coin): Coin { deposit(&mut coin1, coin2); coin1 } public fun destroy_zero(coin: Coin) { let Coin { value } = coin; assert!(value == 0, 1001); } } ``` -------------------------------- ### initialize Source: https://aptos-labs.github.io/framework-book/aptos-framework/staking_config.html Initializes the StakingConfig and StakingRewardsConfig for the Aptos framework. Requires the caller to be the aptos_framework signer and enforces various constraints on stake limits, lockup durations, and rewards rates. ```APIDOC ## initialize ### Description Initializes the StakingConfig and StakingRewardsConfig for the Aptos framework. Requires the caller to be the aptos_framework signer and enforces various constraints on stake limits, lockup durations, and rewards rates. ### Method public fun initialize(aptos_framework: &signer, minimum_stake: u64, maximum_stake: u64, recurring_lockup_duration_secs: u64, allow_validator_set_change: bool, rewards_rate: u64, rewards_rate_denominator: u64, voting_power_increase_limit: u64) ### Parameters - **aptos_framework** (&signer) - The signer for the Aptos framework. - **minimum_stake** (u64) - The minimum stake amount. - **maximum_stake** (u64) - The maximum stake amount. - **recurring_lockup_duration_secs** (u64) - The duration of the recurring lockup in seconds. - **allow_validator_set_change** (bool) - Whether changes to the validator set are allowed. - **rewards_rate** (u64) - The numerator of the rewards rate. - **rewards_rate_denominator** (u64) - The denominator of the rewards rate. - **voting_power_increase_limit** (u64) - The limit for voting power increase in each epoch (0-50%). ### Aborts - If `minimum_stake` > `maximum_stake` or `maximum_stake` == 0. - If `recurring_lockup_duration_secs` == 0. - If `rewards_rate_denominator` == 0. - If `voting_power_increase_limit` == 0 or > 50. - If `rewards_rate` > `MAX_REWARDS_RATE`. - If `rewards_rate` > `rewards_rate_denominator`. - If `StakingConfig` already exists. - If `StakingRewardsConfig` already exists. ### Ensures - `StakingConfig` exists. - `StakingRewardsConfig` exists. ``` -------------------------------- ### Function to Get Start Index for New R Values Source: https://aptos-labs.github.io/framework-book/aptos-framework/sigma_protocol_key_rotation.html The `get_start_idx_for_new_R` function calculates and returns the starting index for the new R values ($\widetilde{R}_i$) in the statement's points vector. This index is determined by adding the number of available chunks to the starting index of the old R values. ```move __ **fun** get_start_idx_for_new_R(): u64 ``` ```move inline **fun** get_start_idx_for_new_R(): u64 { START_IDX_OLD_R + get_num_available_chunks() } ``` -------------------------------- ### Manually Unpacking a Resource in Move Source: https://aptos-labs.github.io/move-book/print.html Shows how to manually unpack a resource within its defining module to handle its destruction, resolving the error from the previous example. ```move module 0x2::m { struct Foo { x: u64 } public fun destroying_resource1_fixed() { let foo = Foo { x: 100 }; let Foo { x: _ } = foo; } } ``` -------------------------------- ### Defining Basic Structs in Move Source: https://aptos-labs.github.io/move-book/print.html Shows how to define structs with different field types and empty structs within a module. Includes examples of valid and invalid struct names. ```move module 0x2::m { struct Foo { x: u64, y: bool } struct Bar {} struct Baz { foo: Foo, } // ^ note: it is fine to have a trailing comma } module 0x2::m { struct Foo { x: Foo } // ^ error! Foo cannot contain Foo } module 0x2::m { struct Foo {} struct BAR {} struct B_a_z_4_2 {} } ``` -------------------------------- ### Create Resource Account and Publish Package Source: https://aptos-labs.github.io/framework-book/aptos-framework/resource_account.html Creates a new resource account, publishes a package under it, and makes the signer capability available. ```move __public__ entry __fun__ create_resource_account_and_publish_package(origin: &signer, seed: vector, metadata_serialized: vector, code: vector>) ``` ```move __public__ entry __fun__ create_resource_account_and_publish_package( origin: &signer, seed: vector, metadata_serialized: vector, code: vector> ) __acquires__ Container { __let__ (resource, resource_signer_cap) = account::create_resource_account(origin, seed); aptos_framework::code::publish_package_txn(&resource, metadata_serialized, code); rotate_account_authentication_key_and_store_capability( origin, resource, resource_signer_cap, ZERO_AUTH_KEY ); } ``` -------------------------------- ### Get Vesting Start Timestamp Function Source: https://aptos-labs.github.io/framework-book/aptos-framework/vesting.html Returns the vesting start timestamp in seconds for a given vesting contract. Vesting distributions begin after this timestamp plus a full period. The function requires the vesting contract to exist and acquires the VestingContract resource. ```move __ #[view] **public** **fun** vesting_start_secs(vesting_contract_address: **address**): u64 ``` ```move **public** **fun** vesting_start_secs(vesting_contract_address: **address**): u64 **acquires** VestingContract { assert_vesting_contract_exists(vesting_contract_address); **borrow_global**(vesting_contract_address).vesting_schedule.start_timestamp_secs } ``` -------------------------------- ### Get Creation Number from ID Function Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Returns the creation number associated with a guid::ID. This function is public and directly accesses the 'creation_num' field of the ID struct. ```move __ **public** **fun** id_creation_num(id: &guid::ID): u64 Implementation ``` __ **public** **fun** id_creation_num(id: &ID): u64 { id.creation_num } ``` ``` -------------------------------- ### initialize Source: https://aptos-labs.github.io/framework-book/aptos-framework/version.html Initializes the Version resource and SetVersionCapability under the aptos framework account. This function can only be called during genesis and enforces that the signer is the aptos framework account. ```APIDOC ## Function `initialize` ### Description Initializes the Version resource and SetVersionCapability under the aptos framework account. ### Signature `public fun initialize(aptos_framework: &signer, initial_version: u64)` ### Aborts - If the Version resource already exists in `@aptos_framework`. - If the SetVersionCapability resource already exists in `@aptos_framework`. - If the signer is not the aptos framework account. ``` -------------------------------- ### Function with Typed Parameters Source: https://aptos-labs.github.io/move-book/print.html Illustrates the declaration of function parameters with local variable names and type annotations. This example shows a simple addition function taking two `u64` parameters. ```move module 0x42::example { fun add(x: u64, y: u64): u64 { x + y } } ``` -------------------------------- ### Aptos Framework Genesis Initialize Function Implementation Source: https://aptos-labs.github.io/framework-book/aptos-framework/genesis.html The implementation of the `initialize` function sets up the Aptos framework by creating reserved accounts, initializing core modules like transaction validation, governance, consensus, execution, versioning, staking, gas schedules, and chain ID. It also configures transaction limits based on APT amounts. ```move __ **fun** initialize( gas_schedule: vector, chain_id: u8, initial_version: u64, consensus_config: vector, execution_config: vector, epoch_interval_microsecs: u64, minimum_stake: u64, maximum_stake: u64, recurring_lockup_duration_secs: u64, allow_validator_set_change: bool, rewards_rate: u64, rewards_rate_denominator: u64, voting_power_increase_limit: u64, ) { // Initialize the aptos framework account. This is the account **where** system resources and modules will be // deployed **to**. This will be entirely managed by on-chain governance and no entities have the key or privileges // **to** **use** this account. **let** (aptos_framework_account, aptos_framework_signer_cap) = account::create_framework_reserved_account(@aptos_framework); // Initialize account configs on aptos framework account. account::initialize(&aptos_framework_account); transaction_validation::initialize( &aptos_framework_account, b"script_prologue", b"module_prologue", b"multi_agent_script_prologue", b"epilogue", ); // Give the decentralized on-chain governance control over the core framework account. aptos_governance::store_signer_cap(&aptos_framework_account, @aptos_framework, aptos_framework_signer_cap); // put reserved framework reserved accounts under aptos governance **let** framework_reserved_addresses = vector<**address**>[@0x2, @0x3, @0x4, @0x5, @0x6, @0x7, @0x8, @0x9, @0xa]; **while** (!framework_reserved_addresses.is_empty()) { **let** **address** = framework_reserved_addresses.pop_back(); **let** (_, framework_signer_cap) = account::create_framework_reserved_account(**address**); aptos_governance::store_signer_cap(&aptos_framework_account, **address**, framework_signer_cap); }; consensus_config::initialize(&aptos_framework_account, consensus_config); execution_config::set(&aptos_framework_account, execution_config); version::initialize(&aptos_framework_account, initial_version); stake::initialize(&aptos_framework_account); stake::initialize_pending_transaction_fee(&aptos_framework_account); timestamp::set_time_has_started(&aptos_framework_account); staking_config::initialize( &aptos_framework_account, minimum_stake, maximum_stake, recurring_lockup_duration_secs, allow_validator_set_change, rewards_rate, rewards_rate_denominator, voting_power_increase_limit, ); storage_gas::initialize(&aptos_framework_account); gas_schedule::initialize(&aptos_framework_account, gas_schedule); // Ensure we can create aggregators for supply, but not enable it for common **use** just yet. aggregator_factory::initialize_aggregator_factory(&aptos_framework_account); chain_id::initialize(&aptos_framework_account, chain_id); reconfiguration::initialize(&aptos_framework_account); block::initialize(&aptos_framework_account, epoch_interval_microsecs); state_storage::initialize(&aptos_framework_account); nonce_validation::initialize(&aptos_framework_account); transaction_limits::initialize( &aptos_framework_account, // Execution tiers: // 2x: 1M APT // 4x: 5M APT // 8x: 10M APT vector[ transaction_limits::new_tier(1_000_000_0000_0000, 200), transaction_limits::new_tier(5_000_000_0000_0000, 400), transaction_limits::new_tier(10_000_000_0000_0000, 800), ], // IO tiers: // 2x: 5M APT // 4x: 10M APT // 8x: 20M APT vector[ transaction_limits::new_tier(5_000_000_0000_0000, 200), transaction_limits::new_tier(10_000_000_0000_0000, 400), transaction_limits::new_tier(20_000_000_0000_0000, 800), ], ); } ``` -------------------------------- ### Get Creator Address from ID Function Source: https://aptos-labs.github.io/framework-book/aptos-framework/guid.html Returns the account address that created the guid::ID. This function is public and directly accesses the 'addr' field of the ID struct. ```move __ **public** **fun** id_creator_address(id: &guid::ID): **address** Implementation ``` __ **public** **fun** id_creator_address(id: &ID): **address** { id.addr } ``` ``` -------------------------------- ### Initialize a New Move Package Source: https://aptos-labs.github.io/move-book/cli.html Scaffolds a new Move package, setting up the basic directory structure and configuration files. ```bash aptos move init ```