Function pallet_gear::pallet::dispatchables::upload_program
source · pub fn upload_program<T: Config>(
code: Vec<u8>,
salt: Vec<u8>,
init_payload: Vec<u8>,
gas_limit: u64,
value: <<T as Config>::Currency as Currency<<T as Config>::AccountId>>::Balance,
keep_alive: bool,
)
Expand description
Creates program initialization request (message), that is scheduled to be run in the same block.
There are no guarantees that initialization message will be run in the same block due to block gas limit restrictions. For example, when it will be the message’s turn, required gas limit for it could be more than remaining block gas limit. Therefore, the message processing will be postponed until the next block.
ProgramId
is computed as Blake256 hash of concatenated bytes of code
+ salt
. (todo #512 code_hash
+ salt
)
Such ProgramId
must not exist in the Program Storage at the time of this call.
There is the same guarantee here as in upload_code
. That is, future program’s
code
and metadata are stored before message was added to the queue and processed.
The origin must be Signed and the sender must have sufficient funds to pay
for gas
and value
(in case the latter is being transferred).
Gear runtime guarantees that an active program always has an account to store value.
If the underlying account management platform (e.g. Substrate’s System pallet) requires
an existential deposit to keep an account alive, the related overhead is considered an
extra cost related with a program instantiation and is charged to the program’s creator
and is released back to the creator when the program is removed.
In context of the above, the value
parameter represents the so-called reducible
balance
a program should have at its disposal upon instantiation. It is not used to offset the
existential deposit required for an account creation.
Parameters:
code
: wasm code of a program as a byte vector.salt
: randomness term (a seed) to allow programs with identical code to be created independently.init_payload
: encoded parameters of the wasm moduleinit
function.gas_limit
: maximum amount of gas the program can spend before it is halted.value
: balance to be transferred to the program once it’s been created.
Emits the following events:
InitMessageEnqueued(MessageInfo)
when init message is placed in the queue.
§Note
Faulty (uninitialized) programs still have a valid addresses (program ids) that can deterministically be derived on the caller’s side upfront. It means that if messages are sent to such an address, they might still linger in the queue.
In order to mitigate the risk of users’ funds being sent to an address, where a valid program should have resided, while it’s not, such “failed-to-initialize” programs are not silently deleted from the program storage but rather marked as “ghost” programs. Ghost program can be removed by their original author via an explicit call. The funds stored by a ghost program will be release to the author once the program has been removed.
§Warning: Doc-Only
This function is an automatically generated, and is doc-only, uncallable
stub. See the real version in
Pallet::upload_program
.