Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCT-1825: Initial passthrough FastAPI server (rebased) #525

Merged
merged 26 commits into from
Oct 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds more migrated code. Allocation and rewards look ok
adam-gf authored and mslomnicki committed Oct 21, 2024
commit 82fc85750ab7210f7c902e2bf2c90b20f4f02272
2 changes: 1 addition & 1 deletion backend/app/__init__.py
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ def register_extensions(app):
cors.init_app(app)
db.init_app(app)
migrate.init_app(app, db)
socketio.init_app(app)
# socketio.init_app(app)
cache.init_app(app)
init_scheduler(app)
init_logger(app)
7 changes: 3 additions & 4 deletions backend/app/extensions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import socketio
from flask_apscheduler import APScheduler
from flask_cors import CORS
from flask_migrate import Migrate
@@ -26,11 +25,11 @@
)
# from flask import current_app as app

socketio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*", logger=True)
# socketio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*", logger=True)

# async_mode="asgi", cors_allowed_origins="*", client_manager=mgr
# async_mode="asgi", cors_allowed_origins="*", client_manager=mgr
# )
# socketio = SocketIO(cors_allowed_origins="*")
socketio = SocketIO(cors_allowed_origins="*")
db = SQLAlchemy()
migrate = Migrate()
cors = CORS()
69 changes: 27 additions & 42 deletions backend/app/infrastructure/events.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from typing import List

from flask import current_app
# from flask_socketio import emit
from flask import current_app as app
from flask_socketio import emit

from app.engine.projects.rewards import ProjectRewardDTO
from app.exceptions import OctantException
@@ -17,27 +17,22 @@


@socketio.on("connect")
async def handle_connect(sid: str, environ: dict):
def handle_connect():
app.logger.debug("Client connected")

print("Type of sid", type(sid))
print("Type of environ", type(environ))
if epochs.get_pending_epoch() is not None:
threshold = get_allocation_threshold()
emit("threshold", {"threshold": str(threshold)})

# socketio.logger.debug("Client connected")
# app_instance = current_app._get_current_object()
with current_app.app_context():
project_rewards = get_estimated_project_rewards().rewards
emit("project_rewards", _serialize_project_rewards(project_rewards))

current_app.logger.debug("Cl/ient connected")

print("Epochs are here")

await socketio.emit("epoch", {"epoch": "fuckup"})

if epochs.get_pending_epoch() is not None:
threshold = get_allocation_threshold()
await socketio.emit("threshold", {"threshold": str(threshold)})

project_rewards = get_estimated_project_rewards().rewards
await socketio.emit("project_rewards", _serialize_project_rewards(project_rewards))
for project in project_rewards:
donors = controller.get_all_donations_by_project(project.address)
emit(
"project_donors",
{"project": project.address, "donors": _serialize_donors(donors)},
)

for project in project_rewards:
donors = controller.get_all_donations_by_project(project.address)
@@ -48,18 +43,13 @@ async def handle_connect(sid: str, environ: dict):


@socketio.on("disconnect")
async def handle_disconnect(sid):
socketio.logger.debug("Client disconnected")
def handle_disconnect():
app.logger.debug("Client disconnected")


@socketio.on("allocate")
async def handle_allocate(sid, msg):

print("message", msg)
def handle_allocate(msg):
msg = json.loads(msg)

print("MEssage", msg)

is_manually_edited = msg["isManuallyEdited"] if "isManuallyEdited" in msg else None
user_address = msg["userAddress"]
app.logger.info(f"User allocation payload: {msg}")
@@ -68,7 +58,7 @@ async def handle_allocate(sid, msg):
msg,
is_manually_edited=is_manually_edited,
)
socketio.logger.info(f"User: {user_address} allocated successfully")
app.logger.info(f"User: {user_address} allocated successfully")

threshold = get_allocation_threshold()
emit("threshold", {"threshold": str(threshold)}, broadcast=True)
@@ -88,21 +78,16 @@ async def handle_allocate(sid, msg):
)


# @socketio.on("project_donors")
# def handle_project_donors(project_address: str):
# print("Project donors")
# emit(
# "project_donors",
# {"project": project_address, "donors": []},
# )
# donors = controller.get_all_donations_by_project(project_address)
# emit(
# "project_donors",
# {"project": project_address, "donors": _serialize_donors(donors)},
# )
@socketio.on("project_donors")
def handle_project_donors(project_address: str):
donors = controller.get_all_donations_by_project(project_address)
emit(
"project_donors",
{"project": project_address, "donors": _serialize_donors(donors)},
)


# @socketio.
@socketio.on_error_default
def default_error_handler(e):
ExceptionHandler.print_stacktrace(e)
if isinstance(e, OctantException):
2 changes: 1 addition & 1 deletion backend/app/settings.py
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ class DevConfig(Config):

ENV = "dev"
DEBUG = True
LOG_LVL = os.getenv("OCTANT_LOG_LEVEL", "DEBUG")
LOG_LVL = os.getenv("OCTANT_LOG_LEVEL", "INFO")
DB_NAME = "dev.db"
CHAIN_ID = int(os.getenv("CHAIN_ID", 1337))
# Put the db file in project root
160 changes: 152 additions & 8 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading