def load_stdin(self, hash_id): assure_dir_exists("cache_stdin") fname = f"cache_stdin/{hash_id}.bin" address = hash_id self.addr = hash_id with open(fname) as f: code = f.read() self.network = "stdin" self.load_binary(code)
def load_addr(self, address): if address == address.lower(): logger.warning( "Address not checksummed. Fixed, but needed to import web3 (+0.6s exec time). Avoid using the all-lowercase version of the contract address." ) from web3 import Web3 # only here, because Web3 address = Web3.toChecksumAddress(address) self.addr = address fname = None code = None dir_name = "cache_code/" + address[:5] + "/" assure_dir_exists(dir_name) cache_fname = f"{dir_name}{address}.bin" if address == address.lower() and os.path.isfile(cache_fname.lower()): print( "addr not checksummed, but found a checksummed one in cache, using that one" ) cache_fname = cache_fname.lower() if os.path.isfile(cache_fname): logger.info("Code for %s found in cache...", address) with open(cache_fname) as source_file: code = source_file.read() self.network = "mainnet" else: if '--silent' not in sys.argv: logger.info("Fetching code for %s...", address) code = "" for network in "mainnet", "goerli", "ropsten", "kovan", "rinkeby": code = code_fetch(address, network) if len(code) > 0: self.network = network break else: self.network = "none" with open(cache_fname, "w+") as f: f.write(code) fname = cache_fname self.load_binary(code)
def load_addr(self, address): if address == address.lower(): logger.warning('Address not checksummed. Fixed, but needed to import web3 (+0.6s exec time)') from web3 import Web3 # only here, because Web3 address = Web3.toChecksumAddress(address) self.addr = address fname = None code = None dir_name = 'cache_code/'+address[:5]+'/' assure_dir_exists(dir_name) cache_fname = f'{dir_name}{address}.bin' if address == address.lower() and os.path.isfile(cache_fname.lower()): print('addr not checksummed, but found a checksummed one in cache, using that one') cache_fname = cache_fname.lower() if os.path.isfile(cache_fname): logger.info('Code for %s found in cache...', address) with open(cache_fname) as source_file: code = source_file.read() self.network = 'mainnet' else: logger.info('Fetching code for %s...', address) code = '' for network in 'mainnet', 'goerli', 'ropsten', 'kovan', 'rinkeby': code = code_fetch(address, network) if len(code)>0: self.network = network break else: self.network = 'none' with open(cache_fname, "w+") as f: f.write(code) fname = cache_fname self.load_binary(code)