|
3 | 3 | from typing import Dict, Optional, Union
|
4 | 4 |
|
5 | 5 | import aiohttp
|
6 |
| -from aleph_client.asynchronous import create_post |
7 |
| -from aleph_client.chains.common import get_fallback_private_key |
8 |
| -from aleph_client.chains.ethereum import ETHAccount |
9 |
| -from aleph_client.types import StorageEnum |
| 6 | +from aleph.sdk import AuthenticatedAlephHttpClient |
| 7 | +from aleph.sdk.chains.common import get_fallback_private_key |
| 8 | +from aleph.sdk.chains.ethereum import ETHAccount |
| 9 | +from aleph.sdk.types import StorageEnum |
| 10 | +from aleph_message.status import MessageStatus |
10 | 11 | from fastapi import FastAPI, HTTPException, Request
|
11 | 12 | from fastapi.responses import Response, StreamingResponse
|
12 | 13 | from pydantic import BaseModel
|
@@ -167,17 +168,21 @@ async def publish_data(body: PostBody):
|
167 | 168 | content = json.loads(message["item_content"])
|
168 | 169 | content_content = content["content"]
|
169 | 170 |
|
170 |
| - result = await create_post( |
171 |
| - account=account, |
172 |
| - post_content=content_content, |
173 |
| - post_type=content["type"], |
174 |
| - address=content["address"], |
175 |
| - ref=None, |
176 |
| - channel=message["channel"], |
177 |
| - inline=True, |
178 |
| - storage_engine=StorageEnum.storage, |
179 |
| - ) |
180 |
| - return {"status": "success"} |
| 171 | + async with AuthenticatedAlephHttpClient(account) as client: |
| 172 | + result, status = await client.create_post( |
| 173 | + post_content=content_content, |
| 174 | + post_type=content["type"], |
| 175 | + address=content["address"], |
| 176 | + ref=None, |
| 177 | + channel=message["channel"], |
| 178 | + inline=True, |
| 179 | + storage_engine=StorageEnum.storage, |
| 180 | + sync=True, |
| 181 | + ) |
| 182 | + if status == MessageStatus.PROCESSED: |
| 183 | + return {"status": "success"} |
| 184 | + else: |
| 185 | + return {"status": "error"} |
181 | 186 |
|
182 | 187 |
|
183 | 188 | @app.get("/properties")
|
|
0 commit comments