From 4f7f7681c315c5d7af06739200facade672cd99b Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 18 Jan 2025 08:21:52 +0800 Subject: [PATCH] [doc] clean up (#15773) --- .../aptos-framework/doc/lite_account.md | 547 ------------------ .../aptos-framework/doc/token_bucket.md | 176 ------ 2 files changed, 723 deletions(-) delete mode 100644 aptos-move/framework/aptos-framework/doc/lite_account.md delete mode 100644 aptos-move/framework/aptos-framework/doc/token_bucket.md diff --git a/aptos-move/framework/aptos-framework/doc/lite_account.md b/aptos-move/framework/aptos-framework/doc/lite_account.md deleted file mode 100644 index fe595f286e68b..0000000000000 --- a/aptos-move/framework/aptos-framework/doc/lite_account.md +++ /dev/null @@ -1,547 +0,0 @@ - - - -# Module `0x1::lite_account` - - - -- [Struct `UpdateDispatchableAuthenticator`](#0x1_lite_account_UpdateDispatchableAuthenticator) -- [Struct `RemoveDispatchableAuthenticator`](#0x1_lite_account_RemoveDispatchableAuthenticator) -- [Resource `DispatchableAuthenticator`](#0x1_lite_account_DispatchableAuthenticator) -- [Constants](#@Constants_0) -- [Function `add_dispatchable_authentication_function`](#0x1_lite_account_add_dispatchable_authentication_function) -- [Function `remove_dispatchable_authentication_function`](#0x1_lite_account_remove_dispatchable_authentication_function) -- [Function `remove_dispatchable_authenticator`](#0x1_lite_account_remove_dispatchable_authenticator) -- [Function `resource_addr`](#0x1_lite_account_resource_addr) -- [Function `update_dispatchable_authenticator_impl`](#0x1_lite_account_update_dispatchable_authenticator_impl) -- [Function `using_dispatchable_authenticator`](#0x1_lite_account_using_dispatchable_authenticator) -- [Function `dispatchable_authenticator`](#0x1_lite_account_dispatchable_authenticator) -- [Function `dispatchable_authenticator_internal`](#0x1_lite_account_dispatchable_authenticator_internal) -- [Function `authenticate`](#0x1_lite_account_authenticate) -- [Function `dispatchable_authenticate`](#0x1_lite_account_dispatchable_authenticate) -- [Specification](#@Specification_1) - - [Function `dispatchable_authenticate`](#@Specification_1_dispatchable_authenticate) - - -
use 0x1::create_signer;
-use 0x1::error;
-use 0x1::event;
-use 0x1::function_info;
-use 0x1::object;
-use 0x1::option;
-use 0x1::signer;
-use 0x1::signing_data;
-use 0x1::simple_map;
-use 0x1::string;
-
- - - - - -## Struct `UpdateDispatchableAuthenticator` - - - -
#[event]
-struct UpdateDispatchableAuthenticator has drop, store
-
- - - -
-Fields - - -
-
-account: address -
-
- -
-
-update: vector<u8> -
-
- -
-
-auth_function: function_info::FunctionInfo -
-
- -
-
- - -
- - - -## Struct `RemoveDispatchableAuthenticator` - - - -
#[event]
-struct RemoveDispatchableAuthenticator has drop, store
-
- - - -
-Fields - - -
-
-account: address -
-
- -
-
- - -
- - - -## Resource `DispatchableAuthenticator` - -The dispatchable authenticator that defines how to authenticates this account in the specified module. -An integral part of Account Abstraction. - - -
#[resource_group_member(#[group = 0x1::object::ObjectGroup])]
-struct DispatchableAuthenticator has copy, drop, key
-
- - - -
-Fields - - -
-
-auth_functions: simple_map::SimpleMap<function_info::FunctionInfo, bool> -
-
- -
-
- - -
- - - -## Constants - - - - - - -
const MAX_U64: u128 = 18446744073709551615;
-
- - - - - - - -
const EAUTH_FUNCTION_SIGNATURE_MISMATCH: u64 = 3;
-
- - - - - - - -
const EDISPATCHABLE_AUTHENTICATOR_IS_NOT_USED: u64 = 1;
-
- - - - - - - -
const EFUNCTION_INFO_EXISTENCE: u64 = 2;
-
- - - - - - - -
const ENOT_MASTER_SIGNER: u64 = 4;
-
- - - - - -## Function `add_dispatchable_authentication_function` - -Update dispatchable authenticator that enables account abstraction. -Note: it is a private entry function that can only be called directly from transaction. - - -
public entry fun add_dispatchable_authentication_function(account: &signer, module_address: address, module_name: string::String, function_name: string::String)
-
- - - -
-Implementation - - -
public entry fun add_dispatchable_authentication_function(
-    account: &signer,
-    module_address: address,
-    module_name: String,
-    function_name: String,
-) acquires DispatchableAuthenticator {
-    //assert!(!is_permissioned_signer(account), error::permission_denied(ENOT_MASTER_SIGNER));
-    update_dispatchable_authenticator_impl(
-        account,
-        function_info::new_function_info_from_address(module_address, module_name, function_name),
-        true
-    );
-}
-
- - - -
- - - -## Function `remove_dispatchable_authentication_function` - - - -
public entry fun remove_dispatchable_authentication_function(account: &signer, module_address: address, module_name: string::String, function_name: string::String)
-
- - - -
-Implementation - - -
public entry fun remove_dispatchable_authentication_function(
-    account: &signer,
-    module_address: address,
-    module_name: String,
-    function_name: String,
-) acquires DispatchableAuthenticator {
-    //assert!(!is_permissioned_signer(account), error::permission_denied(ENOT_MASTER_SIGNER));
-    update_dispatchable_authenticator_impl(
-        account,
-        function_info::new_function_info_from_address(module_address, module_name, function_name),
-        false
-    );
-}
-
- - - -
- - - -## Function `remove_dispatchable_authenticator` - -Update dispatchable authenticator that disables account abstraction. -Note: it is a private entry function that can only be called directly from transaction. - - -
public entry fun remove_dispatchable_authenticator(account: &signer)
-
- - - -
-Implementation - - -
public entry fun remove_dispatchable_authenticator(
-    account: &signer,
-) acquires DispatchableAuthenticator {
-    //assert!(!is_permissioned_signer(account), error::permission_denied(ENOT_MASTER_SIGNER));
-    let addr = signer::address_of(account);
-    let resource_addr = resource_addr(addr);
-    if (exists<DispatchableAuthenticator>(resource_addr)) {
-        move_from<DispatchableAuthenticator>(resource_addr);
-        event::emit(RemoveDispatchableAuthenticator {
-            account: addr,
-        });
-    };
-}
-
- - - -
- - - -## Function `resource_addr` - - - -
fun resource_addr(source: address): address
-
- - - -
-Implementation - - -
inline fun resource_addr(source: address): address {
-    object::create_user_derived_object_address(source, @aptos_fungible_asset)
-}
-
- - - -
- - - -## Function `update_dispatchable_authenticator_impl` - - - -
public(friend) fun update_dispatchable_authenticator_impl(account: &signer, auth_function: function_info::FunctionInfo, is_add: bool)
-
- - - -
-Implementation - - -
public(friend) fun update_dispatchable_authenticator_impl(
-    account: &signer,
-    auth_function: FunctionInfo,
-    is_add: bool,
-) acquires DispatchableAuthenticator {
-    let addr = signer::address_of(account);
-    let resource_addr = resource_addr(addr);
-        let dispatcher_auth_function_info = function_info::new_function_info_from_address(
-            @aptos_framework,
-            string::utf8(b"lite_account"),
-            string::utf8(b"dispatchable_authenticate"),
-        );
-        assert!(
-            function_info::check_dispatch_type_compatibility(&dispatcher_auth_function_info, &auth_function),
-            error::invalid_argument(EAUTH_FUNCTION_SIGNATURE_MISMATCH)
-        );
-    if (is_add && !exists<DispatchableAuthenticator>(resource_addr)) {
-            move_to(&create_signer::create_signer(resource_addr), DispatchableAuthenticator {
-                auth_functions: simple_map::new()
-            });
-        };
-        if (exists<DispatchableAuthenticator>(resource_addr)) {
-            let current_map = &mut borrow_global_mut<DispatchableAuthenticator>(resource_addr).auth_functions;
-            if (is_add) {
-                assert!(!simple_map::contains_key(current_map, &auth_function), error::already_exists(EFUNCTION_INFO_EXISTENCE));
-                simple_map::add(current_map, auth_function, true);
-            } else {
-                assert!(simple_map::contains_key(current_map, &auth_function), error::not_found(EFUNCTION_INFO_EXISTENCE));
-                simple_map::remove(current_map, &auth_function);
-            };
-            event::emit(
-                UpdateDispatchableAuthenticator {
-                    account: addr,
-                    update: if (is_add) {b"add"} else {b"remove"},
-                    auth_function,
-                }
-            );
-            if (simple_map::length(current_map) == 0) {
-                remove_dispatchable_authenticator(account);
-            }
-        };
-}
-
- - - -
- - - -## Function `using_dispatchable_authenticator` - -Return true if the account is an abstracted account that can be authenticated with dispatchable move authenticator. - - -
#[view]
-public fun using_dispatchable_authenticator(addr: address): bool
-
- - - -
-Implementation - - -
public fun using_dispatchable_authenticator(addr: address): bool {
-    exists<DispatchableAuthenticator>(resource_addr(addr))
-}
-
- - - -
- - - -## Function `dispatchable_authenticator` - -Return the current dispatchable authenticator move function info. None means this authentication scheme is disabled. - - -
#[view]
-public fun dispatchable_authenticator(addr: address): option::Option<vector<function_info::FunctionInfo>>
-
- - - -
-Implementation - - -
public fun dispatchable_authenticator(addr: address): Option<vector<FunctionInfo>> acquires DispatchableAuthenticator {
-    let resource_addr = resource_addr(addr);
-    if (exists<DispatchableAuthenticator>(resource_addr)) {
-        option::some(
-            simple_map::keys(&borrow_global<DispatchableAuthenticator>(resource_addr).auth_functions)
-        )
-    } else { option::none() }
-}
-
- - - -
- - - -## Function `dispatchable_authenticator_internal` - - - -
fun dispatchable_authenticator_internal(addr: address): &simple_map::SimpleMap<function_info::FunctionInfo, bool>
-
- - - -
-Implementation - - -
inline fun dispatchable_authenticator_internal(addr: address): &SimpleMap<FunctionInfo, bool> {
-    assert!(using_dispatchable_authenticator(addr), error::not_found(EDISPATCHABLE_AUTHENTICATOR_IS_NOT_USED));
-    &borrow_global<DispatchableAuthenticator>(resource_addr(addr)).auth_functions
-}
-
- - - -
- - - -## Function `authenticate` - - - -
fun authenticate(account: signer, func_info: function_info::FunctionInfo, signing_data: signing_data::SigningData): signer
-
- - - -
-Implementation - - -
fun authenticate(
-    account: signer,
-    func_info: FunctionInfo,
-    signing_data: SigningData,
-): signer acquires DispatchableAuthenticator {
-    let func_infos = dispatchable_authenticator_internal(signer::address_of(&account));
-    assert!(simple_map::contains_key(func_infos, &func_info), error::not_found(EFUNCTION_INFO_EXISTENCE));
-    function_info::load_module_from_function(&func_info);
-    dispatchable_authenticate(account, signing_data, &func_info)
-}
-
- - - -
- - - -## Function `dispatchable_authenticate` - -The native function to dispatch customized move authentication function. - - -
fun dispatchable_authenticate(account: signer, signing_data: signing_data::SigningData, function: &function_info::FunctionInfo): signer
-
- - - -
-Implementation - - -
native fun dispatchable_authenticate(
-    account: signer,
-    signing_data: SigningData,
-    function: &FunctionInfo
-): signer;
-
- - - -
- - - -## Specification - - - -
pragma verify = false;
-
- - - - - -### Function `dispatchable_authenticate` - - -
fun dispatchable_authenticate(account: signer, signing_data: signing_data::SigningData, function: &function_info::FunctionInfo): signer
-
- - - - -
pragma opaque;
-
- - -[move-book]: https://aptos.dev/move/book/SUMMARY diff --git a/aptos-move/framework/aptos-framework/doc/token_bucket.md b/aptos-move/framework/aptos-framework/doc/token_bucket.md deleted file mode 100644 index 743721e304652..0000000000000 --- a/aptos-move/framework/aptos-framework/doc/token_bucket.md +++ /dev/null @@ -1,176 +0,0 @@ - - - -# Module `0x1::token_bucket` - - - -- [Resource `Bucket`](#0x1_token_bucket_Bucket) -- [Function `initialize_bucket`](#0x1_token_bucket_initialize_bucket) -- [Function `request`](#0x1_token_bucket_request) -- [Function `refill`](#0x1_token_bucket_refill) - - -
use 0x1::math64;
-use 0x1::timestamp;
-
- - - - - -## Resource `Bucket` - - - -
struct Bucket has copy, drop, store, key
-
- - - -
-Fields - - -
-
-capacity: u64 -
-
- -
-
-tokens: u64 -
-
- -
-
-refill_rate_per_minute: u64 -
-
- -
-
-last_refill_timestamp: u64 -
-
- -
-
-fractional_time_accumulated: u64 -
-
- -
-
- - -
- - - -## Function `initialize_bucket` - - - -
public fun initialize_bucket(capacity: u64): token_bucket::Bucket
-
- - - -
-Implementation - - -
public fun initialize_bucket(capacity: u64): Bucket {
-    let bucket = Bucket {
-        capacity,
-        tokens: capacity, // Start with a full bucket (full capacity of transactions allowed)
-        refill_rate_per_minute: capacity,
-        last_refill_timestamp: timestamp::now_seconds(),
-        fractional_time_accumulated: 0, // Start with no fractional time accumulated
-    };
-    bucket
-}
-
- - - -
- - - -## Function `request` - - - -
public fun request(bucket: &mut token_bucket::Bucket, num_token_requested: u64): bool
-
- - - -
-Implementation - - -
public fun request(bucket: &mut Bucket, num_token_requested: u64): bool {
-    refill(bucket);
-    if (bucket.tokens >= num_token_requested) {
-        bucket.tokens = bucket.tokens - num_token_requested;
-        true
-    } else {
-        false
-    }
-}
-
- - - -
- - - -## Function `refill` - - - -
fun refill(bucket: &mut token_bucket::Bucket)
-
- - - -
-Implementation - - -
fun refill(bucket: &mut Bucket) {
-    let current_time = timestamp::now_seconds();
-    let time_passed = current_time - bucket.last_refill_timestamp;
-
-    // Total time passed including fractional accumulated time
-    let total_time = time_passed + bucket.fractional_time_accumulated;
-
-    // Calculate the full tokens that can be added
-    let new_tokens = total_time * bucket.refill_rate_per_minute / 60;
-
-    // Calculate the remaining fractional time
-    let remaining_fractional_time = total_time % 60;
-
-    // Refill the bucket with the full tokens
-    if (new_tokens > 0) {
-        bucket.tokens = math64::min(bucket.tokens + new_tokens, bucket.capacity);
-        bucket.last_refill_timestamp = current_time;
-    };
-
-    // Update the fractional time accumulated for the next refill cycle
-    bucket.fractional_time_accumulated = remaining_fractional_time;
-}
-
- - - -
- - -[move-book]: https://aptos.dev/move/book/SUMMARY