Attribute Macro sewup_derive::ewasm_lib_fn [−][src]
#[ewasm_lib_fn]
Expand description
helps you to build your handler in other module
This macro will automatically generated as {FUNCTION_NAME}_SIG
ⓘ
// module.rs
use sewup::ewasm_api;
#[ewasm_lib_fn]
pub fn symbol(s: &str) {
let symbol = s.to_string().into_bytes();
ewasm_api::finish_data(&symbol);
}
ⓘ
// lib.rs
use module::{symbol, SYMBOL_SIG};
#[ewasm_main]
fn main() -> Result<()> {
let contract = Contract::new()?;
match contract.get_function_selector()? {
SYMBOL_SIG => symbol("ETD"),
_ => return Err(Error::UnknownHandle.into()),
};
Ok(())
}
There are two kind of inputs for ewasm_fn
macro, first is functional signature, second and
more are the fields of abijson.
The functional signature can be specific as following ways.
#[ewasm_lib_fn(00fdd58e)]
or #[ewasm_lib_fn(“00fdd58e”)]
constant=true,
inputs=[
{ "internalType": "address", "name": "account", "type": "address" },
{ "internalType": "uint256", "name": "token_id", "type": "uint256" }
],
name=balanceOf,
outputs=[
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
payable=false,
stateMutability=view
)]
The fields are not required, it can use default value if not provided.
The default values of constant
, payable
are false
; the default values of inputs
and
outputs
are []
; the default value of stateMutability
is view
; the default name is the
camel case style of the function name.