Use `convert_type_for_solidity_signature_to_string`

and include Enums
pull/1730/head
webthethird 2 years ago
parent 4dfe45742a
commit 1d35316d9b
  1. 11
      slither/utils/code_generation.py

@ -3,6 +3,7 @@ from typing import TYPE_CHECKING, Optional
from slither.core.declarations.contract import Contract from slither.core.declarations.contract import Contract
from slither.core.solidity_types.user_defined_type import UserDefinedType from slither.core.solidity_types.user_defined_type import UserDefinedType
from slither.utils.type import convert_type_for_solidity_signature_to_string
if TYPE_CHECKING: if TYPE_CHECKING:
from slither.core.declarations import FunctionContract, Structure from slither.core.declarations import FunctionContract, Structure
@ -23,7 +24,11 @@ def generate_interface(contract: "Contract") -> str:
name, args = event.signature name, args = event.signature
interface += f" event {name}({','.join(args)});\n" interface += f" event {name}({','.join(args)});\n"
for error in contract.custom_errors: for error in contract.custom_errors:
interface += f" error {error.solidity_signature};\n" args = [convert_type_for_solidity_signature_to_string(arg.type).replace("(", "").replace(")", "")
for arg in error.parameters]
interface += f" error {error.name}({', '.join(args)});\n"
for enum in contract.enums:
interface += f" enum {enum.name} {{ {', '.join(enum.values)} }}\n"
for struct in contract.structures: for struct in contract.structures:
interface += generate_struct_interface_str(struct) interface += generate_struct_interface_str(struct)
for var in contract.state_variables_entry_points: for var in contract.state_variables_entry_points:
@ -61,9 +66,7 @@ def generate_interface_function_signature(func: "FunctionContract") -> Optional[
pure = " pure" if func.pure else "" pure = " pure" if func.pure else ""
payable = " payable" if func.payable else "" payable = " payable" if func.payable else ""
returns = [ returns = [
"address" convert_type_for_solidity_signature_to_string(ret.type)
if isinstance(ret.type, UserDefinedType) and isinstance(ret.type.type, Contract)
else str(ret.type)
for ret in func.returns for ret in func.returns
] ]
_interface_signature_str = ( _interface_signature_str = (

Loading…
Cancel
Save