mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
Finish off srml-contract create -> instantiate renamings (#3649)
* Finish off srml-contract create -> instantiate renamings * bumped spec_version
This commit is contained in:
@@ -223,9 +223,9 @@ Finally, all changes are `commit`-ted into the underlying overlay. The complexit
|
|||||||
- Only for the first invocation of the contract: up to 5 DB reads and one DB write as well as logic executed by `ensure_can_withdraw`, `withdraw`, `make_free_balance_be`.
|
- Only for the first invocation of the contract: up to 5 DB reads and one DB write as well as logic executed by `ensure_can_withdraw`, `withdraw`, `make_free_balance_be`.
|
||||||
- On top of that for every invocation: Up to 5 DB reads. DB read of the code is of dynamic size. There can also be up to 2 DB writes (if flushed to the storage). Additionally, if the source account removal takes place a DB write will be performed per one storage entry that the account has.
|
- On top of that for every invocation: Up to 5 DB reads. DB read of the code is of dynamic size. There can also be up to 2 DB writes (if flushed to the storage). Additionally, if the source account removal takes place a DB write will be performed per one storage entry that the account has.
|
||||||
|
|
||||||
## Create
|
## Instantiate
|
||||||
|
|
||||||
This function takes the code of the constructor and input data. Creation of a contract consists of the following steps:
|
This function takes the code of the constructor and input data. Instantiation of a contract consists of the following steps:
|
||||||
|
|
||||||
1. Initialization of the execution context.
|
1. Initialization of the execution context.
|
||||||
2. Calling `DetermineContractAddress` hook to determine an address for the contract,
|
2. Calling `DetermineContractAddress` hook to determine an address for the contract,
|
||||||
@@ -303,7 +303,7 @@ Loading `input_data` should be charged in any case.
|
|||||||
|
|
||||||
**complexity**: All complexity comes from loading buffers and executing `call` executive function. The former component is proportional to the sizes of `callee`, `value` and `input_data` buffers. The latter component completely depends on the complexity of `call` executive function, and also dominated by it.
|
**complexity**: All complexity comes from loading buffers and executing `call` executive function. The former component is proportional to the sizes of `callee`, `value` and `input_data` buffers. The latter component completely depends on the complexity of `call` executive function, and also dominated by it.
|
||||||
|
|
||||||
## ext_create
|
## ext_instantiate
|
||||||
|
|
||||||
This function receives the following arguments:
|
This function receives the following arguments:
|
||||||
|
|
||||||
|
|||||||
@@ -580,9 +580,9 @@ decl_module! {
|
|||||||
.map_err(|e| e.reason)
|
.map_err(|e| e.reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new contract from the `codehash` generated by `put_code`, optionally transferring some balance.
|
/// Instantiates a new contract from the `codehash` generated by `put_code`, optionally transferring some balance.
|
||||||
///
|
///
|
||||||
/// Creation is executed as follows:
|
/// Instantiation is executed as follows:
|
||||||
///
|
///
|
||||||
/// - The destination address is computed based on the sender and hash of the code.
|
/// - The destination address is computed based on the sender and hash of the code.
|
||||||
/// - The smart-contract account is created at the computed address.
|
/// - The smart-contract account is created at the computed address.
|
||||||
|
|||||||
@@ -1621,7 +1621,7 @@ const CODE_CALLER_CONTRACT: &str = r#"
|
|||||||
(import "env" "ext_scratch_read" (func $ext_scratch_read (param i32 i32 i32)))
|
(import "env" "ext_scratch_read" (func $ext_scratch_read (param i32 i32 i32)))
|
||||||
(import "env" "ext_balance" (func $ext_balance))
|
(import "env" "ext_balance" (func $ext_balance))
|
||||||
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
||||||
(import "env" "ext_create" (func $ext_create (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
(import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
||||||
(import "env" "ext_println" (func $ext_println (param i32 i32)))
|
(import "env" "ext_println" (func $ext_println (param i32 i32)))
|
||||||
(import "env" "memory" (memory 1 1))
|
(import "env" "memory" (memory 1 1))
|
||||||
|
|
||||||
@@ -1677,7 +1677,7 @@ const CODE_CALLER_CONTRACT: &str = r#"
|
|||||||
|
|
||||||
;; Fail to deploy the contract since it returns a non-zero exit status.
|
;; Fail to deploy the contract since it returns a non-zero exit status.
|
||||||
(set_local $exit_code
|
(set_local $exit_code
|
||||||
(call $ext_create
|
(call $ext_instantiate
|
||||||
(i32.const 24) ;; Pointer to the code hash.
|
(i32.const 24) ;; Pointer to the code hash.
|
||||||
(i32.const 32) ;; Length of the code hash.
|
(i32.const 32) ;; Length of the code hash.
|
||||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||||
@@ -1705,7 +1705,7 @@ const CODE_CALLER_CONTRACT: &str = r#"
|
|||||||
|
|
||||||
;; Fail to deploy the contract due to insufficient gas.
|
;; Fail to deploy the contract due to insufficient gas.
|
||||||
(set_local $exit_code
|
(set_local $exit_code
|
||||||
(call $ext_create
|
(call $ext_instantiate
|
||||||
(i32.const 24) ;; Pointer to the code hash.
|
(i32.const 24) ;; Pointer to the code hash.
|
||||||
(i32.const 32) ;; Length of the code hash.
|
(i32.const 32) ;; Length of the code hash.
|
||||||
(i64.const 200) ;; How much gas to devote for the execution.
|
(i64.const 200) ;; How much gas to devote for the execution.
|
||||||
@@ -1733,7 +1733,7 @@ const CODE_CALLER_CONTRACT: &str = r#"
|
|||||||
|
|
||||||
;; Deploy the contract successfully.
|
;; Deploy the contract successfully.
|
||||||
(set_local $exit_code
|
(set_local $exit_code
|
||||||
(call $ext_create
|
(call $ext_instantiate
|
||||||
(i32.const 24) ;; Pointer to the code hash.
|
(i32.const 24) ;; Pointer to the code hash.
|
||||||
(i32.const 32) ;; Length of the code hash.
|
(i32.const 32) ;; Length of the code hash.
|
||||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||||
@@ -2118,7 +2118,7 @@ const CODE_DESTROY_AND_TRANSFER: &str = r#"
|
|||||||
(import "env" "ext_get_storage" (func $ext_get_storage (param i32) (result i32)))
|
(import "env" "ext_get_storage" (func $ext_get_storage (param i32) (result i32)))
|
||||||
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32 i32)))
|
(import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32 i32)))
|
||||||
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
(import "env" "ext_call" (func $ext_call (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
||||||
(import "env" "ext_create" (func $ext_create (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
(import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
||||||
(import "env" "memory" (memory 1 1))
|
(import "env" "memory" (memory 1 1))
|
||||||
|
|
||||||
(func $assert (param i32)
|
(func $assert (param i32)
|
||||||
@@ -2149,7 +2149,7 @@ const CODE_DESTROY_AND_TRANSFER: &str = r#"
|
|||||||
;; Deploy the contract with the provided code hash.
|
;; Deploy the contract with the provided code hash.
|
||||||
(call $assert
|
(call $assert
|
||||||
(i32.eq
|
(i32.eq
|
||||||
(call $ext_create
|
(call $ext_instantiate
|
||||||
(i32.const 48) ;; Pointer to the code hash.
|
(i32.const 48) ;; Pointer to the code hash.
|
||||||
(i32.const 32) ;; Length of the code hash.
|
(i32.const 32) ;; Length of the code hash.
|
||||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ mod tests {
|
|||||||
|
|
||||||
const CODE_CREATE: &str = r#"
|
const CODE_CREATE: &str = r#"
|
||||||
(module
|
(module
|
||||||
;; ext_create(
|
;; ext_instantiate(
|
||||||
;; code_ptr: u32,
|
;; code_ptr: u32,
|
||||||
;; code_len: u32,
|
;; code_len: u32,
|
||||||
;; gas: u64,
|
;; gas: u64,
|
||||||
@@ -487,11 +487,11 @@ mod tests {
|
|||||||
;; input_data_ptr: u32,
|
;; input_data_ptr: u32,
|
||||||
;; input_data_len: u32,
|
;; input_data_len: u32,
|
||||||
;; ) -> u32
|
;; ) -> u32
|
||||||
(import "env" "ext_create" (func $ext_create (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
(import "env" "ext_instantiate" (func $ext_instantiate (param i32 i32 i64 i32 i32 i32 i32) (result i32)))
|
||||||
(import "env" "memory" (memory 1 1))
|
(import "env" "memory" (memory 1 1))
|
||||||
(func (export "call")
|
(func (export "call")
|
||||||
(drop
|
(drop
|
||||||
(call $ext_create
|
(call $ext_instantiate
|
||||||
(i32.const 16) ;; Pointer to `code_hash`
|
(i32.const 16) ;; Pointer to `code_hash`
|
||||||
(i32.const 32) ;; Length of `code_hash`
|
(i32.const 32) ;; Length of `code_hash`
|
||||||
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
(i64.const 0) ;; How much gas to devote for the execution. 0 = all.
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ use rstd::mem;
|
|||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use sr_primitives::traits::{Bounded, SaturatedConversion};
|
use sr_primitives::traits::{Bounded, SaturatedConversion};
|
||||||
|
|
||||||
/// The value returned from ext_call and ext_create contract external functions if the call or
|
/// The value returned from ext_call and ext_instantiate contract external functions if the call or
|
||||||
/// instantiation traps. This value is chosen as if the execution does not trap, the return value
|
/// instantiation traps. This value is chosen as if the execution does not trap, the return value
|
||||||
/// will always be an 8-bit integer, so 0x0100 is the smallest value that could not be returned.
|
/// will always be an 8-bit integer, so 0x0100 is the smallest value that could not be returned.
|
||||||
const TRAP_RETURN_CODE: u32 = 0x0100;
|
const TRAP_RETURN_CODE: u32 = 0x0100;
|
||||||
@@ -456,7 +456,7 @@ define_env!(Env, <E: Ext>,
|
|||||||
// - value_len: length of the value buffer.
|
// - value_len: length of the value buffer.
|
||||||
// - input_data_ptr: a pointer to a buffer to be used as input data to the initializer code.
|
// - input_data_ptr: a pointer to a buffer to be used as input data to the initializer code.
|
||||||
// - input_data_len: length of the input data buffer.
|
// - input_data_len: length of the input data buffer.
|
||||||
ext_create(
|
ext_instantiate(
|
||||||
ctx,
|
ctx,
|
||||||
code_hash_ptr: u32,
|
code_hash_ptr: u32,
|
||||||
code_hash_len: u32,
|
code_hash_len: u32,
|
||||||
|
|||||||
Reference in New Issue
Block a user