pub struct Function {
pub name: String,
pub inputs: Vec<Param>,
pub outputs: Vec<Param>,
pub state_mutability: StateMutability,
}Expand description
A JSON ABI function.
Fields§
§name: StringThe name of the function.
inputs: Vec<Param>The input types of the function. May be empty.
outputs: Vec<Param>The output types of the function. May be empty.
state_mutability: StateMutabilityThe state mutability of the function.
Implementations§
Source§impl Function
impl Function
Sourcepub fn parse(s: &str) -> Result<Self>
pub fn parse(s: &str) -> Result<Self>
Parses a Solidity function signature string:
$(function)? $name($($inputs),*) [visibility] [s_mutability] $(returns ($($outputs),+))?
Note:
- visibility is ignored
If you want to parse a generic Human-Readable ABI string, use AbiItem::parse.
§Examples
Basic usage:
assert_eq!(
Function::parse("foo(bool bar)"),
Ok(Function {
name: "foo".to_string(),
inputs: vec![Param::parse("bool bar").unwrap()],
outputs: vec![],
state_mutability: StateMutability::NonPayable,
}),
);Functions also support parsing output parameters:
assert_eq!(
Function::parse("function toString(uint number) external view returns (string s)"),
Ok(Function {
name: "toString".to_string(),
inputs: vec![Param::parse("uint number").unwrap()],
outputs: vec![Param::parse("string s").unwrap()],
state_mutability: StateMutability::View,
}),
);Sourcepub fn signature(&self) -> String
pub fn signature(&self) -> String
Returns this function’s signature: $name($($inputs),*).
This is the preimage input used to compute the selector.
Sourcepub fn signature_with_outputs(&self) -> String
pub fn signature_with_outputs(&self) -> String
Returns this function’s full signature:
$name($($inputs),*)($(outputs),*).
This is the same as signature, but also includes
the output types.
Sourcepub fn full_signature(&self) -> String
pub fn full_signature(&self) -> String
Returns this function’s full signature including names of params:
function $name($($inputs $names),*) state_mutability returns ($($outputs $names),*).
This is a full human-readable string, including all parameter names, any optional modifiers (e.g. view, payable, pure) and white-space to aid in human readability. This is useful for storing a string which can still fully reconstruct the original Fragment