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
impl JsonAbi
Sourcepub fn parse<'a, I: IntoIterator<Item = &'a str>>(strings: I) -> Result<Self>
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);
Sourcepub fn into_items(self) -> IntoItems ⓘ
pub fn into_items(self) -> IntoItems ⓘ
Returns an iterator over all of the items in the ABI.
Sourcepub fn to_sol(&self, name: &str, config: Option<ToSolConfig>) -> String
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.
Sourcepub fn to_sol_raw(
&self,
name: &str,
out: &mut String,
config: Option<ToSolConfig>,
)
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.
Sourcepub fn dedup(&mut self)
pub fn dedup(&mut self)
Deduplicates all functions, errors, and events which have the same name and inputs.
Sourcepub const fn constructor(&self) -> Option<&Constructor>
pub const fn constructor(&self) -> Option<&Constructor>
Returns an immutable reference to the constructor.
Sourcepub fn constructor_mut(&mut self) -> Option<&mut Constructor>
pub fn constructor_mut(&mut self) -> Option<&mut Constructor>
Returns a mutable reference to the constructor.
Sourcepub fn function(&self, name: &str) -> Option<&Vec<Function>>
pub fn function(&self, name: &str) -> Option<&Vec<Function>>
Returns an immutable reference to the list of all the functions with the given name.
Sourcepub fn function_mut(&mut self, name: &str) -> Option<&mut Vec<Function>>
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.
Sourcepub fn event(&self, name: &str) -> Option<&Vec<Event>>
pub fn event(&self, name: &str) -> Option<&Vec<Event>>
Returns an immutable reference to the list of all the events with the given name.
Sourcepub fn event_mut(&mut self, name: &str) -> Option<&mut Vec<Event>>
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.
Sourcepub fn error(&self, name: &str) -> Option<&Vec<Error>>
pub fn error(&self, name: &str) -> Option<&Vec<Error>>
Returns an immutable reference to the list of all the errors with the given name.
Sourcepub fn error_mut(&mut self, name: &str) -> Option<&mut Vec<Error>>
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.
Sourcepub fn functions(&self) -> Flatten<Values<'_, String, Vec<Function>>> ⓘ
pub fn functions(&self) -> Flatten<Values<'_, String, Vec<Function>>> ⓘ
Returns an iterator over immutable references to the functions.
Sourcepub fn functions_mut(&mut self) -> Flatten<ValuesMut<'_, String, Vec<Function>>> ⓘ
pub fn functions_mut(&mut self) -> Flatten<ValuesMut<'_, String, Vec<Function>>> ⓘ
Returns an iterator over mutable references to the functions.
Sourcepub fn events(&self) -> Flatten<Values<'_, String, Vec<Event>>> ⓘ
pub fn events(&self) -> Flatten<Values<'_, String, Vec<Event>>> ⓘ
Returns an iterator over immutable references to the events.
Sourcepub fn events_mut(&mut self) -> Flatten<ValuesMut<'_, String, Vec<Event>>> ⓘ
pub fn events_mut(&mut self) -> Flatten<ValuesMut<'_, String, Vec<Event>>> ⓘ
Returns an iterator over mutable references to the events.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for JsonAbi
impl<'de> Deserialize<'de> for JsonAbi
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<'a> FromIterator<AbiItem<'a>> for JsonAbi
impl<'a> FromIterator<AbiItem<'a>> for JsonAbi
impl Eq for JsonAbi
impl StructuralPartialEq for JsonAbi
Auto Trait Implementations§
impl Freeze for JsonAbi
impl RefUnwindSafe for JsonAbi
impl Send for JsonAbi
impl Sync for JsonAbi
impl Unpin for JsonAbi
impl UnwindSafe for JsonAbi
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)