github.com/pdaian/flashboys2@v0.0.0-20190718175736-b101c35361f0/scrape_gasauctions.py (about) 1 from web3 import Web3 2 from receipts import write_receipt 3 4 LOGOUT = "data/gas_slots_6207336_6146507.csv" 5 6 START_BLOCK = 6207336 7 END_BLOCK = 6146507 8 9 curr_block = START_BLOCK 10 11 my_provider = Web3.IPCProvider('/home/geth/parity_mainnet/jsonrpc.ipc') 12 w3 = Web3(my_provider) 13 loghandle = open(LOGOUT, "w") 14 loghandle.write("block_num,tx_position,gas_limit,gas_price,gas_used,from,to,input,hash,log_addrs,log_topics,log_data,gastoken\n") 15 16 while curr_block >= END_BLOCK: 17 while True: 18 try: 19 block = w3.eth.getBlock(curr_block, full_transactions=True) 20 break 21 except: 22 pass # retry in the event of an error 23 numtxs = len(block['transactions']) 24 for txposition in range(0, 10): 25 if txposition >= numtxs: 26 break 27 tx = block['transactions'][txposition] 28 while True: 29 try: 30 receipt = w3.eth.getTransactionReceipt(tx['hash']) 31 break 32 except Exception as e: 33 print(e) # retry in the event of an error 34 35 write_receipt(receipt, tx, loghandle) 36 37 # now do top 10 gas price level txs 38 gas_prices = {} 39 for tx in block['transactions']: 40 gas_price = int(tx['gasPrice']) 41 if not gas_price in gas_prices: 42 gas_prices[gas_price] = [] 43 gas_prices[gas_price].append(tx) 44 45 sorted_prices = sorted(gas_prices.keys(), reverse=True)[:10] 46 for price in sorted_prices: 47 for tx in gas_prices[price]: 48 while True: 49 try: 50 receipt = w3.eth.getTransactionReceipt(tx['hash']) 51 break 52 except Exception as e: 53 print(e) # retry in the event of an error 54 write_receipt(receipt, tx, loghandle) 55 56 print("Done with block", curr_block) 57 curr_block -= 1 58