def main(args): vm = None fname = args.file api = utils.getApi(args.web3) if not fname: if not args.hash: parser.error('hash is required to reproduce the tx if a trace file is not provided') #reproduce the tx if args.parity_evm: vm = VMUtils.ParityVM(args.parity_evm, not args.no_docker) else: vm = VMUtils.GethVM(args.geth_evm, not args.no_docker) artefacts, vm_args = reproduce.reproduceTx(args.hash, vm, api) saved_files = utils.saveFiles(OUTPUT_DIR, artefacts) fname = os.path.join(saved_files['json-trace']['path'], saved_files['json-trace']['name']) ops = loadJsonDebugStackTrace(fname) if ops == None: # Usually, each line is a json-object try: ops = loadJsonObjects(fname) except Exception as e: print("Error loading json:") traceback.print_exc() print("Trying alternate loader") ops = loadWeirdJson(fname) contexts = None if args.json: if not args.hash: parser.error('hash is required if contract json is provided') contracts = [] with open(args.json) as f: combined = json.load(f) sourceList = [os.path.join(args.source, s) for s in combined['sourceList']] for contract in combined['contracts'].keys(): val = combined['contracts'][contract] c = Contract(sourceList, val) contracts.append(c) contexts = buildContexts(ops, api, contracts, args.hash) if vm: print("\nTo view the generated trace:\n") cmd = "python3 opviewer.py -f %s" % fname if args.json: cmd += " --web3 %s -s %s -j %s --hash %s" % (args.web3, args.source, args.json, args.hash) print(cmd) DebugViewer().setTrace(ops, contexts)
def load_contract_sources_from_combined_json(self, tx, combined_json, source_prefix=''): # TODO: untested, need reference file contracts = [] sources = [] # get sources (text) for all contracts for s in combined_json['sourceList']: if s.count('/') == 0: s = source_prefix + '/' + s with open(s) as f: logger.debug(f.name) sources.append(f.read()) # get contract for contract, val in combined_json['contracts'].items(): contracts.append(Contract(sources, val, contract)) self.contracts = contracts self.op_contracts = buildContexts(self.ops, self.api, contracts, tx) return self
def load_contract_sources_from_combined_json(self, tx, combined_json, source_prefix=''): # TODO: untested, need reference file contracts = [] sources = [] # get sources (text) for all contracts for file in [ os.path.join(source_prefix, s) for s in combined_json['sourceList'] ]: with open(file) as s: logger.debug(s.name) sources.append(s.read()) # get contract for contract, val in combined_json['contracts'].items(): contracts.append(Contract(sources, val, contract)) self.contracts = contracts self.op_contracts = buildContexts(self.ops, self.api, contracts, tx) return self