alloy_sol_types

Trait SolInterface

Source
pub trait SolInterface: Sized {
    const NAME: &'static str;
    const MIN_DATA_LENGTH: usize;
    const COUNT: usize;

    // Required methods
    fn selector(&self) -> [u8; 4];
    fn selector_at(i: usize) -> Option<[u8; 4]>;
    fn valid_selector(selector: [u8; 4]) -> bool;
    fn abi_decode_raw(
        selector: [u8; 4],
        data: &[u8],
        validate: bool,
    ) -> Result<Self>;
    fn abi_encoded_size(&self) -> usize;
    fn abi_encode_raw(&self, out: &mut Vec<u8>);

    // Provided methods
    fn type_check(selector: [u8; 4]) -> Result<()> { ... }
    fn selectors() -> Selectors<Self>  { ... }
    fn abi_encode(&self) -> Vec<u8>  { ... }
    fn abi_decode(data: &[u8], validate: bool) -> Result<Self> { ... }
}
Expand description

A collection of ABI-encodable call-like types. This currently includes SolCall and SolError.

This trait assumes that the implementing type always has a selector, and thus encoded/decoded data is always at least 4 bytes long.

This trait is implemented for Infallible to represent an empty interface. This is used by GenericContractError.

§Implementer’s Guide

It should not be necessary to implement this trait manually. Instead, use the sol! procedural macro to parse Solidity syntax into types that implement this trait.

Required Associated Constants§

Source

const NAME: &'static str

The name of this type.

Source

const MIN_DATA_LENGTH: usize

The minimum length of the data for this type.

This does not include the selector’s length (4).

Source

const COUNT: usize

The number of variants.

Required Methods§

Source

fn selector(&self) -> [u8; 4]

The selector of this instance.

Source

fn selector_at(i: usize) -> Option<[u8; 4]>

The selector of this type at the given index, used in selectors.

This must return None if i >= Self::COUNT, and Some with a different selector otherwise.

Source

fn valid_selector(selector: [u8; 4]) -> bool

Returns true if the given selector is known to this type.

Source

fn abi_decode_raw( selector: [u8; 4], data: &[u8], validate: bool, ) -> Result<Self>

ABI-decodes the given data into one of the variants of self.

Source

fn abi_encoded_size(&self) -> usize

The size of the encoded data, without any selectors.

Source

fn abi_encode_raw(&self, out: &mut Vec<u8>)

ABI-encodes self into the given buffer, without any selectors.

Provided Methods§

Source

fn type_check(selector: [u8; 4]) -> Result<()>

Returns an error if the given selector is not known to this type.

Source

fn selectors() -> Selectors<Self>

Returns an iterator over the selectors of this type.

Source

fn abi_encode(&self) -> Vec<u8>

ABI-encodes self into the given buffer.

Source

fn abi_decode(data: &[u8], validate: bool) -> Result<Self>

ABI-decodes the given data into one of the variants of self.

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.

Implementations on Foreign Types§

Source§

impl SolInterface for Infallible

An empty SolInterface implementation. Used by GenericContractError.

Source§

const NAME: &'static str = "GenericContractError"

Source§

const MIN_DATA_LENGTH: usize = 4_294_967_295usize

Source§

const COUNT: usize = 0usize

Source§

fn selector(&self) -> [u8; 4]

Source§

fn selector_at(_i: usize) -> Option<[u8; 4]>

Source§

fn valid_selector(_selector: [u8; 4]) -> bool

Source§

fn abi_decode_raw( selector: [u8; 4], _data: &[u8], _validate: bool, ) -> Result<Self>

Source§

fn abi_encoded_size(&self) -> usize

Source§

fn abi_encode_raw(&self, _out: &mut Vec<u8>)

Implementors§

Source§

impl<T: SolInterface> SolInterface for ContractError<T>

Source§

const NAME: &'static str = "ContractError"

Source§

const MIN_DATA_LENGTH: usize = _

Source§

const COUNT: usize = _