ewasm_input_from!() { /* proc-macro */ }
Expand description

helps you to get the input data from contract caller

This macro automatically deserialize input into handler ewasm_input_from!(contract, the_name_of_the_handler)

#[ewasm_main]
fn main() -> Result<()> {
    let contract = Contract::new()?;
    match contract.get_function_selector()? {
        ewasm_fn_sig!(check_input_object) => ewasm_input_from!(contract move check_input_object)?,
        _ => return Err(Error::UnknownHandle.into()),
    };
 Ok(())
 }

Besides, you can map the error to your customized error when something wrong happened in ewasm_input_from!, for example: ewasm_input_from!(contract move check_input_object, |_| Err("DeserdeError"))

#[ewasm_main(rusty)]
fn main() -> Result<(), &'static str> {
    let contract = Contract::new().map_err(|_| "NewContractError")?;
    match contract.get_function_selector().map_err(|_| "FailGetFnSelector")? {
        ewasm_fn_sig!(check_input_object) =>  ewasm_input_from!(contract move check_input_object, |_| "DeserdeError")?
        _ => return Err("UnknownHandle"),
    };
    Ok(())
}