mirror of https://github.com/skygpu/skynet.git
Add configurable explorer and ipfs links
parent
edd6ccc3e1
commit
20ee6c0317
|
@ -391,6 +391,18 @@ def telegram(
|
|||
|
||||
ipfs_url = load_key(config, 'skynet.telegram.ipfs_url')
|
||||
|
||||
try:
|
||||
explorer_domain = load_key(config, 'skynet.telegram.explorer_domain')
|
||||
|
||||
except ConfigParsingError:
|
||||
explorer_domain = DEFAULT_EXPLORER_DOMAIN
|
||||
|
||||
try:
|
||||
ipfs_domain = load_key(config, 'skynet.telegram.ipfs_domain')
|
||||
|
||||
except ConfigParsingError:
|
||||
ipfs_domain = DEFAULT_IPFS_DOMAIN
|
||||
|
||||
async def _async_main():
|
||||
frontend = SkynetTelegramFrontend(
|
||||
tg_token,
|
||||
|
@ -401,7 +413,9 @@ def telegram(
|
|||
db_host, db_user, db_pass,
|
||||
ipfs_url,
|
||||
remote_ipfs_node=ipfs_gateway_url,
|
||||
key=key
|
||||
key=key,
|
||||
explorer_domain=explorer_domain,
|
||||
ipfs_domain=ipfs_domain
|
||||
)
|
||||
|
||||
async with frontend.open():
|
||||
|
@ -442,6 +456,18 @@ def discord(
|
|||
ipfs_gateway_url = load_key(config, 'skynet.discord.ipfs_gateway_url')
|
||||
ipfs_url = load_key(config, 'skynet.discord.ipfs_url')
|
||||
|
||||
try:
|
||||
explorer_domain = load_key(config, 'skynet.discord.explorer_domain')
|
||||
|
||||
except ConfigParsingError:
|
||||
explorer_domain = DEFAULT_EXPLORER_DOMAIN
|
||||
|
||||
try:
|
||||
ipfs_domain = load_key(config, 'skynet.discord.ipfs_domain')
|
||||
|
||||
except ConfigParsingError:
|
||||
ipfs_domain = DEFAULT_IPFS_DOMAIN
|
||||
|
||||
async def _async_main():
|
||||
frontend = SkynetDiscordFrontend(
|
||||
# dc_token,
|
||||
|
@ -452,7 +478,9 @@ def discord(
|
|||
db_host, db_user, db_pass,
|
||||
ipfs_url,
|
||||
remote_ipfs_node=ipfs_gateway_url,
|
||||
key=key
|
||||
key=key,
|
||||
explorer_domain=explorer_domain,
|
||||
ipfs_domain=ipfs_domain
|
||||
)
|
||||
|
||||
async with frontend.open():
|
||||
|
|
|
@ -183,7 +183,8 @@ CONFIG_ATTRS = [
|
|||
'upscaler'
|
||||
]
|
||||
|
||||
DEFAULT_DOMAIN = 'skygpu.net'
|
||||
DEFAULT_EXPLORER_DOMAIN = 'explorer.skygpu.net'
|
||||
DEFAULT_IPFS_DOMAIN = 'ipfs.skygpu.net'
|
||||
|
||||
DEFAULT_IPFS_REMOTE = '/ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv'
|
||||
DEFAULT_IPFS_LOCAL = 'http://127.0.0.1:5001'
|
||||
|
|
|
@ -9,19 +9,17 @@ from pathlib import Path
|
|||
from functools import partial
|
||||
|
||||
import asks
|
||||
import numpy
|
||||
import trio
|
||||
import anyio
|
||||
import torch
|
||||
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
|
||||
from leap.cleos import CLEOS
|
||||
from leap.sugar import Checksum256, Name, asset_from_str
|
||||
from skynet.constants import DEFAULT_IPFS_DOMAIN
|
||||
|
||||
from skynet.ipfs import AsyncIPFSHTTP, get_ipfs_file
|
||||
from skynet.dgpu.errors import DGPUComputeError
|
||||
from skynet.constants import DEFAULT_DOMAIN
|
||||
|
||||
|
||||
REQUEST_UPDATE_TIME = 3
|
||||
|
@ -61,6 +59,10 @@ class SkynetGPUConnector:
|
|||
|
||||
self.ipfs_client = AsyncIPFSHTTP(self.ipfs_url)
|
||||
|
||||
self.ipfs_domain = DEFAULT_IPFS_DOMAIN
|
||||
if 'ipfs_domain' in config:
|
||||
self.ipfs_domain = config['ipfs_domain']
|
||||
|
||||
self._wip_requests = {}
|
||||
|
||||
# blockchain helpers
|
||||
|
@ -272,7 +274,7 @@ class SkynetGPUConnector:
|
|||
return b'', input_type
|
||||
|
||||
results = {}
|
||||
ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}'
|
||||
ipfs_link = f'https://{self.ipfs_domain}/ipfs/{ipfs_hash}'
|
||||
ipfs_link_legacy = ipfs_link + '/image.png'
|
||||
|
||||
async with trio.open_nursery() as n:
|
||||
|
|
|
@ -45,7 +45,9 @@ class SkynetDiscordFrontend:
|
|||
db_pass: str,
|
||||
ipfs_url: str,
|
||||
remote_ipfs_node: str,
|
||||
key: str
|
||||
key: str,
|
||||
explorer_domain: str,
|
||||
ipfs_domain: str
|
||||
):
|
||||
# self.token = token
|
||||
self.account = account
|
||||
|
@ -58,6 +60,8 @@ class SkynetDiscordFrontend:
|
|||
self.ipfs_url = ipfs_url
|
||||
self.remote_ipfs_node = remote_ipfs_node
|
||||
self.key = key
|
||||
self.explorer_domain = explorer_domain
|
||||
self.ipfs_domain = ipfs_domain
|
||||
|
||||
self.bot = DiscordBot(self)
|
||||
self.cleos = CLEOS(None, None, url=node_url, remote=node_url)
|
||||
|
@ -169,7 +173,7 @@ class SkynetDiscordFrontend:
|
|||
return False
|
||||
|
||||
enqueue_tx_id = res['transaction_id']
|
||||
enqueue_tx_link = f'[**Your request on Skynet Explorer**](https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{enqueue_tx_id})'
|
||||
enqueue_tx_link = f'[**Your request on Skynet Explorer**](https://{self.explorer_domain}/v2/explore/transaction/{enqueue_tx_id})'
|
||||
|
||||
msg_text += f'**broadcasted!** \n{enqueue_tx_link}\n[{timestamp_pretty()}] *workers are processing request...* '
|
||||
embed = discord.Embed(
|
||||
|
@ -241,8 +245,48 @@ class SkynetDiscordFrontend:
|
|||
await message.edit(embed=embed)
|
||||
|
||||
# attempt to get the image and send it
|
||||
ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}/image.png'
|
||||
resp = await get_ipfs_file(ipfs_link)
|
||||
results = {}
|
||||
ipfs_link = f'https://{self.ipfs_domain}/ipfs/{ipfs_hash}'
|
||||
ipfs_link_legacy = ipfs_link + '/image.png'
|
||||
|
||||
async def get_and_set_results(link: str):
|
||||
res = await get_ipfs_file(link)
|
||||
logging.info(f'got response from {link}')
|
||||
if not res or res.status_code != 200:
|
||||
logging.warning(f'couldn\'t get ipfs binary data at {link}!')
|
||||
|
||||
else:
|
||||
try:
|
||||
with Image.open(io.BytesIO(res.raw)) as image:
|
||||
tmp_buf = io.BytesIO()
|
||||
image.save(tmp_buf, format='PNG')
|
||||
png_img = tmp_buf.getvalue()
|
||||
results[link] = png_img
|
||||
|
||||
except UnidentifiedImageError:
|
||||
logging.warning(f'couldn\'t get ipfs binary data at {link}!')
|
||||
|
||||
tasks = [
|
||||
get_and_set_results(ipfs_link),
|
||||
get_and_set_results(ipfs_link_legacy)
|
||||
]
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
png_img = None
|
||||
if ipfs_link_legacy in results:
|
||||
png_img = results[ipfs_link_legacy]
|
||||
|
||||
if ipfs_link in results:
|
||||
png_img = results[ipfs_link]
|
||||
|
||||
if not png_img:
|
||||
await self.update_status_message(
|
||||
status_msg,
|
||||
caption,
|
||||
reply_markup=build_redo_menu(),
|
||||
parse_mode='HTML'
|
||||
)
|
||||
return True
|
||||
|
||||
# reword this function, may not need caption
|
||||
caption, embed = generate_reply_caption(
|
||||
|
|
|
@ -81,11 +81,12 @@ def generate_reply_caption(
|
|||
params: dict,
|
||||
tx_hash: str,
|
||||
worker: str,
|
||||
reward: str
|
||||
reward: str,
|
||||
explorer_domain: str
|
||||
):
|
||||
explorer_link = discord.Embed(
|
||||
title='[SKYNET Transaction Explorer]',
|
||||
url=f'https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{tx_hash}',
|
||||
url=f'https://{explorer_domain}/v2/explore/transaction/{tx_hash}',
|
||||
color=discord.Color.blue())
|
||||
|
||||
meta_info = prepare_metainfo_caption(user, worker, reward, params, explorer_link)
|
||||
|
|
|
@ -10,17 +10,17 @@ from json import JSONDecodeError
|
|||
from decimal import Decimal
|
||||
from hashlib import sha256
|
||||
from datetime import datetime
|
||||
from contextlib import ExitStack, AsyncExitStack
|
||||
from contextlib import AsyncExitStack
|
||||
from contextlib import asynccontextmanager as acm
|
||||
|
||||
from leap.cleos import CLEOS
|
||||
from leap.sugar import Name, asset_from_str, collect_stdout
|
||||
from leap.hyperion import HyperionAPI
|
||||
from telebot.types import InputMediaPhoto
|
||||
|
||||
from telebot.types import InputMediaPhoto
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
|
||||
from skynet.db import open_new_database, open_database_connection
|
||||
from skynet.db import open_database_connection
|
||||
from skynet.ipfs import get_ipfs_file, AsyncIPFSHTTP
|
||||
from skynet.constants import *
|
||||
|
||||
|
@ -44,7 +44,9 @@ class SkynetTelegramFrontend:
|
|||
db_pass: str,
|
||||
ipfs_node: str,
|
||||
remote_ipfs_node: str | None,
|
||||
key: str
|
||||
key: str,
|
||||
explorer_domain: str,
|
||||
ipfs_domain: str
|
||||
):
|
||||
self.token = token
|
||||
self.account = account
|
||||
|
@ -56,6 +58,8 @@ class SkynetTelegramFrontend:
|
|||
self.db_pass = db_pass
|
||||
self.remote_ipfs_node = remote_ipfs_node
|
||||
self.key = key
|
||||
self.explorer_domain = explorer_domain
|
||||
self.ipfs_domain = ipfs_domain
|
||||
|
||||
self.bot = AsyncTeleBot(token, exception_handler=SKYExceptionHandler)
|
||||
self.cleos = CLEOS(None, None, url=node_url, remote=node_url)
|
||||
|
@ -161,7 +165,7 @@ class SkynetTelegramFrontend:
|
|||
enqueue_tx_id = res['transaction_id']
|
||||
enqueue_tx_link = hlink(
|
||||
'Your request on Skynet Explorer',
|
||||
f'https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{enqueue_tx_id}'
|
||||
f'https://{self.explorer_domain}/v2/explore/transaction/{enqueue_tx_id}'
|
||||
)
|
||||
|
||||
await self.append_status_message(
|
||||
|
@ -222,7 +226,7 @@ class SkynetTelegramFrontend:
|
|||
|
||||
tx_link = hlink(
|
||||
'Your result on Skynet Explorer',
|
||||
f'https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{tx_hash}'
|
||||
f'https://{self.explorer_domain}/v2/explore/transaction/{tx_hash}'
|
||||
)
|
||||
|
||||
await self.append_status_message(
|
||||
|
@ -234,11 +238,11 @@ class SkynetTelegramFrontend:
|
|||
)
|
||||
|
||||
caption = generate_reply_caption(
|
||||
user, params, tx_hash, worker, reward)
|
||||
user, params, tx_hash, worker, reward, self.explorer_domain)
|
||||
|
||||
# attempt to get the image and send it
|
||||
results = {}
|
||||
ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}'
|
||||
ipfs_link = f'https://{self.ipfs_domain}/ipfs/{ipfs_hash}'
|
||||
ipfs_link_legacy = ipfs_link + '/image.png'
|
||||
|
||||
async def get_and_set_results(link: str):
|
||||
|
@ -278,7 +282,6 @@ class SkynetTelegramFrontend:
|
|||
if ipfs_link in results:
|
||||
png_img = results[ipfs_link]
|
||||
|
||||
|
||||
if not png_img:
|
||||
await self.update_status_message(
|
||||
status_msg,
|
||||
|
|
|
@ -67,11 +67,12 @@ def generate_reply_caption(
|
|||
params: dict,
|
||||
tx_hash: str,
|
||||
worker: str,
|
||||
reward: str
|
||||
reward: str,
|
||||
explorer_domain: str
|
||||
):
|
||||
explorer_link = hlink(
|
||||
'SKYNET Transaction Explorer',
|
||||
f'https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{tx_hash}'
|
||||
f'https://explorer.{explorer_domain}/v2/explore/transaction/{tx_hash}'
|
||||
)
|
||||
|
||||
meta_info = prepare_metainfo_caption(tguser, worker, reward, params)
|
||||
|
|
Loading…
Reference in New Issue