#[solidity_interface]
Expand description
Derives call enum implementing crate::Callable
and crate::Call
from impl block.
§Macro syntax
#[solidity_interface(name, is, inline_is, events)]
name
- used in generated code, and for Call enum nameis
- used to provide inheritance in Solidityinline_is
- same asis
, butERC165::SupportsInterface
will work differently: Foris
SupportsInterface(A) will return true if A is one of the interfaces the contract is inherited from (e.g. B is created asis(A)
). If B is created asinline_is(A)
SupportsInterface(A) will internally create a new interface that combines all methods of A and B, so SupportsInterface(A) will return false.
#[solidity_interface(rename_selector)]
rename_selector
- by default, selector name will be generated by transforming method name fromsnake_case
tocamelCase
. Use this option, if other naming convention is required. I.e: methodtoken_uri
will be automatically renamed totokenUri
in selector, but name required by ERC721 standard istokenURI
, thus we need to specifyrename_selector = "tokenURI"
explicitly.
Both contract and contract methods may have doccomments, which will end up in a generated solidity interface file, thus you should use solidity syntax for writing documentation in this macro
§Example
ⓘ
struct SuperContract;
struct InlineContract;
struct Contract;
#[derive(ToLog)]
enum ContractEvents {
Event(#[indexed] uint32),
}
/// @dev This contract provides function to multiply two numbers
#[solidity_interface(name = MyContract, is(SuperContract), inline_is(InlineContract))]
impl Contract {
/// Multiply two numbers
/// @param a First number
/// @param b Second number
/// @return uint32 Product of two passed numbers
/// @dev This function returns error in case of overflow
#[weight(200 + a + b)]
#[solidity_interface(rename_selector = "mul")]
fn mul(&mut self, a: uint32, b: uint32) -> Result<uint32> {
Ok(a.checked_mul(b).ok_or("overflow")?)
}
}
See documentation for this proc-macro reexported in evm-coder
crate