-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa0973f
commit b4e0478
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
import json | ||
|
||
|
||
class DummyRPCHandler(BaseHTTPRequestHandler): | ||
def _set_response(self, status_code=200): | ||
self.send_response(status_code) | ||
self.send_header('Content-type', 'application/json') | ||
self.end_headers() | ||
|
||
def do_POST(self): | ||
content_length = int(self.headers['Content-Length']) | ||
request_body = self.rfile.read(content_length) | ||
rpc_request = json.loads(request_body) | ||
|
||
if rpc_request['method'] == 'eth_blockNumber': | ||
response = { | ||
"jsonrpc": "2.0", | ||
"id": rpc_request['id'], | ||
"result": "0x123456" # Dummy block number | ||
} | ||
else: | ||
response = { | ||
"jsonrpc": "2.0", | ||
"id": rpc_request['id'], | ||
"error": { | ||
"code": -32601, | ||
"message": "Method not found" | ||
} | ||
} | ||
|
||
self._set_response() | ||
self.wfile.write(json.dumps(response).encode()) | ||
|
||
def do_GET(self): | ||
self._set_response(404) | ||
self.wfile.write(b'Not found') | ||
|
||
|
||
def run_server(): | ||
server_address = ('localhost', 8000) | ||
httpd = HTTPServer(server_address, DummyRPCHandler) | ||
print('Dummy RPC server is running on http://localhost:8000...') | ||
httpd.serve_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
run_server() |
This file contains 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