def _export_all(self) -> List[Export]: path = Path(self._export_path, "export.sol") content = "" content += self._pragmas() contract_seen = set() contract_to_explore = list(self._slither.contracts) # We only need the inheritance order here, as solc can compile # a contract that use another contract type (ex: state variable) that he has not seen yet while contract_to_explore: next_to_explore = contract_to_explore.pop(0) if not next_to_explore.inheritance or all( (father in contract_seen for father in next_to_explore.inheritance)): content += "\n" content += self._source_codes[next_to_explore] content += "\n" contract_seen.add(next_to_explore) else: contract_to_explore.append(next_to_explore) return [Export(filename=path, content=content)]
def _export_with_import(self) -> List[Export]: exports: List[Export] = [] for contract in self._compilation_unit.contracts: list_contracts: List[Contract] = [] # will contain contract itself list_top_level: List[TopLevel] = [] self._export_list_used_contracts(contract, set(), list_contracts, list_top_level) if list_top_level: logger.info( "Top level objects are not yet supported with the local import flattening" ) for elem in list_top_level: logger.info(f"Missing {elem} for {contract.name}") path = Path(self._export_path, f"{contract.name}.sol") content = "" content += self._pragmas() for used_contract in list_contracts: if used_contract != contract: content += f"import './{used_contract.name}.sol';\n" content += "\n" content += self._source_codes[contract] content += "\n" exports.append(Export(filename=path, content=content)) return exports
def _export_contract_with_inheritance(self, contract) -> Export: list_contracts: List[Contract] = [] # will contain contract itself self._export_list_used_contracts(contract, set(), list_contracts) path = Path(self._export_path, f"{contract.name}.sol") content = "" content += self._pragmas() for listed_contract in list_contracts: content += self._source_codes[listed_contract] content += "\n" return Export(filename=path, content=content)
def _export_with_import(self) -> List[Export]: exports: List[Export] = [] for contract in self._slither.contracts: list_contracts: List[Contract] = [] # will contain contract itself self._export_list_used_contracts(contract, set(), list_contracts) path = Path(self._export_path, f"{contract.name}.sol") content = "" content += self._pragmas() for used_contract in list_contracts: if used_contract != contract: content += f"import './{used_contract.name}.sol';\n" content += "\n" content += self._source_codes[contract] content += "\n" exports.append(Export(filename=path, content=content)) return exports
def _export_contract_with_inheritance(self, contract) -> Export: list_contracts: List[Contract] = [] # will contain contract itself list_top_level: List[TopLevel] = [] self._export_list_used_contracts(contract, set(), list_contracts, list_top_level) path = Path(self._export_path, f"{contract.name}_{uuid.uuid4()}.sol") content = "" content += self._pragmas() for listed_top_level in list_top_level: content += self._source_codes_top_level[listed_top_level] content += "\n" for listed_contract in list_contracts: content += self._source_codes[listed_contract] content += "\n" return Export(filename=path, content=content)