Merge pull request #537 from crytic/dev-flat-pragma

slither-flat: Add --pragma-solidity flag
pull/539/head
Feist Josselin 4 years ago committed by GitHub
commit af3d1b0c75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      slither/tools/flattening/__main__.py
  2. 7
      slither/tools/flattening/flattening.py

@ -76,6 +76,10 @@ def parse_args():
"--remove-assert", help="Remove call to assert().", action="store_true" "--remove-assert", help="Remove call to assert().", action="store_true"
) )
group_patching.add_argument(
"--pragma-solidity", help="Set the solidity pragma with a given version.", action="store", default=None
)
# Add default arguments from crytic-compile # Add default arguments from crytic-compile
cryticparser.init(parser) cryticparser.init(parser)
@ -96,6 +100,7 @@ def main():
remove_assert=args.remove_assert, remove_assert=args.remove_assert,
private_to_internal=args.convert_private, private_to_internal=args.convert_private,
export_path=args.dir, export_path=args.dir,
pragma_solidity=args.pragma_solidity
) )
try: try:

@ -43,6 +43,7 @@ class Flattening:
remove_assert=False, remove_assert=False,
private_to_internal=False, private_to_internal=False,
export_path: Optional[str] = None, export_path: Optional[str] = None,
pragma_solidity: Optional[str] = None
): ):
self._source_codes: Dict[Contract, str] = {} self._source_codes: Dict[Contract, str] = {}
self._slither = slither self._slither = slither
@ -50,6 +51,7 @@ class Flattening:
self._remove_assert = remove_assert self._remove_assert = remove_assert
self._use_abi_encoder_v2 = False self._use_abi_encoder_v2 = False
self._private_to_internal = private_to_internal self._private_to_internal = private_to_internal
self._pragma_solidity = pragma_solidity
self._export_path: Path = DEFAULT_EXPORT_PATH if export_path is None else Path(export_path) self._export_path: Path = DEFAULT_EXPORT_PATH if export_path is None else Path(export_path)
@ -165,8 +167,11 @@ class Flattening:
:return: :return:
""" """
ret = "" ret = ""
if self._slither.solc_version: if self._pragma_solidity:
ret += f"pragma solidity {self._pragma_solidity};\n"
elif self._slither.solc_version:
ret += f"pragma solidity {self._slither.solc_version};\n" ret += f"pragma solidity {self._slither.solc_version};\n"
if self._use_abi_encoder_v2: if self._use_abi_encoder_v2:
ret += "pragma experimental ABIEncoderV2;\n" ret += "pragma experimental ABIEncoderV2;\n"
return ret return ret

Loading…
Cancel
Save