pub struct Function {
pub name: String,
pub inputs: Vec<Param>,
pub outputs: Vec<Param>,
pub state_mutability: StateMutability,
}json-abi only.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<Function, Error>
pub fn parse(s: &str) -> Result<Function, Error>
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
Sourcepub fn selector(&self) -> FixedBytes<4>
pub fn selector(&self) -> FixedBytes<4>
Computes this error’s selector: keccak256(self.signature())[..4]
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Function
impl<'de> Deserialize<'de> for Function
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Function, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Function, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl FunctionExt for Function
impl FunctionExt for Function
Source§fn abi_encode_output(&self, values: &[DynSolValue]) -> Result<Vec<u8>, Error>
fn abi_encode_output(&self, values: &[DynSolValue]) -> Result<Vec<u8>, Error>
Source§fn abi_decode_output(
&self,
data: &[u8],
validate: bool,
) -> Result<Vec<DynSolValue>, Error>
fn abi_decode_output( &self, data: &[u8], validate: bool, ) -> Result<Vec<DynSolValue>, Error>
Source§impl JsonAbiExt for Function
impl JsonAbiExt for Function
Source§fn abi_encode_input(&self, values: &[DynSolValue]) -> Result<Vec<u8>, Error>
fn abi_encode_input(&self, values: &[DynSolValue]) -> Result<Vec<u8>, Error>
Source§fn abi_encode_input_raw(&self, values: &[DynSolValue]) -> Result<Vec<u8>, Error>
fn abi_encode_input_raw(&self, values: &[DynSolValue]) -> Result<Vec<u8>, Error>
Source§fn abi_decode_input(
&self,
data: &[u8],
validate: bool,
) -> Result<Vec<DynSolValue>, Error>
fn abi_decode_input( &self, data: &[u8], validate: bool, ) -> Result<Vec<DynSolValue>, Error>
Source§impl Serialize for Function
impl Serialize for Function
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl Specifier<DynSolCall> for Function
impl Specifier<DynSolCall> for Function
impl Eq for Function
impl StructuralPartialEq for Function
Auto Trait Implementations§
impl Freeze for Function
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 80 bytes