def main(): args = docopt(__doc__, more_magic=True) _update_argv_from_docopt(args) active_project = None if project.check_for_project(): active_project = project.load() active_project.load_config() print(f"{active_project._name} is the active project.") network.connect(CONFIG.argv["network"]) path, _ = _get_path(args["<filename>"]) path_str = path.absolute().as_posix() try: return_value, frame = run( args["<filename>"], method_name=args["<function>"] or "main", args=args["<arg>"], _include_frame=True, ) exit_code = 0 except Exception as e: print(color.format_tb(e)) frame = next( (i.frame for i in inspect.trace()[::-1] if Path(i.filename).as_posix() == path_str), None, ) if frame is None: # exception was an internal brownie issue - do not open the console sys.exit(1) exit_code = 1 return_value = None try: if args["--interactive"]: # filter internal objects from the namespace prior to opening the console globals_dict = { k: v for k, v in frame.f_globals.items() if not k.startswith("__") } extra_locals = { "_": return_value, **globals_dict, **frame.f_locals } shell = Console(active_project, extra_locals) shell.interact( banner="\nInteractive mode enabled. Use quit() to close.", exitmsg="") finally: # the console terminates from a SystemExit - make sure we still deliver the final gas report if CONFIG.argv["gas"]: print("\n======= Gas profile =======") for line in _build_gas_profile_output(): print(line) sys.exit(exit_code)
def main(): """The main entry point of the MythX plugin for Brownie.""" args = docopt(__doc__) _update_argv_from_docopt(args) if CONFIG.argv["mode"] not in ANALYSIS_MODES: raise ValidationError( "Invalid analysis mode: Must be one of [{}]".format( ", ".join(ANALYSIS_MODES))) project_path = project.check_for_project(".") if project_path is None: raise ProjectNotFound build = project.load()._build submission = SubmissionPipeline(build) print("Preparing project data for submission to MythX...") submission.prepare_requests() print("Sending analysis requests to MythX...") submission.send_requests() # exit if user wants an async analysis run if CONFIG.argv["async"]: print( "\nAll contracts were submitted successfully. Check the dashboard at " "https://dashboard.mythx.io/ for the progress and results of your analyses" ) return print("\nWaiting for results...") submission.wait_for_jobs() submission.generate_stdout_report() submission.generate_highlighting_report() # erase previous report report_path = project_path.joinpath( _load_project_structure_config(project_path)["reports"]) report_path = report_path.joinpath("security.json") if report_path.exists(): report_path.unlink() print_console_report(submission.stdout_report) # Write report to Brownie directory with report_path.open("w+") as fp: json.dump(submission.highlight_report, fp, indent=2, sort_keys=True) # Launch GUI if user requested it if CONFIG.argv["gui"]: print("Launching the Brownie GUI") gui = importlib.import_module("brownie._gui").Gui gui().mainloop()
def main(): args = docopt(__doc__) _update_argv_from_docopt(args) if project.check_for_project(): active_project = project.load() active_project.load_config() print(f"{active_project._name} is the active project.") else: active_project = None print("No project was loaded.") network.connect(CONFIG.argv["network"]) shell = Console(active_project) shell.interact(banner="Brownie environment is ready.", exitmsg="")
def main(): args = docopt(__doc__) _update_argv_from_docopt(args) if project.check_for_project(): active_project = project.load() active_project.load_config() print(f"{active_project._name} is the active project.") else: raise ProjectNotFound network.connect(ARGV["network"]) run(args["<filename>"], method_name=args["<function>"] or "main") if ARGV["gas"]: _print_gas_profile()
def main(): args = docopt(__doc__) _update_argv_from_docopt(args) if project.check_for_project(): active_project = project.load() active_project.load_config() print(f"{active_project._name} is the active project.") else: raise ProjectNotFound network.connect(CONFIG.argv["network"]) path, _ = _get_path(args["<filename>"]) path_str = path.absolute().as_posix() try: run(args["<filename>"], method_name=args["<function>"] or "main") except Exception as e: print(color.format_tb(e)) if args["--interactive"]: frame = next( (i.frame for i in inspect.trace()[::-1] if Path(i.filename).as_posix() == path_str), None, ) if frame is not None: globals_dict = { k: v for k, v in frame.f_globals.items() if not k.startswith("__") } shell = Console(active_project, { **globals_dict, **frame.f_locals }) shell.interact( banner="\nInteractive mode enabled. Use quit() to close.", exitmsg="") sys.exit(1) if CONFIG.argv["gas"]: print("\n======= Gas profile =======") for line in _build_gas_profile_output(): print(line)
def main(): args = docopt(__doc__) _update_argv_from_docopt(args) project_path = project.check_for_project(".") if project_path is None: raise ProjectNotFound build = project.load()._build print("Preparing project data for submission to MythX...") contracts, libraries = get_contract_types(build) job_data = assemble_contract_jobs(build, contracts) job_data = update_contract_jobs_with_dependencies(build, contracts, libraries, job_data) client, authenticated = get_mythx_client() job_uuids = send_to_mythx(job_data, client, authenticated) # exit if user wants an async analysis run if ARGV["async"] and authenticated: print( "\nAll contracts were submitted successfully. Check the dashboard at " "https://dashboard.mythx.io/ for the progress and results of your analyses" ) return print("\nWaiting for results...") wait_for_jobs(job_uuids, client) # assemble report json source_to_name = get_contract_locations(build) highlight_report = {"highlights": {"MythX": {}}} stdout_report = {} for c, uuid in enumerate(job_uuids, start=1): print( f"Generating report for job {color['value']}{uuid}{color} ({c}/{len(job_uuids)})" ) if authenticated: print("You can also check the results at {}{}\n".format( DASHBOARD_BASE_URL, uuid)) update_report(client, uuid, highlight_report, stdout_report, source_to_name) # erase previous report report_path = Path("reports/security.json") if report_path.exists(): report_path.unlink() total_issues = sum(x for i in stdout_report.values() for x in i.values()) if not total_issues: notify("SUCCESS", "No issues found!") return # display console report total_high_severity = sum(i.get("HIGH", 0) for i in stdout_report.values()) if total_high_severity: notify( "WARNING", f"Found {total_issues} issues including {total_high_severity} high severity!" ) else: print(f"Found {total_issues} issues:") for name in sorted(stdout_report): print(f"\n contract: {color['contract']}{name}{color}") for key in [ i for i in ("HIGH", "MEDIUM", "LOW") if i in stdout_report[name] ]: c = color("bright " + SEVERITY_COLOURS[key]) print(f" {key.title()}: {c}{stdout_report[name][key]}{color}") # Write report to Brownie directory with report_path.open("w+") as fp: json.dump(highlight_report, fp, indent=2, sort_keys=True) # Launch GUI if user requested it if ARGV["gui"]: print("Launching the Brownie GUI") Gui = importlib.import_module("brownie._gui").Gui Gui().mainloop()