move_module
wraps module bytes and provides some basic functions for handle Move module in Move.
- Struct
MoveModule
- Constants
- Function
new
- Function
new_batch
- Function
into_byte_codes_batch
- Function
module_id
- Function
sort_and_verify_modules
- Function
check_comatibility
- Function
binding_module_address
- Function
replace_module_identiner
- Function
replace_struct_identifier
- Function
replace_constant_string
- Function
replace_constant_address
- Function
replace_constant_u8
- Function
replace_constant_u64
- Function
replace_constant_u256
- Function
module_id_from_name
- Function
sort_and_verify_modules_inner
- Function
request_init_functions
- Function
replace_address_identifiers
- Function
replace_identifiers
- Function
replace_addresses_constant
- Function
replace_bytes_constant
- Function
replace_u8_constant
- Function
replace_u64_constant
- Function
replace_u256_constant
use 0x1::string;
use 0x1::vector;
use 0x2::features;
struct MoveModule has copy, drop, store
Module address is not the same as the signer
const ErrorAddressNotMatchWithSigner: u64 = 1;
Vector length not match
const ErrorLengthNotMatch: u64 = 4;
Module incompatible with the old ones.
const ErrorModuleIncompatible: u64 = 3;
Module verification error
const ErrorModuleVerificationError: u64 = 2;
public fun new(byte_codes: vector<u8>): move_module::MoveModule
public fun new_batch(byte_codes_batch: vector<vector<u8>>): vector<move_module::MoveModule>
public(friend) fun into_byte_codes_batch(modules: vector<move_module::MoveModule>): vector<vector<u8>>
public fun module_id(move_module: &move_module::MoveModule): string::String
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
- Module names of all the modules. Order of names is not matching the input, but sorted by module dependency order
- Module names of the modules with init function.
- 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>)
Check module compatibility when upgrading Abort if the new module is not compatible with the old module.
public fun check_comatibility(new_module: &move_module::MoveModule, old_module: &move_module::MoveModule)
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>
Replace given module's identifier to the new ones
public fun replace_module_identiner(modules: vector<move_module::MoveModule>, old_names: vector<string::String>, new_names: vector<string::String>): vector<move_module::MoveModule>
Replace given struct's identifier to the new ones
public fun replace_struct_identifier(modules: vector<move_module::MoveModule>, old_names: vector<string::String>, new_names: vector<string::String>): vector<move_module::MoveModule>
Replace given string constant to the new ones
public fun replace_constant_string(modules: vector<move_module::MoveModule>, old_strings: vector<string::String>, new_strings: vector<string::String>): vector<move_module::MoveModule>
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>
Replace given u8 constant to the new ones
public fun replace_constant_u8(modules: vector<move_module::MoveModule>, old_u8s: vector<u8>, new_u8s: vector<u8>): vector<move_module::MoveModule>
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>
Replace given u256 constant to the new ones
public fun replace_constant_u256(modules: vector<move_module::MoveModule>, old_u256s: vector<u256>, new_u256s: vector<u256>): vector<move_module::MoveModule>
public fun module_id_from_name(account: address, name: string::String): string::String
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>)
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>)
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>>
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>>
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>>
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>>
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>>
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>>
Native function to replace constant u256 in module binary where the length of
old_u256s
must equal to that of new_u256s
.