Skip to content

Commit

Permalink
thinbg
Browse files Browse the repository at this point in the history
  • Loading branch information
makemake-kbo committed Jan 3, 2024
1 parent 552df92 commit 28a1e4f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions hrotti/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

from fastapi import FastAPI, WebSocket

from .methods import RPCRequest, handle_request
from .methods import RPCRequest, block_info, handle_request

app = FastAPI()

info = block_info(
head="0x5BAD55",
chain_id="0x1",
coinbase="0x407d73d8a49eeb85d32cf465507dd71d507100c1",
gasprice="0x1",
balance="0x1",
)


@app.post("/http")
async def handle_json_rpc(request: RPCRequest):
return handle_request(request)
return handle_request(request, info)


@app.websocket("/ws")
Expand All @@ -19,10 +27,6 @@ async def websocket_endpoint(websocket: WebSocket):
data = await websocket.receive_text()
try:
request = json.loads(data)
if request.get("method") == "eth_blockNumber":
response = json.dumps(
{"jsonrpc": "2.0", "id": request.get("id"), "result": "0x5BAD55"}
)
await websocket.send_text(response)
await websocket.send_text(handle_request(request.get("method"), info))
except json.JSONDecodeError:
await websocket.send_text("Error: Invalid JSON")

0 comments on commit 28a1e4f

Please sign in to comment.