json loading
This commit is contained in:
parent
08ce55e29e
commit
938024fea2
1 changed files with 38 additions and 14 deletions
|
|
@ -10,6 +10,7 @@ from loguru import logger
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
|
|
||||||
|
from lnbits.core.crud import get_wallet_for_key
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.core.views.api import api_payment, api_wallet
|
from lnbits.core.views.api import api_payment, api_wallet
|
||||||
|
|
@ -20,7 +21,7 @@ from . import gerty_ext
|
||||||
from .crud import create_gerty, update_gerty, delete_gerty, get_gerty, get_gertys
|
from .crud import create_gerty, update_gerty, delete_gerty, get_gerty, get_gertys
|
||||||
from .models import Gerty
|
from .models import Gerty
|
||||||
|
|
||||||
from lnbits.utils.exchange_rates import fiat_amount_as_satoshis
|
from lnbits.utils.exchange_rates import satoshis_amount_as_fiat
|
||||||
from ...settings import LNBITS_PATH
|
from ...settings import LNBITS_PATH
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -100,36 +101,59 @@ async def api_gerty_json(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="Gerty does not exist."
|
status_code=HTTPStatus.NOT_FOUND, detail="Gerty does not exist."
|
||||||
)
|
)
|
||||||
gertyReturn = []
|
gertyReturn = []
|
||||||
|
|
||||||
|
# Get Wallet info
|
||||||
|
wallets = ['wallets']
|
||||||
if gerty.lnbits_wallets != "":
|
if gerty.lnbits_wallets != "":
|
||||||
for lnbits_wallet in json.loads(gerty.lnbits_wallets):
|
for lnbits_wallet in json.loads(gerty.lnbits_wallets):
|
||||||
logger.debug(lnbits_wallet)
|
wallet = await get_wallet_for_key(key=lnbits_wallet)
|
||||||
walletPrint = await api_wallet(wallet=lnbits_wallet)
|
wallets.append({
|
||||||
gertyReturn.wallets.append(walletPrint)
|
"name": wallet.name,
|
||||||
#logger.debug(walletPrint)
|
"balance": wallet.balance_msat,
|
||||||
logger.debug(gertyReturn)
|
})
|
||||||
|
gertyReturn.append(wallets)
|
||||||
|
|
||||||
|
#Get Satoshi quotes
|
||||||
|
satoshi = ['sats_quote']
|
||||||
if gerty.sats_quote:
|
if gerty.sats_quote:
|
||||||
gertyReturn.append(await api_gerty_satoshi())
|
satoshi.append(await api_gerty_satoshi())
|
||||||
|
gertyReturn.append(satoshi)
|
||||||
|
|
||||||
|
#Get Exchange Value
|
||||||
|
exchange = ['exchange']
|
||||||
if gerty.exchange != "":
|
if gerty.exchange != "":
|
||||||
try:
|
try:
|
||||||
gertyReturn.append(await fiat_amount_as_satoshis(1, gerty.exchange))
|
exchange.append({
|
||||||
|
"fiat": gerty.exchange,
|
||||||
|
"amount": await satoshis_amount_as_fiat(100000000, gerty.exchange),
|
||||||
|
})
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
gertyReturn.append(exchange)
|
||||||
|
|
||||||
|
onchain = ['onchain']
|
||||||
if gerty.onchain_stats:
|
if gerty.onchain_stats:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
|
difficulty = ['difficulty']
|
||||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/difficulty-adjustment")
|
r = await client.get(gerty.mempool_endpoint + "/api/v1/difficulty-adjustment")
|
||||||
gertyReturn.append({"difficulty-adjustment": json.dumps(r)})
|
difficulty.append(r.json())
|
||||||
|
onchain.append(difficulty)
|
||||||
|
mempool = ['mempool']
|
||||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/fees/mempool-blocks")
|
r = await client.get(gerty.mempool_endpoint + "/api/v1/fees/mempool-blocks")
|
||||||
gertyReturn.append({"mempool-blocks": json.dumps(r)})
|
mempool.append(r.json())
|
||||||
|
onchain.append(mempool)
|
||||||
|
threed = ['threed']
|
||||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/3d")
|
r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/3d")
|
||||||
gertyReturn.append({"3d": json.dumps(r)})
|
threed.append(r.json())
|
||||||
|
onchain.append(threed)
|
||||||
|
gertyReturn.append(onchain)
|
||||||
|
|
||||||
if gerty.ln_sats:
|
ln = ['ln']
|
||||||
|
if gerty.ln_stats:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(gerty.mempool_endpoint + "/api/v1/lightning/statistics/latest")
|
r = await client.get(gerty.mempool_endpoint + "/api/v1/lightning/statistics/latest")
|
||||||
gertyReturn.append({"latest": json.dumps(r)})
|
ln.append(r.json())
|
||||||
logger.debug(gertyReturn)
|
gertyReturn.append(ln)
|
||||||
return gertyReturn
|
return gertyReturn
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue