[][src]Crate ewasm_api

ewasm_api is a library used to interface with Ethereum's EEI in Ewasm, a set of enhancements to the Ethereum smart contract platform. ewasm_api exposes both a set of unsafe "native" functions representing the actual EEI functions, and a set of safe wrappers around them. It is recommended not to use the native functions as they do not perform bounds-checking.

To use ewasm_api, simply include it as a dependency in your project. ewasm_api can be built with various feature sets:

  • default: Builds with wee_alloc as the global allocator and with the Rust standard library.
  • qimalloc: Builds with qimalloc as the global allocator.
  • debug: Exposes the debugging interface.
  • experimental: Exposes the experimental bignum system library API.

Examples

use ewasm_api::prelude::*;

fn entry() {
    let a: Hash = block_hash(1);
    finish_data(&a.bytes);
}

ewasm_entry_point!(entry);

Using lower-level primitives:

This example is not tested
use ewasm_api::{types::Hash, block_hash, finish_data};

#[cfg(target_arch = "wasm32")]
#[no_mangle]
pub extern "C" fn main() {
    let a: types::Hash = block_hash(1);
    finish_data(&a.bytes);
}

Modules

prelude

Re-export of all the basic features.

types

High-level types commonly used in Ethereum contracts.

Macros

ewasm_entry_point

Declare entry point for a contract. Expects a Rust function name to be executed. This will only compile in when using the wasm32 target.

Enums

CallResult

Enum describing the result of a call. Used by call, callCode, callDelegate, and callStatic.

CreateResult

Enum describing the result of create. On success, the data contained is the address of the newly created contract.

Error

Enum representing an error code for EEI calls. Currently used by codeCopy, callDataCopy, externalCodeCopy, and returnDataCopy.

Functions

abort

Halts execution, reverts all changes to the state and consumes all gas.

block_coinbase

Returns the beneficiary address for the block this transaction is in (current block)

block_difficulty

Returns the difficulty of the most recent block.

block_gas_limit

Returns the gas limit of the most recent block.

block_hash

Returns the hash of the numberth most recent block.

block_number

Returns the number of the most recent block.

block_timestamp

Returns the timestamp of the most recent block.

call_code

Executes another account's code in the context of the caller.

call_delegate

Executes a call similar to call_code, but retaining the currently executing call's sender and value.

call_mutable

Executes a standard call to the specified address with the given gas limit, ether value, and data.

call_static

Executes a static call which cannot mutate the state.

calldata_acquire

Returns a vector containing all data passed with the currently executing call.

calldata_copy

Returns the segment of call data beginning at from, and continuing for length bytes.

calldata_size

Returns the length of the call data supplied with the currently executing call.

caller

Returns the sender of the currently executing call.

callvalue

Returns the value sent with the currently executing call.

code_acquire

Returns the currently executing code.

code_copy

Copies the segment of running code beginning at from and continuing for length bytes.

code_size

Returns the size of the currently executing code.

consume_gas

Subtracts the given amount from the VM's gas counter. This is usually injected by the metering contract at deployment time, and hence is unneeded in most cases.

create

Creates a contract with the the given code, sending the specified ether value to its address.

current_address

Returns the executing address.

external_balance

Returns the balance of the address given.

external_code_acquire

Returns the code at the specified address.

external_code_copy

Returns the segment of code at address beginning at from and continuing for length bytes.

external_code_size

Returns the size of the code at the specified address.

finish

Ends execution, signalling success.

finish_data

Fills the return buffer with the given data and halts execution, signalling success.

gas_left

Returns the gas left in the current call.

log0

Appends log data without a topic.

log1

Appends log data with one topic.

log2

Appends log data with two topics.

log3

Appends log data with three topics.

log4

Appends log data with four topics.

returndata_acquire

Returns the data in the VM's return buffer.

returndata_copy

Returns the segment of return buffer data beginning at from and continuing for length bytes.

returndata_size

Returns the length of the data in the VM's return buffer.

revert

Halts execution and reverts all changes to the state.

revert_data

Fills the return buffer with the given data and halts execution, reverting all state changes.

selfdestruct

Self-destructs the running contract, sending all its ether to a specified beneficiary address.

storage_load

Accesses the storage data at the specified key.

storage_store

Sets the storage data at the specified key.

tx_gas_price

Returns the gas price of the currently executing call.

tx_origin

Returns the address of the original transaction sender.

unsafe_calldata_copy

Executes callDataCopy, but does not check for overflow.

unsafe_code_copy

Executes codeCopy, but does not check for overflow.

unsafe_external_code_copy

Executes externalCodeCopy, but does not check for overflow.

unsafe_returndata_copy

Executes returnDataCopy, but does not check for overflow.