diff --git a/.env b/.env index a9ef090..4c54601 100644 --- a/.env +++ b/.env @@ -38,4 +38,3 @@ SUBSCRIPTION_ID='2217755' # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. # See the documentation for all the connection string options: https://pris.ly/d/connection-strings -DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" \ No newline at end of file diff --git a/crypto/sol/app.py b/crypto/sol/app.py index 02a3d76..22dfd60 100644 --- a/crypto/sol/app.py +++ b/crypto/sol/app.py @@ -405,6 +405,15 @@ app = init_app() # Convert Flask app to ASGI asgi_app = WsgiToAsgi(app) +async def restartable_task(task_func, *args, **kwargs): + while True: + try: + await task_func(*args, **kwargs) + except Exception as e: + logging.error(f"Error in task {task_func.__name__}: {e}") + await telegram_utils.send_telegram_message(f"Error in task {task_func.__name__}: {e}") + await asyncio.sleep(5) # Wait before retrying + async def main(): global bot, PROCESSING_LOG, pk @@ -413,10 +422,11 @@ async def main(): await telegram_utils.send_telegram_message("Solana Agent Started. Connecting to mainnet...") # Start the log processor - asyncio.create_task(watch_for_new_logs()) + asyncio.create_task(restartable_task(watch_for_new_logs)) # process_transaction if DO_WATCH_WALLET: + asyncio.create_task(restartable_task(SAPI.wallet_watch_loop)) await SAPI.wallet_watch_loop() def run_asyncio_tasks(): diff --git a/crypto/sol/modules/log_processor.py b/crypto/sol/modules/log_processor.py index b5b5e30..32b8b18 100644 --- a/crypto/sol/modules/log_processor.py +++ b/crypto/sol/modules/log_processor.py @@ -1,10 +1,11 @@ import os import asyncio from pathlib import Path -from .storage import store_transaction +from .storage import store_transaction, prisma_client +from .SolanaAPI import SolanaAPI -LOG_DIRECTORY = "path/to/log/directory" -FILE_MASK = "*.log" +LOG_DIRECTORY = "logs" +FILE_MASK = "wh_*.json" async def process_log_file(file_path): # Read the file and extract transaction data @@ -22,8 +23,18 @@ async def process_log_file(file_path): solana_signature = "extracted_solana_signature" details = {} - # Store the transaction - await store_transaction(wallet_id, transaction_type, sell_currency, sell_amount, sell_value, buy_currency, buy_amount, buy_value, solana_signature, details) + # Process the webhook data + solana_api = SolanaAPI() + transaction_data = await solana_api.process_wh(data) + + # Check if the transaction already exists + existing_transaction = await prisma_client.transaction.find_first( + where={'solana_signature': solana_signature} + ) + + if not existing_transaction: + # Store the transaction if it doesn't exist + await store_transaction(wallet_id, transaction_type, sell_currency, sell_amount, sell_value, buy_currency, buy_amount, buy_value, solana_signature, details) # Rename the file to append '_saved' new_file_path = file_path.with_name(file_path.stem + "_saved" + file_path.suffix) diff --git a/crypto/sol/modules/webui.py b/crypto/sol/modules/webui.py index a478828..2b2b307 100644 --- a/crypto/sol/modules/webui.py +++ b/crypto/sol/modules/webui.py @@ -355,3 +355,5 @@ def get_latest_log_file(wh:bool): except Exception as e: utils.log.error(f"Error fetching latest log file: {e}") return None + +export = init_app \ No newline at end of file diff --git a/crypto/sol/readme.md b/crypto/sol/readme.md index 0da5bee..ebe3326 100644 --- a/crypto/sol/readme.md +++ b/crypto/sol/readme.md @@ -32,11 +32,12 @@ pip-compile requirements.in # Optionally, update your environment # pip-sync requirements.txt -echo "Requirements have been updated in requirements.txt" +prisma on py: +//#python -m prisma generate +pip install -U prisma +prisma db push -max ammount on FATGF gives error: - ERROR:error_logger:Swap Follow Error: -Program log: Instruction: Transfer", "Program log: Error: insufficient funds", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4300 of 1363889 compute units" - +# PROD deployment: +gunicorn -w 4 -k uvicorn.workers.UvicornWorker app:asgi_app --bind 0.0.0.0:3001 --log-level info \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c7d4c76..abb3f80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "kevin-ai", "version": "1.0.0", "dependencies": { - "@prisma/client": "^5.16.1", + "@prisma/client": "^5.22.0", "axios": "^1.7.2", "body-parser": "^1.20.2", "dotenv": "^16.4.5", @@ -26,9 +26,9 @@ } }, "node_modules/@prisma/client": { - "version": "5.16.1", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.16.1.tgz", - "integrity": "sha512-wM9SKQjF0qLxdnOZIVAIMKiz6Hu7vDt4FFAih85K1dk/Rr2mdahy6d3QP41K62N9O0DJJA//gUDA3Mp49xsKIg==", + "version": "5.22.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.22.0.tgz", + "integrity": "sha512-M0SVXfyHnQREBKxCgyo7sffrKttwE6R8PMq330MIUF0pTwjUhLbW84pFDlf06B27XyCR++VtjugEnIHdr07SVA==", "hasInstallScript": true, "engines": { "node": ">=16.13" diff --git a/package.json b/package.json index ff0daf2..5228e31 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "NODE_ENV": "demo" }, "dependencies": { - "@prisma/client": "^5.16.1", + "@prisma/client": "^5.22.0", "axios": "^1.7.2", "body-parser": "^1.20.2", "dotenv": "^16.4.5", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d5fd6d1..4e3465d 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -2,6 +2,19 @@ generator client { provider = "prisma-client-js" } +datasource db { + provider = "mysql" + url = "mysql://root:Zelen0ku4e@192.168.0.10:3306/trader" + //env("DATABASE_URL") +} + + +generator py { + provider = "prisma-client-py" + recursive_type_depth = 5 +} + + model User { id Int @id @default(autoincrement()) username String @unique @@ -76,11 +89,6 @@ model Transaction { timestamp DateTime @default(now()) } -datasource db { - provider = "mysql" - url = "mysql://root:Zelen0ku4e@192.168.0.10:3306/trader" -} - model Timeseries { id Int @id @default(autoincrement()) timestamp DateTime @default(now())