Skip to content

Latest commit

 

History

History
397 lines (188 loc) · 17.4 KB

move_module.md

File metadata and controls

397 lines (188 loc) · 17.4 KB

Module 0x2::move_module

move_module wraps module bytes and provides some basic functions for handle Move module in Move.

Struct MoveModule

struct MoveModule has copy, drop, store

Constants

Module address is not the same as the signer

Vector length not match

const ErrorLengthNotMatch: u64 = 4;

Module incompatible with the old ones.

const ErrorModuleIncompatible: u64 = 3;

Module verification error

Function new

public fun new(byte_codes: vector<u8>): move_module::MoveModule

Function new_batch

public fun new_batch(byte_codes_batch: vector<vector<u8>>): vector<move_module::MoveModule>

Function into_byte_codes_batch

Function module_id

Function sort_and_verify_modules

Sort modules by dependency order and then verify. Return their names and names of the modules with init function if sorted dependency order. This function will ensure the module's bytecode is valid and the module id is matching the module object address. Return

  1. Module names of all the modules. Order of names is not matching the input, but sorted by module dependency order
  2. Module names of the modules with init function.
  3. Indices in input modules of each sorted modules.
public fun sort_and_verify_modules(modules: &vector<move_module::MoveModule>, account_address: address): (vector<string::String>, vector<string::String>, vector<u64>)

Function check_comatibility

Check module compatibility when upgrading Abort if the new module is not compatible with the old module.

Function binding_module_address

Binding given module's address to the new address

public fun binding_module_address(modules: vector<move_module::MoveModule>, old_address: address, new_address: address): vector<move_module::MoveModule>

Function replace_module_identiner

Replace given module's identifier to the new ones

Function replace_struct_identifier

Replace given struct's identifier to the new ones

Function replace_constant_string

Replace given string constant to the new ones

Function replace_constant_address

Replace given address constant to the new ones

public fun replace_constant_address(modules: vector<move_module::MoveModule>, old_addresses: vector<address>, new_addresses: vector<address>): vector<move_module::MoveModule>

Function replace_constant_u8

Replace given u8 constant to the new ones

Function replace_constant_u64

Replace given u64 constant to the new ones

public fun replace_constant_u64(modules: vector<move_module::MoveModule>, old_u64s: vector<u64>, new_u64s: vector<u64>): vector<move_module::MoveModule>

Function replace_constant_u256

Replace given u256 constant to the new ones

Function module_id_from_name

Function sort_and_verify_modules_inner

Sort modules by dependency order and then verify. Return The first vector is the module names of all the modules. The second vector is the module names of the modules with init function. The third vector is the indices in input modules of each sorted modules.

public(friend) fun sort_and_verify_modules_inner(modules: vector<vector<u8>>, account_address: address): (vector<string::String>, vector<string::String>, vector<u64>)

Function request_init_functions

Request to call the init functions of the given modules module_ids: ids of modules which have a init function

public(friend) fun request_init_functions(module_ids: vector<string::String>)

Function replace_address_identifiers

Native function to replace addresses identifier in module binary where the length of old_addresses must equal to that of new_addresses.

public(friend) fun replace_address_identifiers(bytes: vector<vector<u8>>, old_addresses: vector<address>, new_addresses: vector<address>): vector<vector<u8>>

Function replace_identifiers

Native function to replace the name identifier old_name to new_name in module binary.

public(friend) fun replace_identifiers(bytes: vector<vector<u8>>, old_idents: vector<string::String>, new_idents: vector<string::String>): vector<vector<u8>>

Function replace_addresses_constant

Native function to replace constant addresses in module binary where the length of old_addresses must equal to that of new_addresses.

public(friend) fun replace_addresses_constant(bytes: vector<vector<u8>>, old_addresses: vector<address>, new_addresses: vector<address>): vector<vector<u8>>

Function replace_bytes_constant

Native function to replace constant bytes in module binary where the length of old_bytes must equal to that of new_bytes.

public(friend) fun replace_bytes_constant(bytes: vector<vector<u8>>, old_bytes: vector<vector<u8>>, new_bytes: vector<vector<u8>>): vector<vector<u8>>

Function replace_u8_constant

Native function to replace constant u8 in module binary where the length of old_u8s must equal to that of new_u8s.

public(friend) fun replace_u8_constant(bytes: vector<vector<u8>>, old_u8s: vector<u8>, new_u8s: vector<u8>): vector<vector<u8>>

Function replace_u64_constant

Native function to replace constant u64 in module binary where the length of old_u64s must equal to that of new_u64s.

public(friend) fun replace_u64_constant(bytes: vector<vector<u8>>, old_u64s: vector<u64>, new_u64s: vector<u64>): vector<vector<u8>>

Function replace_u256_constant

Native function to replace constant u256 in module binary where the length of old_u256s must equal to that of new_u256s.

public(friend) fun replace_u256_constant(bytes: vector<vector<u8>>, old_u256s: vector<u256>, new_u256s: vector<u256>): vector<vector<u8>>