pub struct Param {
pub components: Vec<Param>,
pub internal_type: Option<InternalType>,
/* private fields */
}
Expand description
Fields§
§components: Vec<Param>
If the paramaeter is a compound type (a struct or tuple), a list of the parameter’s components, in order. Empty otherwise
internal_type: Option<InternalType>
The internal type of the parameter. This type represents the type that
the author of the Solidity contract specified. E.g. for a contract, this
will be contract MyContract
while the type
field will be address
.
Implementations§
Source§impl Param
impl Param
Sourcepub fn parse(input: &str) -> Result<Self>
pub fn parse(input: &str) -> Result<Self>
Parse a parameter from a Solidity parameter string.
§Examples
assert_eq!(
Param::parse("uint256[] foo"),
Ok(Param {
name: "foo".into(),
ty: "uint256[]".into(),
components: vec![],
internal_type: None,
})
);
Sourcepub fn new(
name: &str,
ty: &str,
components: Vec<Self>,
internal_type: Option<InternalType>,
) -> Result<Self>
pub fn new( name: &str, ty: &str, components: Vec<Self>, internal_type: Option<InternalType>, ) -> Result<Self>
Validate and create new instance of Param.
Sourcepub const fn internal_type(&self) -> Option<&InternalType>
pub const fn internal_type(&self) -> Option<&InternalType>
The internal type of the parameter.
Sourcepub fn is_udt(&self) -> bool
pub fn is_udt(&self) -> bool
True if the parameter is a UDT (user-defined type).
A UDT will have
- an internal type that does not match its canonical type
- no space in its internal type (as it does not have a keyword body)
Any Other
specifier will definitely be a UDT if it contains a
contract.
Sourcepub const fn is_contract(&self) -> bool
pub const fn is_contract(&self) -> bool
True if the parameter is a contract.
Sourcepub fn udt_specifier(&self) -> Option<TypeSpecifier<'_>>
pub fn udt_specifier(&self) -> Option<TypeSpecifier<'_>>
The UDT specifier is a TypeSpecifier
containing the UDT name and any
array sizes. It is computed from the internal_type
. If this param is
not a UDT, this function will return None
.
Sourcepub fn struct_specifier(&self) -> Option<TypeSpecifier<'_>>
pub fn struct_specifier(&self) -> Option<TypeSpecifier<'_>>
The struct specifier is a TypeSpecifier
containing the struct name
and any array sizes. It is computed from the internal_type
If this
param is not a struct, this function will return None
.
Sourcepub fn enum_specifier(&self) -> Option<TypeSpecifier<'_>>
pub fn enum_specifier(&self) -> Option<TypeSpecifier<'_>>
The enum specifier is a TypeSpecifier
containing the enum name and
any array sizes. It is computed from the internal_type
. If this param
is not a enum, this function will return None
.
Sourcepub fn contract_specifier(&self) -> Option<TypeSpecifier<'_>>
pub fn contract_specifier(&self) -> Option<TypeSpecifier<'_>>
The struct specifier is a TypeSpecifier
containing the contract name
and any array sizes. It is computed from the internal_type
If this
param is not a struct, this function will return None
.
Sourcepub fn is_simple_type(&self) -> bool
pub fn is_simple_type(&self) -> bool
True if the type is simple
Sourcepub fn is_complex_type(&self) -> bool
pub fn is_complex_type(&self) -> bool
True if the type is complex (tuple or struct)
Sourcepub fn selector_type_raw(&self, s: &mut String)
pub fn selector_type_raw(&self, s: &mut String)
Formats the canonical type of this parameter into the given string.
This is used to encode the preimage of a function or error selector.
Sourcepub fn full_selector_type_raw(&self, s: &mut String)
pub fn full_selector_type_raw(&self, s: &mut String)
Formats the canonical type of this parameter into the given string including then names of the params.
Sourcepub fn selector_type(&self) -> Cow<'_, str>
pub fn selector_type(&self) -> Cow<'_, str>
Returns the canonical type of this parameter.
This is used to encode the preimage of a function or error selector.