Expand description

This module provides the primitive interface to the chain. Functions here should be wrapped in safer wrappers when used from contracts. This module is provided for expert users who wish to optimize their smart contract to the utmost for space and size, and should not be used by the majority of users.

The functions in this module are inherently unsafe, and if preconditions that they state are not ensured then strange behaviour will occur. The behaviour is well-defined on the compiled Wasm by the semantics of the chain, but it is essentially impossible to predict since it is affected by memory layout decided by the compiler and the allocator, and other Rust implementation details. Consequences can range from accidental memory corruption to program termination.

Functions

Address of the sender, 32 bytes

Write a section of the i-th parameter to the given location. Return the number of bytes written or -1 if the parameter does not exist. The location is assumed to contain enough memory to write the requested length into.

Get the size of the i-th parameter to the call. 0-th parameter is always the original parameter that the method was invoked with, invoking a contract adds additional parameters to the stack. Returns -1 if the given parameter does not exist.

Write a section of the policy to the given location. Return the number of bytes written. The location is assumed to contain enough memory to write the requested length into.

Write the receive entrypoint name into the given location. It is assumed that the location contains enough space to write the name.

Get the size of the entrypoint that was named.

Invoker of the top-level transaction, AccountAddress.

Owner of the contract, AccountAddress.

Address of the contract itself, ContractAddress.

Self-balance of the contract, returns the amount

Immediate sender of the message (either contract or account).

Slot time (in milliseconds) from chain meta data

Hash the data using Keccak-256 algorithm. The resulting hash (32 bytes) is written starting at the output pointer. The output segment may overlap with the data segment.

Hash the data using the SHA2-256 algorithm. The resulting hash (32 bytes) is written starting at the output pointer. The output segment may overlap with the data segment.

Hash the data using the SHA3-256 algorithm. The resulting hash (32 bytes) is written starting at the output pointer. The output segment may overlap with the data segment.

Invoke a host instruction. The arguments are

Add a log item. Return values are

Create an empty entry with the given key. The return value is either u64::MAX if creating the entry failed because of an iterator lock on the part of the tree, or else the first bit is 0, and the remaining bits are an entry identifier that maybe used in subsequent calls. If an entry at that key already exists it is set to the empty entry.

Delete the entry. Returns one of

Delete a prefix in the tree, that is, delete all parts of the tree that have the given key as prefix. Returns

Read a part of the entry. The arguments are entry … entry id returned by state_iterator_next or state_create_entry start … where to write in Wasm memory length … length of the data to read offset … where to start reading in the entry The return value is

Resize the entry to the given size. Returns

Return the current size of the entry in bytes. The return value is either

Write a part of the entry. The arguments are entry … entry id returned by state_iterator_next or state_create_entry start … where to read from Wasm memory length … length of the data to read offset … where to start writing in the entry The return value is

Construct an iterator over a part of the tree. This locks the part of the tree that has the given prefix. Locking means that no deletions or insertions of entries may occur in that subtree. Returns

Delete the iterator, unlocking the subtree. Returns

Read a section of the key the iterator is currently pointing at. Returns either

Get the size of the key that the iterator is currently pointing at. Returns

Return the next entry along the iterator, and advance the iterator. The return value is

Lookup an entry with the given key. The return value is either u64::MAX if the entry at the given key does not exist, or else the first bit of the result is 0, and the remaining bits are an entry identifier that may be used in subsequent calls.

Verify an ecdsa over secp256k1 with bitcoin-core implementation. The public key is expected to be 33 bytes, the signature is expected to be 64 bytes (serialized in compressed format), and the message must be 32 bytes. We only allow checking signatures on 32-byte arrays which are expected to be message hashes.

Verify an ed25519 signature. The public key is expected to be 32 bytes, the signature is expected to be 64 bytes, and the message may be variable length.

Write to the return value of the contract. The parameters are