etherscan.py 897 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. from http.server import HTTPServer, CGIHTTPRequestHandler
  3. from mmgen.util import msg
  4. from mmgen.util2 import port_in_use
  5. class handler(CGIHTTPRequestHandler):
  6. header = b'HTTP/1.1 200 OK\nContent-type: text/html\n\n'
  7. def do_response(self, target):
  8. with open(f'test/ref/ethereum/etherscan-{target}.html') as fh:
  9. text = fh.read()
  10. self.wfile.write(self.header + text.encode())
  11. def do_GET(self):
  12. return self.do_response('form')
  13. def do_POST(self):
  14. return self.do_response('result')
  15. def run_etherscan_server(server_class=HTTPServer, handler_class=handler):
  16. if port_in_use(28800):
  17. msg('Port 28800 in use. Assuming etherscan server is running')
  18. return True
  19. msg('Etherscan server listening on port 28800')
  20. server_address = ('localhost', 28800)
  21. httpd = server_class(server_address, handler_class)
  22. httpd.serve_forever()
  23. msg('Etherscan server exiting')