[−][src]Struct near_vm_logic::VMLogic
Methods
impl<'a> VMLogic<'a>
[src]
pub fn new(
ext: &'a mut dyn External,
context: VMContext,
config: &'a Config,
promise_results: &'a [PromiseResult],
memory: &'a mut dyn MemoryLike
) -> Self
[src]
ext: &'a mut dyn External,
context: VMContext,
config: &'a Config,
promise_results: &'a [PromiseResult],
memory: &'a mut dyn MemoryLike
) -> Self
pub fn read_register(
&mut self,
register_id: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
register_id: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
Writes the entire content from the register register_id
into the memory of the guest starting with ptr
.
Arguments
register_id
-- a register id from where to read the data;ptr
-- location on guest memory where to copy the data.
Errors
- If the content extends outside the memory allocated to the guest. In Wasmer, it returns
MemoryAccessViolation
error message; - If
register_id
is pointing to unused register returnsInvalidRegisterId
error message.
Undefined Behavior
If the content of register extends outside the preallocated memory on the host side, or the pointer points to a wrong location this function will overwrite memory that it is not supposed to overwrite causing an undefined behavior.
pub fn register_len(
&mut self,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
Returns the size of the blob stored in the given register.
- If register is used, then returns the size, which can potentially be zero;
- If register is not used, returns
u64::MAX
Arguments
register_id
-- a register id from where to read the data;
pub fn write_register(
&mut self,
register_id: u64,
data: &[u8]
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
register_id: u64,
data: &[u8]
) -> Result<(), HostErrorOrStorageError>
Copies data
into register. If register is unused will initialize it. If register has
larger capacity than needed for data
will not re-allocate it. The register will lose
the pre-existing data if any.
Arguments
register_id
-- a register into which to write the data;data
-- data to be copied into register.
pub fn current_account_id(
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
Saves the account id of the current contract that we execute into the register.
Errors
If the registers exceed the memory limit returns MemoryAccessViolation
.
pub fn signer_account_id(
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
All contract calls are a result of some transaction that was signed by some account using some access key and submitted into a memory pool (either through the wallet using RPC or by a node itself). This function returns the id of that account. Saves the bytes of the signer account id into the register.
Errors
- If the registers exceed the memory limit returns
MemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn signer_account_pk(
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
Saves the public key fo the access key that was used by the signer into the register. In rare situations smart contract might want to know the exact access key that was used to send the original transaction, e.g. to increase the allowance or manipulate with the public key.
Errors
- If the registers exceed the memory limit returns
MemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn predecessor_account_id(
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
All contract calls are a result of a receipt, this receipt might be created by a transaction that does function invocation on the contract or another contract as a result of cross-contract call. Saves the bytes of the predecessor account id into the register.
Errors
- If the registers exceed the memory limit returns
MemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn input(&mut self, register_id: u64) -> Result<(), HostErrorOrStorageError>
[src]
Reads input to the contract call into the register. Input is expected to be in JSON-format.
If input is provided saves the bytes (potentially zero) of input into register. If input is
not provided makes the register "not used", i.e. register_len
now returns u64::MAX
.
pub fn block_index(&mut self) -> Result<u64, HostErrorOrStorageError>
[src]
Returns the current block index.
pub fn block_timestamp(&mut self) -> Result<u64, HostErrorOrStorageError>
[src]
Returns the current block timestamp.
pub fn storage_usage(&mut self) -> Result<StorageUsage, HostErrorOrStorageError>
[src]
Returns the number of bytes used by the contract if it was saved to the trie as of the invocation. This includes:
- The data written with storage_* functions during current and previous execution;
- The bytes needed to store the access keys of the given account.
- The contract code size
- A small fixed overhead for account metadata.
pub fn account_balance(
&mut self,
balance_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
balance_ptr: u64
) -> Result<(), HostErrorOrStorageError>
The current balance of the given account. This includes the attached_deposit that was attached to the transaction.
pub fn attached_deposit(
&mut self,
balance_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
balance_ptr: u64
) -> Result<(), HostErrorOrStorageError>
The balance that was attached to the call that will be immediately deposited before the contract execution starts.
Errors
If called as view function returns `ProhibitedInView``.
pub fn prepaid_gas(&mut self) -> Result<Gas, HostErrorOrStorageError>
[src]
The amount of gas attached to the call that can be used to pay for the gas fees.
Errors
If called as view function returns ProhibitedInView
.
pub fn used_gas(&mut self) -> Result<Gas, HostErrorOrStorageError>
[src]
The gas that was already burnt during the contract execution (cannot exceed prepaid_gas
)
Errors
If called as view function returns ProhibitedInView
.
pub fn random_seed(
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
Writes random seed into the register.
Errors
If the size of the registers exceed the set limit MemoryAccessViolation
.
pub fn sha256(
&mut self,
value_len: u64,
value_ptr: u64,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
value_len: u64,
value_ptr: u64,
register_id: u64
) -> Result<(), HostErrorOrStorageError>
Hashes the random sequence of bytes using sha256 and returns it into register_id
.
Errors
If value_len + value_ptr
points outside the memory or the registers use more memory than
the limit with MemoryAccessViolation
.
pub fn gas(&mut self, gas_amount: u32) -> Result<(), HostErrorOrStorageError>
[src]
Called by gas metering injected into Wasm. Counts both towards burnt_gas
and used_gas
.
Errors
- If passed gas amount somehow overflows internal gas counters returns
IntegerOverflow
; - If we exceed usage limit imposed on burnt gas returns
UsageLimit
; - If we exceed the
prepaid_gas
then returnsBalanceExceeded
.
pub fn promise_create(
&mut self,
account_id_len: u64,
account_id_ptr: u64,
method_name_len: u64,
method_name_ptr: u64,
arguments_len: u64,
arguments_ptr: u64,
amount_ptr: u64,
gas: Gas
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
account_id_len: u64,
account_id_ptr: u64,
method_name_len: u64,
method_name_ptr: u64,
arguments_len: u64,
arguments_ptr: u64,
amount_ptr: u64,
gas: Gas
) -> Result<u64, HostErrorOrStorageError>
Creates a promise that will execute a method on account with given arguments and attaches
the given amount and gas. amount_ptr
point to slices of bytes representing u128
.
Errors
- If
account_id_len + account_id_ptr
ormethod_name_len + method_name_ptr
orarguments_len + arguments_ptr
oramount_ptr + 16
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
Returns
Index of the new promise that uniquely identifies it within the current execution of the method.
pub fn promise_then(
&mut self,
promise_idx: u64,
account_id_len: u64,
account_id_ptr: u64,
method_name_len: u64,
method_name_ptr: u64,
arguments_len: u64,
arguments_ptr: u64,
amount_ptr: u64,
gas: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
account_id_len: u64,
account_id_ptr: u64,
method_name_len: u64,
method_name_ptr: u64,
arguments_len: u64,
arguments_ptr: u64,
amount_ptr: u64,
gas: u64
) -> Result<u64, HostErrorOrStorageError>
Attaches the callback that is executed after promise pointed by promise_idx
is complete.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
; - If
account_id_len + account_id_ptr
ormethod_name_len + method_name_ptr
orarguments_len + arguments_ptr
oramount_ptr + 16
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
Returns
Index of the new promise that uniquely identifies it within the current execution of the method.
pub fn promise_and(
&mut self,
promise_idx_ptr: u64,
promise_idx_count: u64
) -> Result<PromiseIndex, HostErrorOrStorageError>
[src]
&mut self,
promise_idx_ptr: u64,
promise_idx_count: u64
) -> Result<PromiseIndex, HostErrorOrStorageError>
Creates a new promise which completes when time all promises passed as arguments complete.
Cannot be used with registers. promise_idx_ptr
points to an array of u64
elements, with
promise_idx_count
denoting the number of elements. The array contains indices of promises
that need to be waited on jointly.
Errors
- If
promise_ids_ptr + 8 * promise_idx_count
extend outside the guest memory returnsMemoryAccessViolation
; - If any of the promises in the array do not correspond to existing promises returns
InvalidPromiseIndex
. - If called as view function returns
ProhibitedInView
.
Returns
Index of the new promise that uniquely identifies it within the current execution of the method.
pub fn promise_batch_create(
&mut self,
account_id_len: u64,
account_id_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
account_id_len: u64,
account_id_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
Creates a new promise towards given account_id
without any actions attached to it.
Errors
- If
account_id_len + account_id_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
Returns
Index of the new promise that uniquely identifies it within the current execution of the method.
pub fn promise_batch_then(
&mut self,
promise_idx: u64,
account_id_len: u64,
account_id_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
account_id_len: u64,
account_id_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
Creates a new promise towards given account_id
without any actions attached, that is
executed after promise pointed by promise_idx
is complete.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
; - If
account_id_len + account_id_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
Returns
Index of the new promise that uniquely identifies it within the current execution of the method.
pub fn promise_batch_action_create_account(
&mut self,
promise_idx: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64
) -> Result<(), HostErrorOrStorageError>
Appends CreateAccount
action to the batch of actions for the given promise pointed by
promise_idx
.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_deploy_contract(
&mut self,
promise_idx: u64,
code_len: u64,
code_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
code_len: u64,
code_ptr: u64
) -> Result<(), HostErrorOrStorageError>
Appends DeployContract
action to the batch of actions for the given promise pointed by
promise_idx
.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If
code_len + code_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_function_call(
&mut self,
promise_idx: u64,
method_name_len: u64,
method_name_ptr: u64,
arguments_len: u64,
arguments_ptr: u64,
amount_ptr: u64,
gas: Gas
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
method_name_len: u64,
method_name_ptr: u64,
arguments_len: u64,
arguments_ptr: u64,
amount_ptr: u64,
gas: Gas
) -> Result<(), HostErrorOrStorageError>
Appends FunctionCall
action to the batch of actions for the given promise pointed by
promise_idx
.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If
method_name_len + method_name_ptr
orarguments_len + arguments_ptr
oramount_ptr + 16
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_transfer(
&mut self,
promise_idx: u64,
amount_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
amount_ptr: u64
) -> Result<(), HostErrorOrStorageError>
Appends Transfer
action to the batch of actions for the given promise pointed by
promise_idx
.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If
amount_ptr + 16
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_stake(
&mut self,
promise_idx: u64,
amount_ptr: u64,
public_key_len: u64,
public_key_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
amount_ptr: u64,
public_key_len: u64,
public_key_ptr: u64
) -> Result<(), HostErrorOrStorageError>
Appends Stake
action to the batch of actions for the given promise pointed by
promise_idx
.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If the given public key is not a valid (e.g. wrong length) returns
InvalidPublicKey
. - If
amount_ptr + 16
orpublic_key_len + public_key_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_add_key_with_full_access(
&mut self,
promise_idx: u64,
public_key_len: u64,
public_key_ptr: u64,
nonce: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
public_key_len: u64,
public_key_ptr: u64,
nonce: u64
) -> Result<(), HostErrorOrStorageError>
Appends AddKey
action to the batch of actions for the given promise pointed by
promise_idx
. The access key will have FullAccess
permission.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If the given public key is not a valid (e.g. wrong length) returns
InvalidPublicKey
. - If
public_key_len + public_key_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_add_key_with_function_call(
&mut self,
promise_idx: u64,
public_key_len: u64,
public_key_ptr: u64,
nonce: u64,
allowance_ptr: u64,
receiver_id_len: u64,
receiver_id_ptr: u64,
method_names_len: u64,
method_names_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
public_key_len: u64,
public_key_ptr: u64,
nonce: u64,
allowance_ptr: u64,
receiver_id_len: u64,
receiver_id_ptr: u64,
method_names_len: u64,
method_names_ptr: u64
) -> Result<(), HostErrorOrStorageError>
Appends AddKey
action to the batch of actions for the given promise pointed by
promise_idx
. The access key will have FunctionCall
permission.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If the given public key is not a valid (e.g. wrong length) returns
InvalidPublicKey
. - If
public_key_len + public_key_ptr
,allowance_ptr + 16
,receiver_id_len + receiver_id_ptr
ormethod_names_len + method_names_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_delete_key(
&mut self,
promise_idx: u64,
public_key_len: u64,
public_key_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
public_key_len: u64,
public_key_ptr: u64
) -> Result<(), HostErrorOrStorageError>
Appends DeleteKey
action to the batch of actions for the given promise pointed by
promise_idx
.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If the given public key is not a valid (e.g. wrong length) returns
InvalidPublicKey
. - If
public_key_len + public_key_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_batch_action_delete_account(
&mut self,
promise_idx: u64,
beneficiary_id_len: u64,
beneficiary_id_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64,
beneficiary_id_len: u64,
beneficiary_id_ptr: u64
) -> Result<(), HostErrorOrStorageError>
Appends DeleteAccount
action to the batch of actions for the given promise pointed by
promise_idx
.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If the promise pointed by the
promise_idx
is an ephemeral promise created bypromise_and
returnsCannotAppendActionToJointPromise
. - If
beneficiary_id_len + beneficiary_id_ptr
points outside the memory of the guest or host returnsMemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_results_count(&self) -> Result<u64, HostErrorOrStorageError>
[src]
If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the number of complete and incomplete callbacks.
Note, we are only going to have incomplete callbacks once we have promise_or combinator.
- If there is only one callback returns
1
; - If there are multiple callbacks (e.g. created through
promise_and
) returns their number; - If the function was called not through the callback returns
0
.
pub fn promise_result(
&mut self,
result_idx: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
result_idx: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result in blob format and places it into the register.
- If promise result is complete and successful copies its blob into the register;
- If promise result is complete and failed or incomplete keeps register unused;
Returns
- If promise result is not complete returns
0
; - If promise result is complete and successful returns
1
; - If promise result is complete and failed returns
2
.
Errors
- If
result_id
does not correspond to an existing result returnsInvalidResultIndex
; - If copying the blob exhausts the memory limit it returns
MemoryAccessViolation
. - If called as view function returns
ProhibitedInView
.
pub fn promise_return(
&mut self,
promise_idx: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
promise_idx: u64
) -> Result<(), HostErrorOrStorageError>
When promise promise_idx
finishes executing its result is considered to be the result of
the current function.
Errors
- If
promise_idx
does not correspond to an existing promise returnsInvalidPromiseIndex
. - If called as view function returns
ProhibitedInView
.
pub fn value_return(
&mut self,
value_len: u64,
value_ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
value_len: u64,
value_ptr: u64
) -> Result<(), HostErrorOrStorageError>
Sets the blob of data as the return value of the contract.
Errors
If value_len + value_ptr
exceeds the memory container or points to an unused register it
returns MemoryAccessViolation
.
pub fn panic(&self) -> Result<(), HostErrorOrStorageError>
[src]
Terminates the execution of the program with panic GuestPanic
.
pub fn panic_utf8(
&mut self,
len: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
len: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
Guest panics with the UTF-8 encoded string.
If len == u64::MAX
then treats the string as null-terminated with character '\0'
.
Errors
- If string extends outside the memory of the guest with
MemoryAccessViolation
; - If string is not UTF-8 returns
BadUtf8
. - If string is longer than
max_log_len
returnsBadUtf8
.
pub fn log_utf8(
&mut self,
len: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
len: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
Logs the UTF-8 encoded string.
If len == u64::MAX
then treats the string as null-terminated with character '\0'
.
Errors
- If string extends outside the memory of the guest with
MemoryAccessViolation
; - If string is not UTF-8 returns
BadUtf8
. - If string is longer than
max_log_len
returnsBadUtf8
.
pub fn log_utf16(
&mut self,
len: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
len: u64,
ptr: u64
) -> Result<(), HostErrorOrStorageError>
Logs the UTF-16 encoded string. If len == u64::MAX
then treats the string as
null-terminated with two-byte sequence of 0x00 0x00
.
Errors
- If string extends outside the memory of the guest with
MemoryAccessViolation
; - If string is not UTF-16 returns
BadUtf16
.
pub fn abort(
&mut self,
msg_ptr: u32,
filename_ptr: u32,
line: u32,
col: u32
) -> Result<(), HostErrorOrStorageError>
[src]
&mut self,
msg_ptr: u32,
filename_ptr: u32,
line: u32,
col: u32
) -> Result<(), HostErrorOrStorageError>
Special import kept for compatibility with AssemblyScript contracts. Not called by smart contracts directly, but instead called by the code generated by AssemblyScript.
pub fn read_and_parse_account_id(
&self,
ptr: u64,
len: u64
) -> Result<AccountId, HostErrorOrStorageError>
[src]
&self,
ptr: u64,
len: u64
) -> Result<AccountId, HostErrorOrStorageError>
Reads account id from the given location in memory.
Errors
- If account is not UTF-8 encoded then returns
BadUtf8
;
pub fn storage_write(
&mut self,
key_len: u64,
key_ptr: u64,
value_len: u64,
value_ptr: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
key_len: u64,
key_ptr: u64,
value_len: u64,
value_ptr: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
Writes key-value into storage.
- If key is not in use it inserts the key-value pair and does not modify the register. Returns
0
; - If key is in use it inserts the key-value and copies the old value into the
register_id
. Returns1
.
Errors
- If
key_len + key_ptr
orvalue_len + value_ptr
exceeds the memory container or points to an unused register it returnsMemoryAccessViolation
; - If returning the preempted value into the registers exceed the memory container it returns
MemoryAccessViolation
.
pub fn storage_read(
&mut self,
key_len: u64,
key_ptr: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
key_len: u64,
key_ptr: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
Reads the value stored under the given key.
- If key is used copies the content of the value into the
register_id
, even if the content is zero bytes. Returns1
; - If key is not present then does not modify the register. Returns
0
;
Errors
- If
key_len + key_ptr
exceeds the memory container or points to an unused register it returnsMemoryAccessViolation
; - If returning the preempted value into the registers exceed the memory container it returns
MemoryAccessViolation
.
pub fn storage_remove(
&mut self,
key_len: u64,
key_ptr: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
key_len: u64,
key_ptr: u64,
register_id: u64
) -> Result<u64, HostErrorOrStorageError>
Removes the value stored under the given key.
- If key is used, removes the key-value from the trie and copies the content of the value
into the
register_id
, even if the content is zero bytes. Returns1
; - If key is not present then does not modify the register. Returns
0
.
Errors
- If
key_len + key_ptr
exceeds the memory container or points to an unused register it returnsMemoryAccessViolation
; - If the registers exceed the memory limit returns
MemoryAccessViolation
; - If returning the preempted value into the registers exceed the memory container it returns
MemoryAccessViolation
.
pub fn storage_has_key(
&mut self,
key_len: u64,
key_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
key_len: u64,
key_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
Checks if there is a key-value pair.
- If key is used returns
1
, even if the value is zero bytes; - Otherwise returns
0
.
Errors
If key_len + key_ptr
exceeds the memory container it returns MemoryAccessViolation
.
pub fn storage_iter_prefix(
&mut self,
prefix_len: u64,
prefix_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
prefix_len: u64,
prefix_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
Creates an iterator object inside the host. Returns the identifier that uniquely differentiates the given iterator from other iterators that can be simultaneously created.
- It iterates over the keys that have the provided prefix. The order of iteration is defined by the lexicographic order of the bytes in the keys;
- If there are no keys, it creates an empty iterator, see below on empty iterators.
Errors
If prefix_len + prefix_ptr
exceeds the memory container it returns MemoryAccessViolation
.
pub fn storage_iter_range(
&mut self,
start_len: u64,
start_ptr: u64,
end_len: u64,
end_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
start_len: u64,
start_ptr: u64,
end_len: u64,
end_ptr: u64
) -> Result<u64, HostErrorOrStorageError>
Iterates over all key-values such that keys are between start
and end
, where start
is
inclusive and end
is exclusive. Unless lexicographically start < end
, it creates an
empty iterator. Note, this definition allows for start
or end
keys to not actually exist
on the given trie.
Errors
If start_len + start_ptr
or end_len + end_ptr
exceeds the memory container or points to
an unused register it returns MemoryAccessViolation
.
pub fn storage_iter_next(
&mut self,
iterator_id: u64,
key_register_id: u64,
value_register_id: u64
) -> Result<u64, HostErrorOrStorageError>
[src]
&mut self,
iterator_id: u64,
key_register_id: u64,
value_register_id: u64
) -> Result<u64, HostErrorOrStorageError>
Advances iterator and saves the next key and value in the register.
- If iterator is not empty (after calling next it points to a key-value), copies the key
into
key_register_id
and value intovalue_register_id
and returns1
; - If iterator is empty returns
0
; This allows us to iterate over the keys that have zero bytes stored in values.
Errors
- If
key_register_id == value_register_id
returnsMemoryAccessViolation
; - If the registers exceed the memory limit returns
MemoryAccessViolation
; - If
iterator_id
does not correspond to an existing iterator returnsInvalidIteratorId
; - If between the creation of the iterator and calling
storage_iter_next
the range over which it iterates was modified returnsIteratorWasInvalidated
. Specifically, ifstorage_write
orstorage_remove
was invoked on the key key such that:- in case of
storage_iter_prefix
.key
has the given prefix and:- Iterator was not called next yet.
next
was already called on the iterator and it is currently pointing at thekey
curr
such thatcurr <= key
.
- in case of
storage_iter_range
.start<=key<end
and:- Iterator was not called
next
yet. next
was already called on the iterator and it is currently pointing at the keycurr
such thatcurr<=key<end
.
- Iterator was not called
- in case of
pub fn outcome(self) -> VMOutcome
[src]
Computes the outcome of execution.
Auto Trait Implementations
impl<'a> !Send for VMLogic<'a>
impl<'a> !Sync for VMLogic<'a>
impl<'a> Unpin for VMLogic<'a>
impl<'a> !UnwindSafe for VMLogic<'a>
impl<'a> !RefUnwindSafe for VMLogic<'a>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,