|
14 | 14 | //! - `experimental`: Exposes the experimental bignum system library API. |
15 | 15 | //! |
16 | 16 | //! # Examples |
17 | | -//! ```ignore |
18 | | -//! extern crate ewasm_api; |
| 17 | +//! ``` |
| 18 | +//! use ewasm_api::prelude::*; |
| 19 | +//! |
| 20 | +//! fn entry() { |
| 21 | +//! let a: Hash = block_hash(1); |
| 22 | +//! finish_data(&a.bytes); |
| 23 | +//! } |
| 24 | +//! |
| 25 | +//! ewasm_entry_point!(entry); |
| 26 | +//! ``` |
19 | 27 | //! |
20 | | -//! use ewasm_api::{Hash, block_hash, finish_data}; |
| 28 | +//! Using lower-level primitives: |
| 29 | +//! ```ignore |
| 30 | +//! use ewasm_api::{types::Hash, block_hash, finish_data}; |
21 | 31 | //! |
22 | 32 | //! #[cfg(target_arch = "wasm32")] |
23 | 33 | //! #[no_mangle] |
24 | 34 | //! pub extern "C" fn main() { |
25 | | -//! let a: Hash = block_hash(1); |
| 35 | +//! let a: types::Hash = block_hash(1); |
26 | 36 | //! finish_data(&a.bytes); |
27 | 37 | //! } |
28 | 38 | //! ``` |
| 39 | +//! |
29 | 40 |
|
30 | 41 | #[macro_use] |
31 | 42 | extern crate cfg_if; |
@@ -85,6 +96,19 @@ pub mod prelude { |
85 | 96 | pub use crate::eth2; |
86 | 97 | } |
87 | 98 |
|
| 99 | +/// Declare entry point for a contract. Expects a Rust function name to be executed. |
| 100 | +/// This will only compile in when using the wasm32 target. |
| 101 | +#[macro_export] |
| 102 | +macro_rules! ewasm_entry_point { |
| 103 | + ($name:ident) => { |
| 104 | + #[cfg(target_arch = "wasm32")] |
| 105 | + #[no_mangle] |
| 106 | + pub extern "C" fn main() { |
| 107 | + $name() |
| 108 | + } |
| 109 | + }; |
| 110 | +} |
| 111 | + |
88 | 112 | /// Enum representing an error code for EEI calls. Currently used by `codeCopy`, `callDataCopy`, |
89 | 113 | /// `externalCodeCopy`, and `returnDataCopy`. |
90 | 114 | pub enum Error { |
|
0 commit comments