Modules on Aptos
Aptos allows for permissionless publishing of modules within a package as well as upgrading those that have appropriate compatibility policy set.
A module contains several structs and functions, much like Rust.
During package publishing time, a few constraints are maintained:
- Both Structs and public function signatures are published as immutable.
- The init_modulefunction plays a crucial role in module initialization:- When a module is published for the first time (i.e., the module does not exist on-chain), the VM will search for and execute the init_module(account: &signer)function.
- When upgrading an existing module that is already on-chain, the init_modulefunction will NOT be called.
- The signer of the account that is publishing the module is passed into the init_modulefunction.
- This function must be private and not return any value.
- The init_modulefunction can have at most one parameter, and its type must be&signer
- The init_modulefunction should not have generic parameters
- The init_modulefunction is commonly used to initialize module-specific data structures or set initial states.
 
- When a module is published for the first time (i.e., the module does not exist on-chain), the VM will search for and execute the