Module constructors #93
Labels
mark:next
Strategic issues related to next versions of Testnet and mid/long term plans
team:Core
Low Level Core Development Team (Rust)
type:feature
implementing a new feature
Summary
There should be a way to provide modules some data on deployment, which is then used to initialize the state. Currently it is only possible to "bake in" the initial state in the WASM bytecode. This precludes the module writer from writing a module once, and then reusing the same bytecode with different initial states. This use-case should become possible.
Possible solution design or implementation
It could be possible to check the existence of a such a module constructor by interpreting the module exports. If an export exists with a predefined name and signature, this could then be called with a piece of data provided by the deployer through the argument buffer. An example name and signature could be:
The
pos
argument would be the length of the argument in the buffer. The contract would then deserialize (possibly usingrkyv
) the piece of data and proceed with initialization.This has to be accompanied with a mechanism that disallows the constructor to be called more than once.
Additional context
Not only is this a useful mechanism for prospective smart contract writers, it's also extremely useful to construct multiple networks with different types of genesis data, given that different networks are defined by differently initialized genesis contracts.
The text was updated successfully, but these errors were encountered: