fix: mypy errors
This commit is contained in:
committed by
Sebastian Geisler
parent
976a3d4e5c
commit
c3e337a319
@@ -1,7 +1,7 @@
|
||||
from flask import Blueprint
|
||||
|
||||
|
||||
core_app = Blueprint("core", __name__, template_folder="templates", static_folder="static")
|
||||
core_app: Blueprint = Blueprint("core", __name__, template_folder="templates", static_folder="static")
|
||||
|
||||
|
||||
from .views.api import * # noqa
|
||||
|
||||
+13
-4
@@ -16,7 +16,10 @@ def create_account() -> User:
|
||||
user_id = uuid4().hex
|
||||
db.execute("INSERT INTO accounts (id) VALUES (?)", (user_id,))
|
||||
|
||||
return get_account(user_id=user_id)
|
||||
new_account = get_account(user_id=user_id)
|
||||
assert new_account, "Newly created account couldn't be retrieved"
|
||||
|
||||
return new_account
|
||||
|
||||
|
||||
def get_account(user_id: str) -> Optional[User]:
|
||||
@@ -74,7 +77,10 @@ def create_wallet(*, user_id: str, wallet_name: Optional[str] = None) -> Wallet:
|
||||
(wallet_id, wallet_name or DEFAULT_WALLET_NAME, user_id, uuid4().hex, uuid4().hex),
|
||||
)
|
||||
|
||||
return get_wallet(wallet_id=wallet_id)
|
||||
new_wallet = get_wallet(wallet_id=wallet_id)
|
||||
assert new_wallet, "Newly created wallet couldn't be retrieved"
|
||||
|
||||
return new_wallet
|
||||
|
||||
|
||||
def delete_wallet(*, user_id: str, wallet_id: str) -> None:
|
||||
@@ -175,7 +181,7 @@ def delete_wallet_payments_expired(wallet_id: str, *, seconds: int = 86400) -> N
|
||||
|
||||
|
||||
def create_payment(
|
||||
*, wallet_id: str, checking_id: str, amount: str, memo: str, fee: int = 0, pending: bool = True
|
||||
*, wallet_id: str, checking_id: str, amount: int, memo: str, fee: int = 0, pending: bool = True
|
||||
) -> Payment:
|
||||
with open_db() as db:
|
||||
db.execute(
|
||||
@@ -186,7 +192,10 @@ def create_payment(
|
||||
(wallet_id, checking_id, amount, int(pending), memo, fee),
|
||||
)
|
||||
|
||||
return get_wallet_payment(wallet_id, checking_id)
|
||||
new_payment = get_wallet_payment(wallet_id, checking_id)
|
||||
assert new_payment, "Newly created payment couldn't be retrieved"
|
||||
|
||||
return new_payment
|
||||
|
||||
|
||||
def update_payment_status(checking_id: str, pending: bool) -> None:
|
||||
|
||||
@@ -4,8 +4,8 @@ from typing import List, NamedTuple, Optional
|
||||
class User(NamedTuple):
|
||||
id: str
|
||||
email: str
|
||||
extensions: Optional[List[str]] = []
|
||||
wallets: Optional[List["Wallet"]] = []
|
||||
extensions: List[str] = []
|
||||
wallets: List["Wallet"] = []
|
||||
password: Optional[str] = None
|
||||
|
||||
@property
|
||||
@@ -27,9 +27,9 @@ class Wallet(NamedTuple):
|
||||
|
||||
@property
|
||||
def balance(self) -> int:
|
||||
return int(self.balance / 1000)
|
||||
return self.balance // 1000
|
||||
|
||||
def get_payment(self, checking_id: str) -> "Payment":
|
||||
def get_payment(self, checking_id: str) -> Optional["Payment"]:
|
||||
from .crud import get_wallet_payment
|
||||
|
||||
return get_wallet_payment(self.id, checking_id)
|
||||
@@ -59,7 +59,7 @@ class Payment(NamedTuple):
|
||||
|
||||
@property
|
||||
def sat(self) -> int:
|
||||
return self.amount / 1000
|
||||
return self.amount // 1000
|
||||
|
||||
@property
|
||||
def is_in(self) -> bool:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from lnbits.bolt11 import decode as bolt11_decode
|
||||
from lnbits.bolt11 import decode as bolt11_decode # type: ignore
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
from lnbits.settings import WALLET
|
||||
|
||||
@@ -24,7 +24,6 @@ def create_invoice(*, wallet_id: str, amount: int, memo: str) -> Tuple[str, str]
|
||||
|
||||
def pay_invoice(*, wallet_id: str, bolt11: str, max_sat: Optional[int] = None) -> str:
|
||||
temp_id = f"temp_{urlsafe_short_hash()}"
|
||||
|
||||
try:
|
||||
invoice = bolt11_decode(bolt11)
|
||||
|
||||
@@ -34,7 +33,7 @@ def pay_invoice(*, wallet_id: str, bolt11: str, max_sat: Optional[int] = None) -
|
||||
if max_sat and invoice.amount_msat > max_sat * 1000:
|
||||
raise ValueError("Amount in invoice is too high.")
|
||||
|
||||
fee_reserve = max(1000, invoice.amount_msat * 0.01)
|
||||
fee_reserve = max(1000, int(invoice.amount_msat * 0.01))
|
||||
create_payment(
|
||||
wallet_id=wallet_id,
|
||||
checking_id=temp_id,
|
||||
@@ -43,7 +42,9 @@ def pay_invoice(*, wallet_id: str, bolt11: str, max_sat: Optional[int] = None) -
|
||||
memo=temp_id,
|
||||
)
|
||||
|
||||
if get_wallet(wallet_id).balance_msat < 0:
|
||||
wallet = get_wallet(wallet_id)
|
||||
assert wallet, "invalid wallet id"
|
||||
if wallet.balance_msat < 0:
|
||||
raise PermissionError("Insufficient balance.")
|
||||
|
||||
ok, checking_id, fee_msat, error_message = WALLET.pay_invoice(bolt11)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import requests
|
||||
|
||||
from flask import abort, redirect, request, url_for
|
||||
from lnurl import LnurlWithdrawResponse, handle as handle_lnurl
|
||||
from lnurl.exceptions import LnurlException
|
||||
from lnurl import LnurlWithdrawResponse, handle as handle_lnurl # type: ignore
|
||||
from lnurl.exceptions import LnurlException # type: ignore
|
||||
from time import sleep
|
||||
|
||||
from lnbits.core import core_app
|
||||
|
||||
Reference in New Issue
Block a user