Last active
January 8, 2022 17:35
-
-
Save raddy/a3b96eaac96d74d095dde1069d00b7a4 to your computer and use it in GitHub Desktop.
Fetch addresses out of opcodes dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import json | |
| def etherscan_link(addy : str): | |
| return f"https://etherscan.io/address/{addy}" | |
| def formatted_addy(addy : str): | |
| l = etherscan_link(addy) | |
| return f"[{addy}]({l})" | |
| def load_json(path : str): | |
| with open(path) as f: | |
| return json.load(f) | |
| def main(): | |
| def addy(line : str): | |
| for tok in line.split(): | |
| if not tok.startswith('0x'): | |
| continue | |
| if len(tok) == 42 and tok[-8:] not in ['00000000', 'ffffffff']: | |
| return tok | |
| if len(tok) == 66 and tok[-8:] not in ['00000000', 'ffffffff']: | |
| return '0x' + tok[-40:] | |
| name = sys.argv[1] | |
| addies = set() | |
| with open(name) as file: | |
| while (line := file.readline().rstrip()): | |
| a = addy(line) | |
| if a: | |
| addies.add(a) # or don't use walrus in py < 3.8 | |
| resp_json = load_json(sys.argv[2]) if len(sys.argv) == 3 else {} | |
| addy_dict = {} | |
| for entry in resp_json: | |
| addy_dict[entry['TX_TO_ADDRESS']] = entry['TX_TO_ADDRESS_NAME'] | |
| for addy in addies: | |
| print(formatted_addy(addy) + ' | ' + addy_dict.get(addy, '')) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment