Type Definition concordium_std::ReceiveResult

source ·
pub type ReceiveResult<A> = Result<A, Reject>;
Expand description

The expected return type of the receive method of a smart contract.

Optionally, to define a custom type for error instead of using Reject, allowing to track the reason for rejection, but only in unit tests.

See also the documentation for bail! for how to use custom error types.

Example

Defining a custom error type that implements Reject and Serial.

#[derive(Serial, Reject)]
enum MyCustomError {
    SomeError,
}

#[receive(contract = "mycontract", name = "receive")]
fn contract_receive<S: HasStateApi>(
    _ctx: &impl HasReceiveContext,
    _host: &impl HasHost<(), StateApiType = S>,
) -> Result<(), MyCustomError> {
    Err(MyCustomError::SomeError)
}