From 6b1781f2e32fdc524b2586e348e18dab1003061d Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Wed, 10 Apr 2024 15:25:35 +0200 Subject: [PATCH] Fix: vm-connector used obsolete software The vm-connector service used to run with obsolete versions of the aleph-sdk and Python. Solution: Use the latest the version of the SDK and pin the version of dependencies. --- docker/vm_connector.dockerfile | 4 ++-- vm_connector/main.py | 36 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/docker/vm_connector.dockerfile b/docker/vm_connector.dockerfile index 3aebf7478..61dd4bef6 100644 --- a/docker/vm_connector.dockerfile +++ b/docker/vm_connector.dockerfile @@ -1,11 +1,11 @@ -FROM python:3.9 +FROM python:3.11 RUN apt-get update && apt-get -y upgrade && apt-get install -y \ libsecp256k1-dev \ zip \ && rm -rf /var/lib/apt/lists/* -RUN pip install fastapi aiofiles uvicorn aleph-client eth-account +RUN pip install 'fastapi==0.110.0' 'aiofiles==23.2.1' 'uvicorn==0.29.0' 'aleph-sdk-python==0.9.1' WORKDIR /opt ENV PYTHONPATH=/opt diff --git a/vm_connector/main.py b/vm_connector/main.py index 02662d923..353326498 100644 --- a/vm_connector/main.py +++ b/vm_connector/main.py @@ -3,14 +3,16 @@ from typing import Dict, Optional, Union import aiohttp -from aleph_client.asynchronous import create_post -from aleph_client.chains.common import get_fallback_private_key -from aleph_client.chains.ethereum import ETHAccount -from aleph_client.types import StorageEnum +from aleph_message.status import MessageStatus from fastapi import FastAPI, HTTPException, Request from fastapi.responses import Response, StreamingResponse from pydantic import BaseModel +from aleph.sdk import AuthenticatedAlephHttpClient +from aleph.sdk.chains.common import get_fallback_private_key +from aleph.sdk.chains.ethereum import ETHAccount +from aleph.sdk.types import StorageEnum + from .conf import settings logger = logging.getLogger(__file__) @@ -167,17 +169,21 @@ async def publish_data(body: PostBody): content = json.loads(message["item_content"]) content_content = content["content"] - result = await create_post( - account=account, - post_content=content_content, - post_type=content["type"], - address=content["address"], - ref=None, - channel=message["channel"], - inline=True, - storage_engine=StorageEnum.storage, - ) - return {"status": "success"} + async with AuthenticatedAlephHttpClient(account) as client: + result, status = await client.create_post( + post_content=content_content, + post_type=content["type"], + address=content["address"], + ref=None, + channel=message["channel"], + inline=True, + storage_engine=StorageEnum.storage, + sync=True, + ) + if status == MessageStatus.PROCESSED: + return {"status": "success"} + else: + return {"status": "error"} @app.get("/properties")