Attribute Macro sewup_derive::ewasm_main[][src]

#[ewasm_main]
Expand description

helps you setup the main function of a contract

There are three different kind contract output, and the return Result can based on anyhow::Result or std::result::Result. If you want to use std::result::Result, you need to set up default option with default message in default mode and auto mode, such that there will be a return message in bytes let you know some error happen.

#[ewasm_main] The default contract output, the Anyhow error will be return as a string message This is for a scenario that you just want to modify the data on chain only, and the error will to string than return.

#[ewasm_main(default="message")] The default contract output, if any error happened the default message will be returned

#[ewasm_main(rusty)] The rust style output, the result object from ewasm_main function will be returned, this is for a scenario that you are using a rust client to catch and want to catch the result from the contract.

#[ewasm_main(auto)] Auto unwrap the OK output of the Anyhow::Result object from ewasm_main function. This is for a scenario that you are using a rust non-rust client, and you are only care the happy case of executing the contract.

#[ewasm_main(auto, default="message")] Auto unwrap the OK output of the result object (it can be Anyhow::Result or std::result::Result) from ewasm_main function, if any error happened the default message will be returned. This is for a scenario that you are using a rust non-rust client, and you are only care the happy case of executing the contract.

#[ewasm_main]
fn main() -> anyhow::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(())
}
#[ewasm_main(auto, default = "Some error happen")]
fn main() -> Result<String, ()> {
    let contract = sewup::primitives::Contract::new().expect("contract should work");
    match contract
        .get_function_selector()
        .expect("function selector should work")
    {
        sewup_derive::ewasm_fn_sig!(hello) => hello(),
        _ => Err(()),
    }
}