fix routing issues

This commit is contained in:
Tiago vasconcelos
2021-10-15 16:20:23 +01:00
parent 6935589dad
commit 9096ed38b9

View File

@@ -1,5 +1,6 @@
import time import time
from base64 import urlsafe_b64encode from base64 import urlsafe_b64encode
from pydantic import BaseModel
from lnbits.core.services import pay_invoice, create_invoice from lnbits.core.services import pay_invoice, create_invoice
from lnbits.core.crud import get_payments, delete_expired_invoices from lnbits.core.crud import get_payments, delete_expired_invoices
@@ -15,6 +16,7 @@ from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse, JSONResponse # type: ignore from starlette.responses import HTMLResponse, JSONResponse # type: ignore
from fastapi.params import Depends from fastapi.params import Depends
from fastapi.param_functions import Query from fastapi.param_functions import Query
from fastapi.security import OAuth2PasswordBearer
@lndhub_ext.get("/ext/getinfo") @lndhub_ext.get("/ext/getinfo")
@@ -24,17 +26,20 @@ async def lndhub_getinfo():
detail="bad auth", detail="bad auth",
) )
class AuthData(BaseModel):
login: str = Query(None)
password: str = Query(None)
refresh_token: str = Query(None)
@lndhub_ext.post("/ext/auth") @lndhub_ext.post("/ext/auth")
async def lndhub_auth( async def lndhub_auth(
login: str = Query(None), data: AuthData
password: str = Query(None),
refresh_token: str = Query(None),
): ):
token = ( token = (
refresh_token data.refresh_token
if refresh_token if data.refresh_token
else urlsafe_b64encode((login + ":" + password).encode("utf-8")).decode("ascii") else urlsafe_b64encode((data.login + ":" + data.password).encode("utf-8")).decode("ascii")
) )
return {"refresh_token": token, "access_token": token} return {"refresh_token": token, "access_token": token}
@@ -102,18 +107,19 @@ async def lndhub_payinvoice(
@lndhub_ext.get("/ext/balance") @lndhub_ext.get("/ext/balance")
@check_wallet() # @check_wallet()
async def lndhub_balance( async def lndhub_balance(
wallet: WalletTypeInfo = Depends(get_key_type), wallet: WalletTypeInfo = Depends(get_key_type),
): ):
return {"BTC": {"AvailableBalance": wallet.wallet.balance}} return {"BTC": {"AvailableBalance": wallet.wallet.balance}}
@lndhub_ext.route("/ext/gettxs", methods=["GET"]) @lndhub_ext.get("/ext/gettxs")
@check_wallet() # @check_wallet()
async def lndhub_gettxs( async def lndhub_gettxs(
wallet: WalletTypeInfo = Depends(get_key_type), limit: int = Query(0, ge=0, lt=200) wallet: WalletTypeInfo = Depends(get_key_type), limit: int = Query(0, ge=0, lt=200)
): ):
print("WALLET", wallet)
for payment in await get_payments( for payment in await get_payments(
wallet_id=wallet.wallet.id, wallet_id=wallet.wallet.id,
complete=False, complete=False,
@@ -150,7 +156,7 @@ async def lndhub_gettxs(
] ]
@lndhub_ext.route("/ext/getuserinvoices", methods=["GET"]) @lndhub_ext.get("/ext/getuserinvoices")
async def lndhub_getuserinvoices( async def lndhub_getuserinvoices(
wallet: WalletTypeInfo = Depends(get_key_type), limit: int = Query(0, ge=0, lt=200) wallet: WalletTypeInfo = Depends(get_key_type), limit: int = Query(0, ge=0, lt=200)
): ):
@@ -200,7 +206,7 @@ async def lndhub_getbtc(wallet: WalletTypeInfo = Depends(get_key_type)):
@lndhub_ext.get("/ext/getpending") @lndhub_ext.get("/ext/getpending")
@check_wallet() # @check_wallet()
async def lndhub_getpending(): async def lndhub_getpending():
"pending onchain transactions" "pending onchain transactions"
return [] return []