stylus_sdk::abi

Trait Router

Source
pub trait Router<S>
where S: TopLevelStorage + BorrowMut<Self::Storage>,
{ type Storage; // Required methods fn route(storage: &mut S, selector: u32, input: &[u8]) -> Option<ArbResult>; fn receive(storage: &mut S) -> Option<Result<(), Vec<u8>>>; fn fallback(storage: &mut S, calldata: &[u8]) -> Option<ArbResult>; }
Expand description

Executes a method given a selector and calldata. This trait can be automatically implemented via #[public]. Composition with other routers is possible via #[inherit].

Required Associated Types§

Source

type Storage

The type the TopLevelStorage borrows into. Usually just Self.

Required Methods§

Source

fn route(storage: &mut S, selector: u32, input: &[u8]) -> Option<ArbResult>

Tries to find and execute a method for the given selector, returning None if none is found. Routes add via #[inherit] will only execute if no match is found among Self. This means that it is possible to override a method by redefining it in Self.

Source

fn receive(storage: &mut S) -> Option<Result<(), Vec<u8>>>

Receive function for this contract. Called when no calldata is provided. A receive function may not be defined, in which case this method will return None. Receive functions are always payable, take in no inputs, and return no outputs. If defined, they will always be called when a transaction does not send any calldata, regardless of the transaction having a value attached.

Source

fn fallback(storage: &mut S, calldata: &[u8]) -> Option<ArbResult>

Called when no receive function is defined. If no #[fallback] function is defined in the contract, then any transactions that do not match a selector will revert. A fallback function may have two different implementations. It can be either declared without any input or output, or with bytes input calldata and bytes output. If a user defines a fallback function with no input or output, then this method will be called and the underlying user-defined function will simply be invoked with no input. A fallback function can be declared as payable. If not payable, then any transactions that trigger a fallback with value attached will revert.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§