difftreelog
doc: document #[solidity_interface] macro
in: master
1 file changed
crates/evm-coder-macros/src/lib.rsdiffbeforeafterboth27/// Returns solidity function selector (first 4 bytes of hash) by its27/// Returns solidity function selector (first 4 bytes of hash) by its28/// textual representation28/// textual representation29///29///30/// ```rs30/// ```ignore31/// use evm_coder_macros::fn_selector;31/// use evm_coder_macros::fn_selector;32///32///33/// assert_eq!(fn_selector!(transfer(address, uint256)), 0xa9059cbb);33/// assert_eq!(fn_selector!(transfer(address, uint256)), 0xa9059cbb);555556/// Returns solidity topic (hash) by its textual representation56/// Returns solidity topic (hash) by its textual representation57///57///58/// ```rs58/// ```ignore59/// use evm_coder_macros::event_topic;59/// use evm_coder_macros::event_topic;60///60///61/// assert_eq!(61/// assert_eq!(184 Ident::new(&name, ident.span())184 Ident::new(&name, ident.span())185}185}186186187/// Derives call enum implementing [`evm_coder::Callable`], [`evm_coder::Weighted`]188/// and [`evm_coder::Call`] from impl block189/// 190/// ## Macro syntax191/// 192/// `#[solidity_interface(name, is, inline_is, events)]`193/// - *name*: used in generated code, and for Call enum name194/// - *is*: used to provide call inheritance, not found methods will be delegated to all contracts195/// specified in is/inline_is 196/// - *inline_is*: same as is, but selectors for passed contracts will be used by derived ERC165197/// implementation198/// 199/// `#[weight(value)]`200/// Can be added to every method of impl block, used for deriving [`evm_coder::Weighted`], which201/// is used by substrate bridge202/// - *value*: expression, which evaluates to weight required to call this method.203/// This expression can use call arguments to calculate non-constant execution time.204/// This expression should evaluate faster than actual execution does, and may provide worser case205/// than one is called206/// 207/// `#[solidity_interface(rename_selector)]`208/// - *rename_selector*: by default, selector name will be generated by transforming method name209/// from snake_case to camelCase. Use this option, if other naming convention is required.210/// I.e: method `token_uri` will be automatically renamed to `tokenUri` in selector, but name211/// required by ERC721 standard is `tokenURI`, thus we need to specify `rename_selector = "tokenURI"`212/// explicitly213/// 214/// Also, any contract method may have doc comments, which will be automatically added to generated215/// solidity interface definitions216/// 217/// ## Example218/// 219/// ```ignore220/// struct SuperContract;221/// struct InlineContract;222/// struct Contract;223/// 224/// #[derive(ToLog)]225/// enum ContractEvents {226/// Event(#[indexed] uint32), 227/// }228/// 229/// #[solidity_interface(name = "MyContract", is(SuperContract), inline_is(InlineContract))]230/// impl Contract {231/// /// Multiply two numbers232/// #[weight(200 + a + b)]233/// #[solidity_interface(rename_selector = "mul")]234/// fn mul(&mut self, a: uint32, b: uint32) -> Result<uint32> {235/// Ok(a.checked_mul(b).ok_or("overflow")?) 236/// }237/// }238/// ```187#[proc_macro_attribute]239#[proc_macro_attribute]188pub fn solidity_interface(args: TokenStream, stream: TokenStream) -> TokenStream {240pub fn solidity_interface(args: TokenStream, stream: TokenStream) -> TokenStream {189 let args = parse_macro_input!(args as AttributeArgs);241 let args = parse_macro_input!(args as AttributeArgs);216 stream268 stream217}269}218270271/// ## Syntax272/// 273/// `#[indexed]`274/// Marks this field as indexed, so it will appear in [`ethereum::Log`] topics instead of data219#[proc_macro_derive(ToLog, attributes(indexed))]275#[proc_macro_derive(ToLog, attributes(indexed))]220pub fn to_log(value: TokenStream) -> TokenStream {276pub fn to_log(value: TokenStream) -> TokenStream {221 let input = parse_macro_input!(value as DeriveInput);277 let input = parse_macro_input!(value as DeriveInput);