cleaned up
This commit is contained in:
parent
e6a3c63dd5
commit
e84eedd66f
6 changed files with 81 additions and 257 deletions
|
|
@ -1,18 +1,14 @@
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
|
import httpx
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import (
|
from .models import Gerty, Mempool, MempoolEndpoint
|
||||||
Gerty,
|
|
||||||
Mempool,
|
|
||||||
Fees_recommended,
|
|
||||||
Hashrate_1w,
|
|
||||||
Hashrate_1m,
|
|
||||||
Statistics,
|
|
||||||
Difficulty_adjustment,
|
|
||||||
Tip_height)
|
|
||||||
|
|
||||||
async def create_gerty(wallet_id: str, data: Gerty) -> Gerty:
|
async def create_gerty(wallet_id: str, data: Gerty) -> Gerty:
|
||||||
gerty_id = urlsafe_short_hash()
|
gerty_id = urlsafe_short_hash()
|
||||||
|
|
@ -21,9 +17,9 @@ async def create_gerty(wallet_id: str, data: Gerty) -> Gerty:
|
||||||
INSERT INTO gerty.gertys (
|
INSERT INTO gerty.gertys (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
wallet,
|
|
||||||
utc_offset,
|
utc_offset,
|
||||||
type,
|
type,
|
||||||
|
wallet,
|
||||||
lnbits_wallets,
|
lnbits_wallets,
|
||||||
mempool_endpoint,
|
mempool_endpoint,
|
||||||
exchange,
|
exchange,
|
||||||
|
|
@ -35,9 +31,9 @@ async def create_gerty(wallet_id: str, data: Gerty) -> Gerty:
|
||||||
(
|
(
|
||||||
gerty_id,
|
gerty_id,
|
||||||
data.name,
|
data.name,
|
||||||
data.wallet,
|
|
||||||
data.utc_offset,
|
data.utc_offset,
|
||||||
data.type,
|
data.type,
|
||||||
|
wallet_id,
|
||||||
data.lnbits_wallets,
|
data.lnbits_wallets,
|
||||||
data.mempool_endpoint,
|
data.mempool_endpoint,
|
||||||
data.exchange,
|
data.exchange,
|
||||||
|
|
@ -82,124 +78,35 @@ async def delete_gerty(gerty_id: str) -> None:
|
||||||
|
|
||||||
#############MEMPOOL###########
|
#############MEMPOOL###########
|
||||||
|
|
||||||
async def get_fees_recommended(gerty) -> Optional[Fees_recommended]:
|
async def get_mempool_info(endPoint: str, gerty) -> Optional[Mempool]:
|
||||||
row = await db.fetchone("SELECT * FROM gerty.fees_recommended", ())
|
endpoints = MempoolEndpoint()
|
||||||
|
url = ""
|
||||||
|
for endpoint in endpoints:
|
||||||
|
logger.debug(endpoint)
|
||||||
|
if endPoint == endpoint[0]:
|
||||||
|
url = endpoint[1]
|
||||||
|
row = await db.fetchone("SELECT * FROM gerty.mempool WHERE endpoint = ?", (endPoint,))
|
||||||
|
if not row:
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
response = await client.get(gerty.mempool_endpoint + url)
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO gerty.mempool (
|
||||||
|
endpoint,
|
||||||
|
data,
|
||||||
|
time,
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
""",
|
||||||
|
(endPoint, json.dumps(response.json()), int(time.time())),
|
||||||
|
)
|
||||||
|
return response.json()
|
||||||
if int(time.time()) - row.time > 20:
|
if int(time.time()) - row.time > 20:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(gerty.mempool_endpoint + "/api/v1/fees/recommended")
|
response = await client.get(gerty.mempool_endpoint + url)
|
||||||
if response.status_code == 200:
|
await db.execute(
|
||||||
await db.execute(
|
"UPDATE gerty.mempool SET data = ?, time = ? WHERE endpoint = ?",
|
||||||
"""
|
(json.dumps(response.json()), int(time.time()), endPoint),
|
||||||
UPDATE gerty.fees_recommended
|
)
|
||||||
SET data = ?, time = ?
|
return response.json()
|
||||||
""",
|
return json.loads(row.data)
|
||||||
(response.json(), int(time.time())),
|
|
||||||
)
|
|
||||||
return Fees_recommended(**response) if response else None
|
|
||||||
else:
|
|
||||||
return Fees_recommended(**row) if row else None
|
|
||||||
|
|
||||||
async def get_hashrate_1w(gerty) -> Optional[Hashrate_1w]:
|
|
||||||
row = await db.fetchone("SELECT * FROM gerty.hashrate_1w", ())
|
|
||||||
if int(time.time()) - row.time > 20:
|
|
||||||
async with httpx.AsyncClient() as client:
|
|
||||||
response = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/1w")
|
|
||||||
if response.status_code == 200:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE gerty.hashrate_1w
|
|
||||||
SET data = ?, time = ?
|
|
||||||
""",
|
|
||||||
(response.json(), int(time.time())),
|
|
||||||
)
|
|
||||||
return Hashrate_1w(**response) if response else None
|
|
||||||
else:
|
|
||||||
return Hashrate_1w(**row) if row else None
|
|
||||||
|
|
||||||
async def get_hashrate_1m(gerty) -> Optional[Hashrate_1m]:
|
|
||||||
row = await db.fetchone("SELECT * FROM gerty.hashrate_1m", ())
|
|
||||||
if int(time.time()) - row.time > 20:
|
|
||||||
async with httpx.AsyncClient() as client:
|
|
||||||
response = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/1m")
|
|
||||||
if response.status_code == 200:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE gerty.hashrate_1m
|
|
||||||
SET data = ?, time = ?
|
|
||||||
""",
|
|
||||||
(response.json(), int(time.time())),
|
|
||||||
)
|
|
||||||
return Hashrate_1m(**response) if response else None
|
|
||||||
else:
|
|
||||||
return Hashrate_1m(**row) if row else None
|
|
||||||
|
|
||||||
async def get_statistics(gerty) -> Optional[Statistics]:
|
|
||||||
row = await db.fetchone("SELECT * FROM gerty.statistics", ())
|
|
||||||
if int(time.time()) - row.time > 20:
|
|
||||||
async with httpx.AsyncClient() as client:
|
|
||||||
response = await client.get(gerty.mempool_endpoint + "/api/v1/lightning/statistics/latest")
|
|
||||||
if response.status_code == 200:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE gerty.statistics
|
|
||||||
SET data = ?, time = ?
|
|
||||||
""",
|
|
||||||
(response.json(), int(time.time())),
|
|
||||||
)
|
|
||||||
return Statistics(**response) if response else None
|
|
||||||
else:
|
|
||||||
return Statistics(**row) if row else None
|
|
||||||
|
|
||||||
async def get_difficulty_adjustment(gerty) -> Optional[Difficulty_adjustment]:
|
|
||||||
row = await db.fetchone("SELECT * FROM gerty.difficulty_adjustment", ())
|
|
||||||
logger.debug(int(time.time()))
|
|
||||||
logger.debug(row.time)
|
|
||||||
logger.debug(int(time.time()) - row.time)
|
|
||||||
if int(time.time()) - row.time > 20:
|
|
||||||
async with httpx.AsyncClient() as client:
|
|
||||||
response = await client.get(gerty.mempool_endpoint + "/api/v1/difficulty-adjustment")
|
|
||||||
if response.status_code == 200:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE gerty.difficulty_adjustment
|
|
||||||
SET data = ?, time = ?
|
|
||||||
""",
|
|
||||||
(response.json(), int(time.time())),
|
|
||||||
)
|
|
||||||
return Difficulty_adjustment(**response) if response else None
|
|
||||||
else:
|
|
||||||
return Difficulty_adjustment(**row) if row else None
|
|
||||||
|
|
||||||
async def get_tip_height() -> Optional[Tip_height]:
|
|
||||||
row = await db.fetchone("SELECT * FROM gerty.tip_height", ())
|
|
||||||
if int(time.time()) - row.time > 20:
|
|
||||||
async with httpx.AsyncClient() as client:
|
|
||||||
response = await client.get(gerty.mempool_endpoint + "/api/blocks/tip/height")
|
|
||||||
if response.status_code == 200:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE gerty.tip_height
|
|
||||||
SET data = ?, time = ?
|
|
||||||
""",
|
|
||||||
(response.json(), int(time.time())),
|
|
||||||
)
|
|
||||||
return Tip_height(**response) if response else None
|
|
||||||
else:
|
|
||||||
return Tip_height(**row) if row else None
|
|
||||||
|
|
||||||
async def get_mempool() -> Optional[Mempool]:
|
|
||||||
row = await db.fetchone("SELECT * FROM gerty.mempool", ())
|
|
||||||
if int(time.time()) - row.time > 20:
|
|
||||||
async with httpx.AsyncClient() as client:
|
|
||||||
response = await client.get(gerty.mempool_endpoint + "/api/mempool")
|
|
||||||
if response.status_code == 200:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE gerty.mempool
|
|
||||||
SET data = ?, time = ?
|
|
||||||
""",
|
|
||||||
(response.json(), int(time.time())),
|
|
||||||
)
|
|
||||||
return Mempool(**response) if response else None
|
|
||||||
else:
|
|
||||||
return Mempool(**row) if row else None
|
|
||||||
|
|
@ -4,15 +4,7 @@ from datetime import datetime, timedelta
|
||||||
import httpx
|
import httpx
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from .crud import (
|
from .crud import get_mempool_info
|
||||||
get_fees_recommended,
|
|
||||||
get_hashrate_1w,
|
|
||||||
get_hashrate_1m,
|
|
||||||
get_statistics,
|
|
||||||
get_difficulty_adjustment,
|
|
||||||
get_tip_height,
|
|
||||||
get_mempool
|
|
||||||
)
|
|
||||||
|
|
||||||
from .number_prefixer import *
|
from .number_prefixer import *
|
||||||
|
|
||||||
|
|
@ -80,7 +72,7 @@ async def get_mining_dashboard(gerty):
|
||||||
if isinstance(gerty.mempool_endpoint, str):
|
if isinstance(gerty.mempool_endpoint, str):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
# current hashrate
|
# current hashrate
|
||||||
r = await get_hashrate_1w(gerty)
|
r = await get_mempool_info("get_hashrate_1w", gerty)
|
||||||
data = r.json()
|
data = r.json()
|
||||||
hashrateNow = data["currentHashrate"]
|
hashrateNow = data["currentHashrate"]
|
||||||
hashrateOneWeekAgo = data["hashrates"][6]["avgHashrate"]
|
hashrateOneWeekAgo = data["hashrates"][6]["avgHashrate"]
|
||||||
|
|
@ -102,7 +94,7 @@ async def get_mining_dashboard(gerty):
|
||||||
)
|
)
|
||||||
areas.append(text)
|
areas.append(text)
|
||||||
|
|
||||||
r = await get_difficulty_adjustment(gerty)
|
r = await get_mempool_info("difficulty_adjustment", gerty)
|
||||||
|
|
||||||
# timeAvg
|
# timeAvg
|
||||||
text = []
|
text = []
|
||||||
|
|
@ -132,7 +124,7 @@ async def get_mining_dashboard(gerty):
|
||||||
)
|
)
|
||||||
areas.append(text)
|
areas.append(text)
|
||||||
|
|
||||||
r = await get_hashrate_1m(gerty)
|
r = await get_mempool_info("hashrate_1m", gerty)
|
||||||
data = r.json()
|
data = r.json()
|
||||||
stat = {}
|
stat = {}
|
||||||
stat["current"] = data["currentDifficulty"]
|
stat["current"] = data["currentDifficulty"]
|
||||||
|
|
@ -144,7 +136,7 @@ async def get_mining_dashboard(gerty):
|
||||||
|
|
||||||
|
|
||||||
async def get_lightning_stats(gerty):
|
async def get_lightning_stats(gerty):
|
||||||
data = await get_statistics(gerty)
|
data = await get_mempool_info("statistics", gerty)
|
||||||
areas = []
|
areas = []
|
||||||
|
|
||||||
text = []
|
text = []
|
||||||
|
|
@ -271,14 +263,14 @@ async def api_get_mining_stat(stat_slug: str, gerty):
|
||||||
stat = ""
|
stat = ""
|
||||||
if stat_slug == "mining_current_hash_rate":
|
if stat_slug == "mining_current_hash_rate":
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await get_hashrate_1m(gerty)
|
r = await get_mempool_info("hashrate_1m", gerty)
|
||||||
data = r.json()
|
data = r.json()
|
||||||
stat = {}
|
stat = {}
|
||||||
stat['current'] = data['currentHashrate']
|
stat['current'] = data['currentHashrate']
|
||||||
stat['1w'] = data['hashrates'][len(data['hashrates']) - 7]['avgHashrate']
|
stat['1w'] = data['hashrates'][len(data['hashrates']) - 7]['avgHashrate']
|
||||||
elif stat_slug == "mining_current_difficulty":
|
elif stat_slug == "mining_current_difficulty":
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await get_hashrate_1m(gerty)
|
r = await get_mempool_info("hashrate_1m", gerty)
|
||||||
data = r.json()
|
data = r.json()
|
||||||
stat = {}
|
stat = {}
|
||||||
stat['current'] = data['currentDifficulty']
|
stat['current'] = data['currentDifficulty']
|
||||||
|
|
@ -328,7 +320,7 @@ async def get_screen_data(screen_num: int, screens_list: dict, gerty):
|
||||||
elif screen_slug == "onchain_block_height":
|
elif screen_slug == "onchain_block_height":
|
||||||
logger.debug("iam block height")
|
logger.debug("iam block height")
|
||||||
text = []
|
text = []
|
||||||
text.append(get_text_item_dict(text=format_number(await get_tip_height(gerty)), font_size=80, gerty_type=gerty.type))
|
text.append(get_text_item_dict(text=format_number(await get_mempool_info("tip_height", gerty)), font_size=80, gerty_type=gerty.type))
|
||||||
areas.append(text)
|
areas.append(text)
|
||||||
elif screen_slug == "onchain_difficulty_retarget_date":
|
elif screen_slug == "onchain_difficulty_retarget_date":
|
||||||
areas.append(await get_onchain_stat(screen_slug, gerty))
|
areas.append(await get_onchain_stat(screen_slug, gerty))
|
||||||
|
|
@ -383,7 +375,7 @@ async def get_dashboard(gerty):
|
||||||
|
|
||||||
# Mempool fees
|
# Mempool fees
|
||||||
text = []
|
text = []
|
||||||
text.append(get_text_item_dict(text=format_number(await get_tip_height(gerty)), font_size=40,gerty_type=gerty.type))
|
text.append(get_text_item_dict(text=format_number(await get_mempool_info("tip_height", gerty)), font_size=40,gerty_type=gerty.type))
|
||||||
text.append(get_text_item_dict(text="Current block height", font_size=15,gerty_type=gerty.type))
|
text.append(get_text_item_dict(text="Current block height", font_size=15,gerty_type=gerty.type))
|
||||||
areas.append(text)
|
areas.append(text)
|
||||||
|
|
||||||
|
|
@ -467,7 +459,7 @@ async def get_onchain_stat(stat_slug: str, gerty):
|
||||||
|
|
||||||
):
|
):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await get_difficulty_adjustment(gerty)
|
r = await get_mempool_info("difficulty_adjustment", gerty)
|
||||||
if stat_slug == "onchain_difficulty_epoch_progress":
|
if stat_slug == "onchain_difficulty_epoch_progress":
|
||||||
stat = round(r.json()['progressPercent'])
|
stat = round(r.json()['progressPercent'])
|
||||||
text.append(get_text_item_dict(text="Progress through current difficulty epoch", font_size=15,gerty_type=gerty.type))
|
text.append(get_text_item_dict(text="Progress through current difficulty epoch", font_size=15,gerty_type=gerty.type))
|
||||||
|
|
@ -491,7 +483,7 @@ async def get_onchain_dashboard(gerty):
|
||||||
areas = []
|
areas = []
|
||||||
if isinstance(gerty.mempool_endpoint, str):
|
if isinstance(gerty.mempool_endpoint, str):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await get_difficulty_adjustment(gerty)
|
r = await get_mempool_info("difficulty_adjustment", gerty)
|
||||||
text = []
|
text = []
|
||||||
stat = round(r.json()["progressPercent"])
|
stat = round(r.json()["progressPercent"])
|
||||||
text.append(get_text_item_dict(text="Progress through epoch", font_size=12,gerty_type=gerty.type))
|
text.append(get_text_item_dict(text="Progress through epoch", font_size=12,gerty_type=gerty.type))
|
||||||
|
|
@ -523,7 +515,7 @@ async def get_onchain_dashboard(gerty):
|
||||||
async def get_time_remaining_next_difficulty_adjustment(gerty):
|
async def get_time_remaining_next_difficulty_adjustment(gerty):
|
||||||
if isinstance(gerty.mempool_endpoint, str):
|
if isinstance(gerty.mempool_endpoint, str):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await get_difficulty_adjustment(gerty)
|
r = await get_mempool_info("difficulty_adjustment", gerty)
|
||||||
stat = r.json()["remainingTime"]
|
stat = r.json()["remainingTime"]
|
||||||
time = get_time_remaining(stat / 1000, 3)
|
time = get_time_remaining(stat / 1000, 3)
|
||||||
return time
|
return time
|
||||||
|
|
@ -534,7 +526,7 @@ async def get_mempool_stat(stat_slug: str, gerty):
|
||||||
if isinstance(gerty.mempool_endpoint, str):
|
if isinstance(gerty.mempool_endpoint, str):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
if stat_slug == "mempool_tx_count":
|
if stat_slug == "mempool_tx_count":
|
||||||
r = get_mempool(gerty)
|
r = get_mempool_info("mempool", gerty)
|
||||||
if stat_slug == "mempool_tx_count":
|
if stat_slug == "mempool_tx_count":
|
||||||
stat = round(r.json()["count"])
|
stat = round(r.json()["count"])
|
||||||
text.append(get_text_item_dict(text="Transactions in the mempool", font_size=15,gerty_type=gerty.type))
|
text.append(get_text_item_dict(text="Transactions in the mempool", font_size=15,gerty_type=gerty.type))
|
||||||
|
|
@ -543,7 +535,7 @@ async def get_mempool_stat(stat_slug: str, gerty):
|
||||||
)
|
)
|
||||||
elif stat_slug == "mempool_recommended_fees":
|
elif stat_slug == "mempool_recommended_fees":
|
||||||
y_offset = 60
|
y_offset = 60
|
||||||
fees = await get_fees_recommended()
|
fees = await get_mempool_info("fees_recommended", gerty)
|
||||||
pos_y = 80 + y_offset
|
pos_y = 80 + y_offset
|
||||||
text.append(get_text_item_dict("mempool.space", 40, 160, pos_y, gerty.type))
|
text.append(get_text_item_dict("mempool.space", 40, 160, pos_y, gerty.type))
|
||||||
pos_y = 180 + y_offset
|
pos_y = 180 + y_offset
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ async def m001_initial(db):
|
||||||
"""
|
"""
|
||||||
CREATE TABLE gerty.gertys (
|
CREATE TABLE gerty.gertys (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
|
wallet TEXT NOT NULL,
|
||||||
refresh_time INT,
|
refresh_time INT,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
wallet TEXT NOT NULL,
|
|
||||||
lnbits_wallets TEXT,
|
lnbits_wallets TEXT,
|
||||||
mempool_endpoint TEXT,
|
mempool_endpoint TEXT,
|
||||||
exchange TEXT,
|
exchange TEXT,
|
||||||
|
|
@ -37,57 +37,10 @@ async def m004_initial(db):
|
||||||
"""
|
"""
|
||||||
Initial Gertys table.
|
Initial Gertys table.
|
||||||
"""
|
"""
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE gerty.fees_recommended (
|
|
||||||
data TEXT NOT NULL,
|
|
||||||
time TIMESTAMP
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE gerty.hashrate_1w (
|
|
||||||
data TEXT NOT NULL,
|
|
||||||
time TIMESTAMP
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE gerty.hashrate_1m (
|
|
||||||
data TEXT NOT NULL,
|
|
||||||
time TIMESTAMP
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE gerty.statistics (
|
|
||||||
data TEXT NOT NULL,
|
|
||||||
time TIMESTAMP
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE gerty.difficulty_adjustment (
|
|
||||||
data TEXT NOT NULL,
|
|
||||||
time TIMESTAMP
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE gerty.tip_height (
|
|
||||||
data TEXT NOT NULL,
|
|
||||||
time TIMESTAMP
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE gerty.mempool (
|
CREATE TABLE gerty.mempool (
|
||||||
|
endpoint TEXT NOT NULL,
|
||||||
data TEXT NOT NULL,
|
data TEXT NOT NULL,
|
||||||
time TIMESTAMP
|
time TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -27,30 +27,16 @@ class Gerty(BaseModel):
|
||||||
|
|
||||||
#########MEMPOOL MODELS###########
|
#########MEMPOOL MODELS###########
|
||||||
|
|
||||||
class Fees_recommended(BaseModel):
|
class MempoolEndpoint(BaseModel):
|
||||||
data: str = Query(None)
|
fees_recommended: str = "/api/v1/fees/recommended"
|
||||||
time: int = Query(None)
|
hashrate_1w: str = "/api/v1/mining/hashrate/1w"
|
||||||
|
hashrate_1m: str = "/api/v1/mining/hashrate/1m"
|
||||||
class Hashrate_1w(BaseModel):
|
statistics: str = "/api/v1/lightning/statistics/latest"
|
||||||
data: str = Query(None)
|
difficulty_adjustment: str = "/api/v1/difficulty-adjustment"
|
||||||
time: int = Query(None)
|
tip_height: str = "/api/blocks/tip/height"
|
||||||
|
mempool: str = "/api/mempool"
|
||||||
class Hashrate_1m(BaseModel):
|
|
||||||
data: str = Query(None)
|
|
||||||
time: int = Query(None)
|
|
||||||
|
|
||||||
class Statistics(BaseModel):
|
|
||||||
data: str = Query(None)
|
|
||||||
time: int = Query(None)
|
|
||||||
|
|
||||||
class Difficulty_adjustment(BaseModel):
|
|
||||||
data: str = Query(None)
|
|
||||||
time: int = Query(None)
|
|
||||||
|
|
||||||
class Tip_height(BaseModel):
|
|
||||||
data: str = Query(None)
|
|
||||||
time: int = Query(None)
|
|
||||||
|
|
||||||
class Mempool(BaseModel):
|
class Mempool(BaseModel):
|
||||||
|
endpoint: str = Query(None)
|
||||||
data: str = Query(None)
|
data: str = Query(None)
|
||||||
time: int = Query(None)
|
time: int = Query(None)
|
||||||
|
|
@ -135,14 +135,6 @@
|
||||||
:options="['Gerty', 'Mini Gerty']"
|
:options="['Gerty', 'Mini Gerty']"
|
||||||
label="Gerty Type *"
|
label="Gerty Type *"
|
||||||
></q-select>
|
></q-select>
|
||||||
<q-select
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
emit-value
|
|
||||||
v-model="formDialog.data.wallet"
|
|
||||||
:options="g.user.walletOptions"
|
|
||||||
label="Wallet *"
|
|
||||||
></q-select>
|
|
||||||
<q-select
|
<q-select
|
||||||
filled
|
filled
|
||||||
multiple
|
multiple
|
||||||
|
|
@ -350,7 +342,7 @@
|
||||||
<q-btn
|
<q-btn
|
||||||
unelevated
|
unelevated
|
||||||
color="primary"
|
color="primary"
|
||||||
:disable="formDialog.data.wallet == null || formDialog.data.name == null"
|
:disable="formDialog.data.name == null"
|
||||||
type="submit"
|
type="submit"
|
||||||
class="q-mr-md"
|
class="q-mr-md"
|
||||||
v-if="!formDialog.data.id"
|
v-if="!formDialog.data.id"
|
||||||
|
|
@ -360,7 +352,7 @@
|
||||||
v-else
|
v-else
|
||||||
unelevated
|
unelevated
|
||||||
color="primary"
|
color="primary"
|
||||||
:disable="formDialog.data.wallet == null || formDialog.data.name == null"
|
:disable="formDialog.data.name == null"
|
||||||
type="submit"
|
type="submit"
|
||||||
>Update Gerty
|
>Update Gerty
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -661,7 +653,6 @@
|
||||||
this.formDialog.data.id = gerty.id
|
this.formDialog.data.id = gerty.id
|
||||||
this.formDialog.data.name = gerty.name
|
this.formDialog.data.name = gerty.name
|
||||||
this.formDialog.data.type = gerty.type
|
this.formDialog.data.type = gerty.type
|
||||||
this.formDialog.data.wallet = gerty.wallet
|
|
||||||
this.formDialog.data.utc_offset = gerty.utc_offset
|
this.formDialog.data.utc_offset = gerty.utc_offset
|
||||||
this.formDialog.data.lnbits_wallets = JSON.parse(gerty.lnbits_wallets)
|
this.formDialog.data.lnbits_wallets = JSON.parse(gerty.lnbits_wallets)
|
||||||
this.formDialog.data.exchange = gerty.exchange,
|
this.formDialog.data.exchange = gerty.exchange,
|
||||||
|
|
@ -677,7 +668,6 @@
|
||||||
this.formDialog.data
|
this.formDialog.data
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
{#console.log('sendFormDataGerty', this.formDialog.data)#}
|
|
||||||
this.createGerty(
|
this.createGerty(
|
||||||
this.g.user.wallets[0].adminkey,
|
this.g.user.wallets[0].adminkey,
|
||||||
this.formDialog.data
|
this.formDialog.data
|
||||||
|
|
@ -687,7 +677,6 @@
|
||||||
createGerty: function () {
|
createGerty: function () {
|
||||||
var data = {
|
var data = {
|
||||||
name: this.formDialog.data.name,
|
name: this.formDialog.data.name,
|
||||||
wallet: this.formDialog.data.wallet,
|
|
||||||
utc_offset: this.formDialog.data.utc_offset,
|
utc_offset: this.formDialog.data.utc_offset,
|
||||||
type: this.formDialog.data.type,
|
type: this.formDialog.data.type,
|
||||||
lnbits_wallets: JSON.stringify(this.formDialog.data.lnbits_wallets),
|
lnbits_wallets: JSON.stringify(this.formDialog.data.lnbits_wallets),
|
||||||
|
|
@ -696,15 +685,13 @@
|
||||||
refresh_time: this.formDialog.data.refresh_time,
|
refresh_time: this.formDialog.data.refresh_time,
|
||||||
display_preferences: JSON.stringify(this.formDialog.data.display_preferences)
|
display_preferences: JSON.stringify(this.formDialog.data.display_preferences)
|
||||||
}
|
}
|
||||||
console.log('createGerty', data)
|
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request(
|
.request(
|
||||||
'POST',
|
'POST',
|
||||||
'/gerty/api/v1/gerty',
|
'/gerty/api/v1/gerty',
|
||||||
_.findWhere(this.g.user.wallets, {id: this.formDialog.data.wallet})
|
this.g.user.wallets[0].inkey,
|
||||||
.inkey,
|
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,11 @@ from .crud import (
|
||||||
get_gerty,
|
get_gerty,
|
||||||
get_gertys,
|
get_gertys,
|
||||||
update_gerty,
|
update_gerty,
|
||||||
get_fees_recommended,
|
get_mempool_info
|
||||||
get_hashrate_1w,
|
|
||||||
get_hashrate_1m,
|
|
||||||
get_statistics,
|
|
||||||
get_difficulty_adjustment,
|
|
||||||
get_tip_height,
|
|
||||||
get_mempool
|
|
||||||
)
|
)
|
||||||
from .helpers import *
|
from .helpers import *
|
||||||
from .models import Gerty
|
|
||||||
|
|
||||||
|
from .models import Gerty, MempoolEndpoint
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty", status_code=HTTPStatus.OK)
|
@gerty_ext.get("/api/v1/gerty", status_code=HTTPStatus.OK)
|
||||||
async def api_gertys(
|
async def api_gertys(
|
||||||
|
|
@ -164,37 +158,42 @@ async def api_gerty_json(gerty_id: str, p: int = None): # page number
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty/fees-recommended/{gerty_id}")
|
@gerty_ext.get("/api/v1/gerty/fees-recommended/{gerty_id}")
|
||||||
async def api_gerty_get_fees_recommended(gerty_id):
|
async def api_gerty_get_fees_recommended(gerty_id):
|
||||||
logger.debug("gerty_id")
|
|
||||||
gerty = await get_gerty(gerty_id)
|
gerty = await get_gerty(gerty_id)
|
||||||
logger.debug(gerty)
|
return await get_mempool_info("fees_recommended", gerty)
|
||||||
return get_fees_recommended(gerty)
|
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty/hashrate-1w/{gerty_id}")
|
@gerty_ext.get("/api/v1/gerty/hashrate-1w/{gerty_id}")
|
||||||
async def api_gerty_get_hashrate_1w(gerty_id):
|
async def api_gerty_get_hashrate_1w(gerty_id):
|
||||||
gerty = await get_gerty(gerty_id)
|
gerty = await get_gerty(gerty_id)
|
||||||
return get_hashrate_1w(gerty)
|
return await get_mempool_info("hashrate_1w", gerty)
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty/hashrate-1m/{gerty_id}")
|
@gerty_ext.get("/api/v1/gerty/hashrate-1m/{gerty_id}")
|
||||||
async def api_gerty_get_hashrate_1m(gerty_id):
|
async def api_gerty_get_hashrate_1m(gerty_id):
|
||||||
gerty = await get_gerty(gerty_id)
|
gerty = await get_gerty(gerty_id)
|
||||||
return get_hashrate_1m(gerty)
|
return await get_mempool_info("hashrate_1m", gerty)
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty/statistics/{gerty_id}")
|
@gerty_ext.get("/api/v1/gerty/statistics/{gerty_id}")
|
||||||
async def api_gerty_get_statistics(gerty_id):
|
async def api_gerty_get_statistics(gerty_id):
|
||||||
gerty = await get_gerty(gerty_id)
|
gerty = await get_gerty(gerty_id)
|
||||||
return get_statistics(gerty)
|
return await get_mempool_info("statistics", gerty)
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty/difficulty-adjustment/{gerty_id}")
|
@gerty_ext.get("/api/v1/gerty/difficulty-adjustment/{gerty_id}")
|
||||||
async def api_gerty_get_difficulty_adjustment(gerty_id):
|
async def api_gerty_get_difficulty_adjustment(gerty_id):
|
||||||
gerty = await get_gerty(gerty_id)
|
gerty = await get_gerty(gerty_id)
|
||||||
return get_difficulty_adjustment(gerty)
|
return await get_mempool_info("difficulty_adjustment", gerty)
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty/tip-height/{gerty_id}")
|
@gerty_ext.get("/api/v1/gerty/tip-height/{gerty_id}")
|
||||||
async def api_gerty_get_tip_height(gerty_id):
|
async def api_gerty_get_tip_height(gerty_id):
|
||||||
gerty = await get_gerty(gerty_id)
|
gerty = await get_gerty(gerty_id)
|
||||||
return get_tip_height(gerty)
|
return await get_mempool_info("tip_height", gerty)
|
||||||
|
|
||||||
@gerty_ext.get("/api/v1/gerty/mempool/{gerty_id}")
|
@gerty_ext.get("/api/v1/gerty/mempool/{gerty_id}")
|
||||||
async def api_gerty_get_mempool(gerty_id):
|
async def api_gerty_get_mempool(gerty_id):
|
||||||
gerty = await get_gerty(gerty_id)
|
gerty = await get_gerty(gerty_id)
|
||||||
return get_mempool(gerty)
|
return await get_mempool_info("mempool", gerty)
|
||||||
|
|
||||||
|
@gerty_ext.get("/api/v1/gerty/wibble/{gerty_id}")
|
||||||
|
async def api_gerty_get_wibble(gerty_id):
|
||||||
|
endPoint = "fees_recommended"
|
||||||
|
gerty = await get_gerty(gerty_id)
|
||||||
|
return await get_mempool_info("fees_recommended", gerty)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue