pub trait HostFn: Sealed {
Show 61 methods
// Required methods
fn account_reentrance_count(account: &[u8]) -> u32;
fn address(output: &mut &mut [u8]);
fn lock_delegate_dependency(code_hash: &[u8]);
fn balance(output: &mut &mut [u8]);
fn block_number(output: &mut &mut [u8]);
fn call(
callee: &[u8],
gas: u64,
value: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>;
fn call_v1(
flags: CallFlags,
callee: &[u8],
gas: u64,
value: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>;
fn call_v2(
flags: CallFlags,
callee: &[u8],
ref_time_limit: u64,
proof_size_limit: u64,
deposit: Option<&[u8]>,
value: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>;
fn call_chain_extension(
func_id: u32,
input: &[u8],
output: Option<&mut &mut [u8]>,
) -> u32;
fn call_runtime(call: &[u8]) -> Result<(), ReturnErrorCode>;
fn caller(output: &mut &mut [u8]);
fn caller_is_origin() -> bool;
fn caller_is_root() -> u32;
fn clear_storage(key: &[u8]);
fn clear_storage_v1(key: &[u8]) -> Option<u32>;
fn clear_transient_storage(key: &[u8]) -> Option<u32>;
fn code_hash(
account_id: &[u8],
output: &mut [u8],
) -> Result<(), ReturnErrorCode>;
fn contains_storage(key: &[u8]) -> Option<u32>;
fn contains_storage_v1(key: &[u8]) -> Option<u32>;
fn contains_transient_storage(key: &[u8]) -> Option<u32>;
fn debug_message(str: &[u8]) -> Result<(), ReturnErrorCode>;
fn delegate_call(
flags: CallFlags,
code_hash: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>;
fn deposit_event(topics: &[u8], data: &[u8]);
fn ecdsa_recover(
signature: &[u8; 65],
message_hash: &[u8; 32],
output: &mut [u8; 33],
) -> Result<(), ReturnErrorCode>;
fn ecdsa_to_eth_address(
pubkey: &[u8; 33],
output: &mut [u8; 20],
) -> Result<(), ReturnErrorCode>;
fn gas_left(out: &mut &mut [u8]);
fn gas_left_v1(output: &mut &mut [u8]);
fn get_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>;
fn get_storage_v1(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>;
fn get_transient_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>;
fn hash_sha2_256(input: &[u8], output: &mut [u8; 32]);
fn hash_keccak_256(input: &[u8], output: &mut [u8; 32]);
fn hash_blake2_256(input: &[u8], output: &mut [u8; 32]);
fn hash_blake2_128(input: &[u8], output: &mut [u8; 16]);
fn input(output: &mut &mut [u8]);
fn instantiate_v1(
code_hash: &[u8],
gas: u64,
value: &[u8],
input: &[u8],
address: Option<&mut &mut [u8]>,
output: Option<&mut &mut [u8]>,
salt: &[u8],
) -> Result<(), ReturnErrorCode>;
fn instantiate_v2(
code_hash: &[u8],
ref_time_limit: u64,
proof_size_limit: u64,
deposit: Option<&[u8]>,
value: &[u8],
input: &[u8],
address: Option<&mut &mut [u8]>,
output: Option<&mut &mut [u8]>,
salt: &[u8],
) -> Result<(), ReturnErrorCode>;
fn instantiation_nonce() -> u64;
fn is_contract(account_id: &[u8]) -> bool;
fn minimum_balance(output: &mut &mut [u8]);
fn own_code_hash(output: &mut [u8]);
fn now(output: &mut &mut [u8]);
fn reentrance_count() -> u32;
fn unlock_delegate_dependency(code_hash: &[u8]);
fn return_value(flags: ReturnFlags, return_value: &[u8]) -> !;
fn set_code_hash(code_hash: &[u8]) -> Result<(), ReturnErrorCode>;
fn set_storage(key: &[u8], value: &[u8]);
fn set_storage_v1(key: &[u8], value: &[u8]) -> Option<u32>;
fn set_storage_v2(key: &[u8], value: &[u8]) -> Option<u32>;
fn set_transient_storage(key: &[u8], value: &[u8]) -> Option<u32>;
fn sr25519_verify(
signature: &[u8; 64],
message: &[u8],
pub_key: &[u8; 32],
) -> Result<(), ReturnErrorCode>;
fn take_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>;
fn take_transient_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>;
fn transfer(account_id: &[u8], value: &[u8]) -> Result<(), ReturnErrorCode>;
fn terminate(beneficiary: &[u8]) -> !;
fn terminate_v1(beneficiary: &[u8]) -> !;
fn value_transferred(output: &mut &mut [u8]);
fn weight_to_fee(gas: u64, output: &mut &mut [u8]);
fn weight_to_fee_v1(
ref_time_limit: u64,
proof_size_limit: u64,
output: &mut &mut [u8],
);
fn xcm_execute(msg: &[u8]) -> Result<(), ReturnErrorCode>;
fn xcm_send(
dest: &[u8],
msg: &[u8],
output: &mut [u8; 32],
) -> Result<(), ReturnErrorCode>;
}
Expand description
Defines all the host apis implemented by the wasm vm.
Required Methods§
Sourcefn account_reentrance_count(account: &[u8]) -> u32
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn account_reentrance_count(account: &[u8]) -> u32
Returns the number of times specified contract exists on the call stack. Delegated calls are not counted as separate calls.
§Parameters
account
: The contract address. Should be decodable as anT::AccountId
. Traps otherwise.
§Return
Returns the number of times specified contract exists on the call stack.
Sourcefn address(output: &mut &mut [u8])
fn address(output: &mut &mut [u8])
Stores the address of the current contract into the supplied buffer.
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
output
: A reference to the output data buffer to write the address.
Sourcefn lock_delegate_dependency(code_hash: &[u8])
fn lock_delegate_dependency(code_hash: &[u8])
Lock a new delegate dependency to the contract.
Traps if the maximum number of delegate_dependencies is reached or if the delegate dependency already exists.
§Parameters
code_hash
: The code hash of the dependency. Should be decodable as anT::Hash
. Traps otherwise.
Sourcefn balance(output: &mut &mut [u8])
fn balance(output: &mut &mut [u8])
Stores the free balance of the current account into the supplied buffer.
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
output
: A reference to the output data buffer to write the balance.
Sourcefn block_number(output: &mut &mut [u8])
fn block_number(output: &mut &mut [u8])
Stores the current block number of the current contract into the supplied buffer.
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
output
: A reference to the output data buffer to write the block number.
Sourcefn call(
callee: &[u8],
gas: u64,
value: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>
👎Deprecated: Deprecated, use newer version instead
fn call( callee: &[u8], gas: u64, value: &[u8], input_data: &[u8], output: Option<&mut &mut [u8]>, ) -> Result<(), ReturnErrorCode>
Make a call to another contract.
This is equivalent to calling the newer version of this function with
flags
set to CallFlags::ALLOW_REENTRY
. See the newer version for documentation.
Sourcefn call_v1(
flags: CallFlags,
callee: &[u8],
gas: u64,
value: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>
👎Deprecated: Deprecated, use newer version instead
fn call_v1( flags: CallFlags, callee: &[u8], gas: u64, value: &[u8], input_data: &[u8], output: Option<&mut &mut [u8]>, ) -> Result<(), ReturnErrorCode>
Make a call to another contract.
Equivalent to the newer Self::call_v2
version but works with
ref_time Weight only
Sourcefn call_v2(
flags: CallFlags,
callee: &[u8],
ref_time_limit: u64,
proof_size_limit: u64,
deposit: Option<&[u8]>,
value: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>
fn call_v2( flags: CallFlags, callee: &[u8], ref_time_limit: u64, proof_size_limit: u64, deposit: Option<&[u8]>, value: &[u8], input_data: &[u8], output: Option<&mut &mut [u8]>, ) -> Result<(), ReturnErrorCode>
Call (possibly transferring some amount of funds) into the specified account.
§Parameters
flags
: SeeCallFlags
for a documentation of the supported flags.callee
: The address of the callee. Should be decodable as anT::AccountId
. Traps otherwise.ref_time_limit
: how much ref_time Weight to devote to the execution.proof_size_limit
: how much proof_size Weight to devote to the execution.deposit
: The storage deposit limit for instantiation. Should be decodable as aOption<T::Balance>
. Traps otherwise. PassingNone
means setting no specific limit for the call, which implies storage usage up to the limit of the parent call.value
: The value to transfer into the contract. Should be decodable as aT::Balance
. Traps otherwise.input
: The input data buffer used to call the contract.output
: A reference to the output data buffer to write the call output buffer. IfNone
is provided then the output buffer is not copied.
§Errors
An error means that the call wasn’t successful output buffer is returned unless stated otherwise.
- CalleeReverted: Output buffer is returned.
- CalleeTrapped
- TransferFailed
- NotCallable
Sourcefn call_chain_extension(
func_id: u32,
input: &[u8],
output: Option<&mut &mut [u8]>,
) -> u32
fn call_chain_extension( func_id: u32, input: &[u8], output: Option<&mut &mut [u8]>, ) -> u32
Call into the chain extension provided by the chain if any.
Handling of the input values is up to the specific chain extension and so is the return value. The extension can decide to use the inputs as primitive inputs or as in/out arguments by interpreting them as pointers. Any caller of this function must therefore coordinate with the chain that it targets.
§Note
If no chain extension exists the contract will trap with the NoChainExtension
module error.
§Parameters
func_id
: The function id of the chain extension.input
: The input data buffer.output
: A reference to the output data buffer to write the call output buffer. IfNone
is provided then the output buffer is not copied.
§Return
The chain extension returned value, if executed successfully.
Sourcefn call_runtime(call: &[u8]) -> Result<(), ReturnErrorCode>
fn call_runtime(call: &[u8]) -> Result<(), ReturnErrorCode>
Call some dispatchable of the runtime.
§Parameters
call
: The call data.
§Return
Returns Error::Success
when the dispatchable was successfully executed and
returned Ok
. When the dispatchable was executed but returned an error
Error::CallRuntimeFailed
is returned. The full error is not
provided because it is not guaranteed to be stable.
§Comparison with ChainExtension
Just as a chain extension this API allows the runtime to extend the functionality of contracts. While making use of this function is generally easier it cannot be used in all cases. Consider writing a chain extension if you need to do perform one of the following tasks:
- Return data.
- Provide functionality exclusively to contracts.
- Provide custom weights.
- Avoid the need to keep the
Call
data structure stable.
Sourcefn caller(output: &mut &mut [u8])
fn caller(output: &mut &mut [u8])
Stores the address of the caller into the supplied buffer.
If the available space in output
is less than the size of the value a trap is triggered.
If this is a top-level call (i.e. initiated by an extrinsic) the origin address of the extrinsic will be returned. Otherwise, if this call is initiated by another contract then the address of the contract will be returned.
If there is no address associated with the caller (e.g. because the caller is root) then
it traps with BadOrigin
.
§Parameters
output
: A reference to the output data buffer to write the caller address.
Sourcefn caller_is_origin() -> bool
fn caller_is_origin() -> bool
Checks whether the caller of the current contract is the origin of the whole call stack.
Prefer this over is_contract()
when checking whether your contract
is being called by a contract or a plain account. The reason is that it performs better
since it does not need to do any storage lookups.
§Return
A return value of true
indicates that this contract is being called by a plain account
and false
indicates that the caller is another contract.
Sourcefn caller_is_root() -> u32
fn caller_is_root() -> u32
Checks whether the caller of the current contract is root.
Note that only the origin of the call stack can be root. Hence this function returning
true
implies that the contract is being called by the origin.
A return value of true
indicates that this contract is being called by a root origin,
and false
indicates that the caller is a signed origin.
Sourcefn clear_storage(key: &[u8])
fn clear_storage(key: &[u8])
Clear the value at the given key in the contract storage.
Equivalent to the newer Self::clear_storage_v1
version with
the exception of the return type. Still a valid thing to call when not interested in the
return value.
Sourcefn clear_storage_v1(key: &[u8]) -> Option<u32>
fn clear_storage_v1(key: &[u8]) -> Option<u32>
Sourcefn clear_transient_storage(key: &[u8]) -> Option<u32>
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn clear_transient_storage(key: &[u8]) -> Option<u32>
Sourcefn code_hash(
account_id: &[u8],
output: &mut [u8],
) -> Result<(), ReturnErrorCode>
fn code_hash( account_id: &[u8], output: &mut [u8], ) -> Result<(), ReturnErrorCode>
Sourcefn contains_storage(key: &[u8]) -> Option<u32>
fn contains_storage(key: &[u8]) -> Option<u32>
Checks whether there is a value stored under the given key.
This version is to be used with a fixed sized storage key. For runtimes supporting transparent hashing, please use the newer version of this function.
Sourcefn contains_storage_v1(key: &[u8]) -> Option<u32>
fn contains_storage_v1(key: &[u8]) -> Option<u32>
Sourcefn contains_transient_storage(key: &[u8]) -> Option<u32>
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn contains_transient_storage(key: &[u8]) -> Option<u32>
Sourcefn debug_message(str: &[u8]) -> Result<(), ReturnErrorCode>
fn debug_message(str: &[u8]) -> Result<(), ReturnErrorCode>
Emit a custom debug message.
No newlines are added to the supplied message. Specifying invalid UTF-8 just drops the message with no trap.
This is a no-op if debug message recording is disabled which is always the case when the code is executing on-chain. The message is interpreted as UTF-8 and appended to the debug buffer which is then supplied to the calling RPC client.
§Note
Even though no action is taken when debug message recording is disabled there is still a non trivial overhead (and weight cost) associated with calling this function. Contract languages should remove calls to this function (either at runtime or compile time) when not being executed as an RPC. For example, they could allow users to disable logging through compile time flags (cargo features) for on-chain deployment. Additionally, the return value of this function can be cached in order to prevent further calls at runtime.
Sourcefn delegate_call(
flags: CallFlags,
code_hash: &[u8],
input_data: &[u8],
output: Option<&mut &mut [u8]>,
) -> Result<(), ReturnErrorCode>
fn delegate_call( flags: CallFlags, code_hash: &[u8], input_data: &[u8], output: Option<&mut &mut [u8]>, ) -> Result<(), ReturnErrorCode>
Execute code in the context (storage, caller, value) of the current contract.
Reentrancy protection is always disabled since the callee is allowed to modify the callers storage. This makes going through a reentrancy attack unnecessary for the callee when it wants to exploit the caller.
§Parameters
flags
: SeeCallFlags
for a documentation of the supported flags.code_hash
: The hash of the code to be executed.input
: The input data buffer used to call the contract.output
: A reference to the output data buffer to write the call output buffer. IfNone
is provided then the output buffer is not copied.
§Errors
An error means that the call wasn’t successful and no output buffer is returned unless stated otherwise.
- CalleeReverted: Output buffer is returned.
- CalleeTrapped
- CodeNotFound
Sourcefn deposit_event(topics: &[u8], data: &[u8])
fn deposit_event(topics: &[u8], data: &[u8])
Deposit a contract event with the data buffer and optional list of topics. There is a limit
on the maximum number of topics specified by event_topics
.
There should not be any duplicates in topics
.
§Parameters
topics
: The topics list encoded asVec<T::Hash>
. It can’t contain duplicates.
Sourcefn ecdsa_recover(
signature: &[u8; 65],
message_hash: &[u8; 32],
output: &mut [u8; 33],
) -> Result<(), ReturnErrorCode>
fn ecdsa_recover( signature: &[u8; 65], message_hash: &[u8; 32], output: &mut [u8; 33], ) -> Result<(), ReturnErrorCode>
Recovers the ECDSA public key from the given message hash and signature.
Writes the public key into the given output buffer. Assumes the secp256k1 curve.
§Parameters
signature
: The signature bytes.message_hash
: The message hash bytes.output
: A reference to the output data buffer to write the public key.
§Errors
Sourcefn ecdsa_to_eth_address(
pubkey: &[u8; 33],
output: &mut [u8; 20],
) -> Result<(), ReturnErrorCode>
fn ecdsa_to_eth_address( pubkey: &[u8; 33], output: &mut [u8; 20], ) -> Result<(), ReturnErrorCode>
Sourcefn gas_left(out: &mut &mut [u8])
fn gas_left(out: &mut &mut [u8])
Stores the weight left into the supplied buffer.
Equivalent to the newer Self::gas_left_v1
version but
works with ref_time Weight only.
Sourcefn gas_left_v1(output: &mut &mut [u8])
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn gas_left_v1(output: &mut &mut [u8])
Stores the amount of weight left into the supplied buffer. The data is encoded as Weight.
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
output
: A reference to the output data buffer to write the weight left.
Sourcefn get_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>
fn get_storage( key: &[u8], output: &mut &mut [u8], ) -> Result<(), ReturnErrorCode>
Retrieve the value under the given key from storage.
This version is to be used with a fixed sized storage key. For runtimes supporting transparent hashing, please use the newer version of this function.
Sourcefn get_storage_v1(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>
fn get_storage_v1( key: &[u8], output: &mut &mut [u8], ) -> Result<(), ReturnErrorCode>
Sourcefn get_transient_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn get_transient_storage( key: &[u8], output: &mut &mut [u8], ) -> Result<(), ReturnErrorCode>
Sourcefn hash_sha2_256(input: &[u8], output: &mut [u8; 32])
fn hash_sha2_256(input: &[u8], output: &mut [u8; 32])
Computes the sha2_256 32-bit hash on the given input buffer.
§Notes
- The
input
andoutput
buffer may overlap. - The output buffer is expected to hold at least 32 bits.
- It is the callers responsibility to provide an output buffer that is large enough to hold the expected amount of bytes returned by the hash function.
§Parameters
input
: The input data buffer.output
: The output buffer to write the hash result to.
Sourcefn hash_keccak_256(input: &[u8], output: &mut [u8; 32])
fn hash_keccak_256(input: &[u8], output: &mut [u8; 32])
Computes the keccak_256 32-bit hash on the given input buffer.
§Notes
- The
input
andoutput
buffer may overlap. - The output buffer is expected to hold at least 32 bits.
- It is the callers responsibility to provide an output buffer that is large enough to hold the expected amount of bytes returned by the hash function.
§Parameters
input
: The input data buffer.output
: The output buffer to write the hash result to.
Sourcefn hash_blake2_256(input: &[u8], output: &mut [u8; 32])
fn hash_blake2_256(input: &[u8], output: &mut [u8; 32])
Computes the blake2_256 32-bit hash on the given input buffer.
§Notes
- The
input
andoutput
buffer may overlap. - The output buffer is expected to hold at least 32 bits.
- It is the callers responsibility to provide an output buffer that is large enough to hold the expected amount of bytes returned by the hash function.
§Parameters
input
: The input data buffer.output
: The output buffer to write the hash result to.
Sourcefn hash_blake2_128(input: &[u8], output: &mut [u8; 16])
fn hash_blake2_128(input: &[u8], output: &mut [u8; 16])
Computes the blake2_128 16-bit hash on the given input buffer.
§Notes
- The
input
andoutput
buffer may overlap. - The output buffer is expected to hold at least 16 bits.
- It is the callers responsibility to provide an output buffer that is large enough to hold the expected amount of bytes returned by the hash function.
§Parameters
input
: The input data buffer.output
: The output buffer to write the hash result to.
Sourcefn instantiate_v1(
code_hash: &[u8],
gas: u64,
value: &[u8],
input: &[u8],
address: Option<&mut &mut [u8]>,
output: Option<&mut &mut [u8]>,
salt: &[u8],
) -> Result<(), ReturnErrorCode>
👎Deprecated: Deprecated, use newer version instead
fn instantiate_v1( code_hash: &[u8], gas: u64, value: &[u8], input: &[u8], address: Option<&mut &mut [u8]>, output: Option<&mut &mut [u8]>, salt: &[u8], ) -> Result<(), ReturnErrorCode>
Instantiate a contract with the specified code hash.
Equivalent to the newer Self::instantiate_v2
version but works
with ref_time Weight only.
Sourcefn instantiate_v2(
code_hash: &[u8],
ref_time_limit: u64,
proof_size_limit: u64,
deposit: Option<&[u8]>,
value: &[u8],
input: &[u8],
address: Option<&mut &mut [u8]>,
output: Option<&mut &mut [u8]>,
salt: &[u8],
) -> Result<(), ReturnErrorCode>
fn instantiate_v2( code_hash: &[u8], ref_time_limit: u64, proof_size_limit: u64, deposit: Option<&[u8]>, value: &[u8], input: &[u8], address: Option<&mut &mut [u8]>, output: Option<&mut &mut [u8]>, salt: &[u8], ) -> Result<(), ReturnErrorCode>
Instantiate a contract with the specified code hash.
This function creates an account and executes the constructor defined in the code specified by the code hash.
§Parameters
code_hash
: The hash of the code to be instantiated.ref_time_limit
: how much ref_time Weight to devote to the execution.proof_size_limit
: how much proof_size Weight to devote to the execution.deposit
: The storage deposit limit for instantiation. Should be decodable as aOption<T::Balance>
. Traps otherwise. PassingNone
means setting no specific limit for the call, which implies storage usage up to the limit of the parent call.value
: The value to transfer into the contract. Should be decodable as aT::Balance
. Traps otherwise.input
: The input data buffer.address
: A reference to the address buffer to write the address of the contract. IfNone
is provided then the output buffer is not copied.output
: A reference to the return value buffer to write the constructor output buffer. IfNone
is provided then the output buffer is not copied.salt
: The salt bytes to use for this instantiation.
§Errors
Please consult the ReturnErrorCode enum declaration for more information on those errors. Here we only note things specific to this function.
An error means that the account wasn’t created and no address or output buffer is returned unless stated otherwise.
- CalleeReverted: Output buffer is returned.
- CalleeTrapped
- TransferFailed
- CodeNotFound
Sourcefn instantiation_nonce() -> u64
fn instantiation_nonce() -> u64
Returns a nonce that is unique per contract instantiation.
The nonce is incremented for each successful contract instantiation. This is a sensible default salt for contract instantiations.
Sourcefn is_contract(account_id: &[u8]) -> bool
fn is_contract(account_id: &[u8]) -> bool
Sourcefn minimum_balance(output: &mut &mut [u8])
fn minimum_balance(output: &mut &mut [u8])
Stores the minimum balance (a.k.a. existential deposit) into the supplied buffer.
The data is encoded as T::Balance
.
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
output
: A reference to the output data buffer to write the minimum balance.
Sourcefn own_code_hash(output: &mut [u8])
fn own_code_hash(output: &mut [u8])
Retrieve the code hash of the currently executing contract.
§Parameters
output
: A reference to the output data buffer to write the code hash.
Sourcefn now(output: &mut &mut [u8])
fn now(output: &mut &mut [u8])
Load the latest block timestamp into the supplied buffer
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
output
: A reference to the output data buffer to write the timestamp.
Sourcefn reentrance_count() -> u32
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn reentrance_count() -> u32
Returns the number of times the currently executing contract exists on the call stack in addition to the calling instance.
§Return
Returns 0
when there is no reentrancy.
Sourcefn unlock_delegate_dependency(code_hash: &[u8])
fn unlock_delegate_dependency(code_hash: &[u8])
Removes the delegate dependency from the contract.
Traps if the delegate dependency does not exist.
§Parameters
code_hash
: The code hash of the dependency. Should be decodable as anT::Hash
. Traps otherwise.
Sourcefn return_value(flags: ReturnFlags, return_value: &[u8]) -> !
fn return_value(flags: ReturnFlags, return_value: &[u8]) -> !
Cease contract execution and save a data buffer as a result of the execution.
This function never returns as it stops execution of the caller. This is the only way to return a data buffer to the caller. Returning from execution without calling this function is equivalent to calling:
return_value(ReturnFlags::empty(), &[])
Using an unnamed non empty ReturnFlags
triggers a trap.
§Parameters
flags
: Flag used to signal special return conditions to the supervisor. SeeReturnFlags
for a documentation of the supported flags.return_value
: The return value buffer.
Sourcefn set_code_hash(code_hash: &[u8]) -> Result<(), ReturnErrorCode>
fn set_code_hash(code_hash: &[u8]) -> Result<(), ReturnErrorCode>
Replace the contract code at the specified address with new code.
§Note
There are a couple of important considerations which must be taken into account when using this API:
-
The storage at the code address will remain untouched. This means that contract developers must ensure that the storage layout of the new code is compatible with that of the old code.
-
Contracts using this API can’t be assumed as having deterministic addresses. Said another way, when using this API you lose the guarantee that an address always identifies a specific code hash.
-
If a contract calls into itself after changing its code the new call would use the new code. However, if the original caller panics after returning from the sub call it would revert the changes made by
set_code_hash()
and the next caller would use the old code.
§Parameters
code_hash
: The hash of the new code. Should be decodable as anT::Hash
. Traps otherwise.
§Errors
Sourcefn set_storage(key: &[u8], value: &[u8])
fn set_storage(key: &[u8], value: &[u8])
Set the value at the given key in the contract storage.
Equivalent to Self::set_storage_v1
version with the
exception of the return type. Still a valid thing to call for fixed sized storage key, when
not interested in the return value.
Sourcefn set_storage_v1(key: &[u8], value: &[u8]) -> Option<u32>
fn set_storage_v1(key: &[u8], value: &[u8]) -> Option<u32>
Set the value at the given key in the contract storage.
This version is to be used with a fixed sized storage key. For runtimes supporting transparent hashing, please use the newer version of this function.
Sourcefn set_storage_v2(key: &[u8], value: &[u8]) -> Option<u32>
fn set_storage_v2(key: &[u8], value: &[u8]) -> Option<u32>
Set the value at the given key in the contract storage.
The key and value lengths must not exceed the maximums defined by the contracts module parameters.
§Parameters
key
: The storage key.encoded_value
: The storage value.
§Return
Returns the size of the pre-existing value at the specified key if any.
Sourcefn set_transient_storage(key: &[u8], value: &[u8]) -> Option<u32>
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn set_transient_storage(key: &[u8], value: &[u8]) -> Option<u32>
Set the value at the given key in the contract transient storage.
The key and value lengths must not exceed the maximums defined by the contracts module parameters.
§Parameters
key
: The storage key.encoded_value
: The storage value.
§Return
Returns the size of the pre-existing value at the specified key if any.
Sourcefn sr25519_verify(
signature: &[u8; 64],
message: &[u8],
pub_key: &[u8; 32],
) -> Result<(), ReturnErrorCode>
fn sr25519_verify( signature: &[u8; 64], message: &[u8], pub_key: &[u8; 32], ) -> Result<(), ReturnErrorCode>
Sourcefn take_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>
fn take_storage( key: &[u8], output: &mut &mut [u8], ) -> Result<(), ReturnErrorCode>
Sourcefn take_transient_storage(
key: &[u8],
output: &mut &mut [u8],
) -> Result<(), ReturnErrorCode>
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn take_transient_storage( key: &[u8], output: &mut &mut [u8], ) -> Result<(), ReturnErrorCode>
Sourcefn transfer(account_id: &[u8], value: &[u8]) -> Result<(), ReturnErrorCode>
fn transfer(account_id: &[u8], value: &[u8]) -> Result<(), ReturnErrorCode>
Sourcefn terminate(beneficiary: &[u8]) -> !
👎Deprecated: Deprecated, use newer version instead
fn terminate(beneficiary: &[u8]) -> !
Remove the calling account and transfer remaining balance.
This is equivalent to calling the newer version of this function
Sourcefn terminate_v1(beneficiary: &[u8]) -> !
fn terminate_v1(beneficiary: &[u8]) -> !
Remove the calling account and transfer remaining free balance.
This function never returns. Either the termination was successful and the execution of the destroyed contract is halted. Or it failed during the termination which is considered fatal and results in a trap + rollback.
§Parameters
beneficiary
: The address of the beneficiary account, Should be decodable as anT::AccountId
.
§Traps
- The contract is live i.e is already on the call stack.
- Failed to send the balance to the beneficiary.
- The deletion queue is full.
Sourcefn value_transferred(output: &mut &mut [u8])
fn value_transferred(output: &mut &mut [u8])
Stores the value transferred along with this call/instantiate into the supplied buffer.
The data is encoded as T::Balance
.
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
output
: A reference to the output data buffer to write the transferred value.
Sourcefn weight_to_fee(gas: u64, output: &mut &mut [u8])
fn weight_to_fee(gas: u64, output: &mut &mut [u8])
Stores the price for the specified amount of gas into the supplied buffer.
Equivalent to the newer Self::weight_to_fee_v1
version but
works with ref_time Weight only. It is recommended to switch to the latest version, once
it’s stabilized.
Sourcefn weight_to_fee_v1(
ref_time_limit: u64,
proof_size_limit: u64,
output: &mut &mut [u8],
)
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn weight_to_fee_v1( ref_time_limit: u64, proof_size_limit: u64, output: &mut &mut [u8], )
Stores the price for the specified amount of gas into the supplied buffer.
The data is encoded as T::Balance
.
If the available space in output
is less than the size of the value a trap is triggered.
§Parameters
ref_time_limit
: The ref_time Weight limit to query the price for.proof_size_limit
: The proof_size Weight limit to query the price for.output
: A reference to the output data buffer to write the price.
Sourcefn xcm_execute(msg: &[u8]) -> Result<(), ReturnErrorCode>
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn xcm_execute(msg: &[u8]) -> Result<(), ReturnErrorCode>
Execute an XCM program locally, using the contract’s address as the origin.
This is equivalent to dispatching pallet_xcm::execute
through call_runtime, except that
the function is called directly instead of being dispatched.
§Parameters
msg
: The message, should be decodable as a VersionedXcm, traps otherwise.output
: A reference to the output data buffer to write the Outcome
§Return
Returns Error::Success
when the XCM execution attempt is successful. When the XCM
execution fails, ReturnCode::XcmExecutionFailed
is returned
Sourcefn xcm_send(
dest: &[u8],
msg: &[u8],
output: &mut [u8; 32],
) -> Result<(), ReturnErrorCode>
👎Deprecated: Unstable function. Behaviour can change without further notice. Use only for testing.
fn xcm_send( dest: &[u8], msg: &[u8], output: &mut [u8; 32], ) -> Result<(), ReturnErrorCode>
Send an XCM program from the contract to the specified destination.
This is equivalent to dispatching pallet_xcm::send
through call_runtime
, except that
the function is called directly instead of being dispatched.
§Parameters
dest
: The XCM destination, should be decodable as VersionedLocation, traps otherwise.msg
: The message, should be decodable as a VersionedXcm, traps otherwise.
§Return
Returns ReturnCode::Success
when the message was successfully sent. When the XCM
execution fails, ReturnErrorCode::XcmSendFailed
is returned.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.