alloy_json_abi

Struct JsonAbi

Source
pub struct JsonAbi {
    pub constructor: Option<Constructor>,
    pub fallback: Option<Fallback>,
    pub receive: Option<Receive>,
    pub functions: BTreeMap<String, Vec<Function>>,
    pub events: BTreeMap<String, Vec<Event>>,
    pub errors: BTreeMap<String, Vec<Error>>,
}
Expand description

The JSON contract ABI, as specified in the Solidity ABI spec.

Fields§

§constructor: Option<Constructor>

The constructor function.

§fallback: Option<Fallback>

The fallback function.

§receive: Option<Receive>

The receive function.

§functions: BTreeMap<String, Vec<Function>>

The functions, indexed by the function name.

§events: BTreeMap<String, Vec<Event>>

The events, indexed by the event name.

§errors: BTreeMap<String, Vec<Error>>

The errors, indexed by the error name.

Implementations§

Source§

impl JsonAbi

Source

pub fn new() -> Self

Creates an empty ABI object.

Source

pub fn parse<'a, I: IntoIterator<Item = &'a str>>(strings: I) -> Result<Self>

Parse a Human-Readable ABI string into a JSON object.

§Examples
assert_eq!(JsonAbi::parse([])?, JsonAbi::new());

let abi = JsonAbi::parse([
    "constructor(string symbol, string name)",
    "function transferFrom(address from, address to, uint value)",
    "function balanceOf(address owner)(uint balance)",
    "event Transfer(address indexed from, address indexed to, address value)",
    "error InsufficientBalance(address owner, uint balance)",
    "function addPerson(tuple(string, uint16) person)",
    "function addPeople(tuple(string, uint16)[] person)",
    "function getPerson(uint id)(tuple(string, uint16))",
    "event PersonAdded(uint indexed id, tuple(string, uint16) person)",
])?;
assert_eq!(abi.len(), 9);
Source

pub fn len(&self) -> usize

Returns the total number of items (of any type).

Source

pub fn is_empty(&self) -> bool

Returns true if the ABI contains no items.

Source

pub fn items(&self) -> Items<'_>

Returns an iterator over all of the items in the ABI.

Source

pub fn into_items(self) -> IntoItems

Returns an iterator over all of the items in the ABI.

Source

pub fn to_sol(&self, name: &str, config: Option<ToSolConfig>) -> String

Formats this JSON ABI as a Solidity interface.

The order of the definitions is not guaranteed.

Generates:

interface <name> {
    <enums>...
    <UDVTs>...
    <structs>...
    <errors>...
    <events>...
    <fallback>
    <receive>
    <functions>...
}

Note that enums are going to be identical to uint8 UDVTs, since no other information about enums is present in the ABI.

Source

pub fn to_sol_raw( &self, name: &str, out: &mut String, config: Option<ToSolConfig>, )

Formats this JSON ABI as a Solidity interface into the given string.

See to_sol for more information.

Source

pub fn dedup(&mut self)

Deduplicates all functions, errors, and events which have the same name and inputs.

Source

pub const fn constructor(&self) -> Option<&Constructor>

Returns an immutable reference to the constructor.

Source

pub fn constructor_mut(&mut self) -> Option<&mut Constructor>

Returns a mutable reference to the constructor.

Source

pub fn function(&self, name: &str) -> Option<&Vec<Function>>

Returns an immutable reference to the list of all the functions with the given name.

Source

pub fn function_mut(&mut self, name: &str) -> Option<&mut Vec<Function>>

Returns a mutable reference to the list of all the functions with the given name.

Source

pub fn event(&self, name: &str) -> Option<&Vec<Event>>

Returns an immutable reference to the list of all the events with the given name.

Source

pub fn event_mut(&mut self, name: &str) -> Option<&mut Vec<Event>>

Returns a mutable reference to the list of all the events with the given name.

Source

pub fn error(&self, name: &str) -> Option<&Vec<Error>>

Returns an immutable reference to the list of all the errors with the given name.

Source

pub fn error_mut(&mut self, name: &str) -> Option<&mut Vec<Error>>

Returns a mutable reference to the list of all the errors with the given name.

Source

pub fn functions(&self) -> Flatten<Values<'_, String, Vec<Function>>>

Returns an iterator over immutable references to the functions.

Source

pub fn functions_mut(&mut self) -> Flatten<ValuesMut<'_, String, Vec<Function>>>

Returns an iterator over mutable references to the functions.

Source

pub fn events(&self) -> Flatten<Values<'_, String, Vec<Event>>>

Returns an iterator over immutable references to the events.

Source

pub fn events_mut(&mut self) -> Flatten<ValuesMut<'_, String, Vec<Event>>>

Returns an iterator over mutable references to the events.

Source

pub fn errors(&self) -> Flatten<Values<'_, String, Vec<Error>>>

Returns an iterator over immutable references to the errors.

Source

pub fn errors_mut(&mut self) -> Flatten<ValuesMut<'_, String, Vec<Error>>>

Returns an iterator over mutable references to the errors.

Trait Implementations§

Source§

impl Clone for JsonAbi

Source§

fn clone(&self) -> JsonAbi

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JsonAbi

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for JsonAbi

Source§

fn default() -> JsonAbi

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for JsonAbi

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> FromIterator<AbiItem<'a>> for JsonAbi

Source§

fn from_iter<T: IntoIterator<Item = AbiItem<'a>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for JsonAbi

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for JsonAbi

Source§

fn eq(&self, other: &JsonAbi) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for JsonAbi

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for JsonAbi

Source§

impl StructuralPartialEq for JsonAbi

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,