From aa267f52a25bf068fd371adad73dc24c705740c5 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 28 Dec 2022 15:09:30 +0100 Subject: [PATCH 01/14] enable nix flake on {aarch64,x86_64}-darwin --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index af25ba5c3..d9f0f1f0c 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,7 @@ }; outputs = { self, nixpkgs, poetry2nix }@inputs: let - supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f system (import nixpkgs { inherit system; overlays = [ poetry2nix.overlay self.overlays.default ]; })); From a3773819425852a7f11b01998ff5eb5f2c222ceb Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 28 Dec 2022 12:36:39 +0100 Subject: [PATCH 02/14] use bytes.fromhex/hex builtins instead of binascii.hexlify/unhexlify --- lnbits/bolt11.py | 13 ++++++------- lnbits/core/services.py | 3 +-- lnbits/core/views/api.py | 9 +++------ lnbits/extensions/bleskomat/helpers.py | 3 +-- lnbits/extensions/boltz/boltz.py | 11 +++++------ lnbits/extensions/boltz/mempool.py | 3 +-- lnbits/extensions/cashu/crud.py | 1 - lnbits/extensions/lndhub/utils.py | 4 +--- lnbits/wallets/lndgrpc.py | 9 ++++----- tests/core/views/test_api.py | 1 - 10 files changed, 22 insertions(+), 35 deletions(-) diff --git a/lnbits/bolt11.py b/lnbits/bolt11.py index 32b43feb6..41b73b7d0 100644 --- a/lnbits/bolt11.py +++ b/lnbits/bolt11.py @@ -1,7 +1,6 @@ import hashlib import re import time -from binascii import unhexlify from decimal import Decimal from typing import List, NamedTuple, Optional @@ -108,7 +107,7 @@ def decode(pr: str) -> Invoice: message = bytearray([ord(c) for c in hrp]) + data.tobytes() sig = signature[0:64] if invoice.payee: - key = VerifyingKey.from_string(unhexlify(invoice.payee), curve=SECP256k1) + key = VerifyingKey.from_string(bytes.fromhex(invoice.payee), curve=SECP256k1) key.verify(sig, message, hashlib.sha256, sigdecode=sigdecode_string) else: keys = VerifyingKey.from_public_key_recovery( @@ -131,7 +130,7 @@ def encode(options): if options["timestamp"]: addr.date = int(options["timestamp"]) - addr.paymenthash = unhexlify(options["paymenthash"]) + addr.paymenthash = bytes.fromhex(options["paymenthash"]) if options["description"]: addr.tags.append(("d", options["description"])) @@ -149,8 +148,8 @@ def encode(options): while len(splits) >= 5: route.append( ( - unhexlify(splits[0]), - unhexlify(splits[1]), + bytes.fromhex(splits[0]), + bytes.fromhex(splits[1]), int(splits[2]), int(splits[3]), int(splits[4]), @@ -235,7 +234,7 @@ def lnencode(addr, privkey): raise ValueError("Must include either 'd' or 'h'") # We actually sign the hrp, then data (padded to 8 bits with zeroes). - privkey = secp256k1.PrivateKey(bytes(unhexlify(privkey))) + privkey = secp256k1.PrivateKey(bytes.fromhex(privkey)) sig = privkey.ecdsa_sign_recoverable( bytearray([ord(c) for c in hrp]) + data.tobytes() ) @@ -261,7 +260,7 @@ class LnAddr(object): def __str__(self): return "LnAddr[{}, amount={}{} tags=[{}]]".format( - hexlify(self.pubkey.serialize()).decode("utf-8"), + bytes.hex(self.pubkey.serialize()).decode("utf-8"), self.amount, self.currency, ", ".join([k + "=" + str(v) for k, v in self.tags]), diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 336d26651..bb389a73f 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -1,6 +1,5 @@ import asyncio import json -from binascii import unhexlify from io import BytesIO from typing import Dict, List, Optional, Tuple from urllib.parse import parse_qs, urlparse @@ -308,7 +307,7 @@ async def perform_lnurlauth( ) -> Optional[LnurlErrorResponse]: cb = urlparse(callback) - k1 = unhexlify(parse_qs(cb.query)["k1"][0]) + k1 = bytes.fromhex(parse_qs(cb.query)["k1"][0]) key = wallet.wallet.lnurlauth_key(cb.netloc) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 85bc394f7..c1778f806 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -1,5 +1,4 @@ import asyncio -import binascii import hashlib import json import time @@ -145,16 +144,14 @@ async def api_payments_create_invoice(data: CreateInvoiceData, wallet: Wallet): if data.description_hash or data.unhashed_description: try: description_hash = ( - binascii.unhexlify(data.description_hash) - if data.description_hash - else b"" + bytes.fromhex(data.description_hash) if data.description_hash else b"" ) unhashed_description = ( - binascii.unhexlify(data.unhashed_description) + bytes.fromhex(data.unhashed_description) if data.unhashed_description else b"" ) - except binascii.Error: + except ValueError: raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, detail="'description_hash' and 'unhashed_description' must be a valid hex strings", diff --git a/lnbits/extensions/bleskomat/helpers.py b/lnbits/extensions/bleskomat/helpers.py index 6e55b3df1..cec7434db 100644 --- a/lnbits/extensions/bleskomat/helpers.py +++ b/lnbits/extensions/bleskomat/helpers.py @@ -2,7 +2,6 @@ import base64 import hashlib import hmac import urllib -from binascii import unhexlify from http import HTTPStatus from typing import Dict @@ -19,7 +18,7 @@ def generate_bleskomat_lnurl_signature( payload: str, api_key_secret: str, api_key_encoding: str = "hex" ): if api_key_encoding == "hex": - key = unhexlify(api_key_secret) + key = bytes.fromhex(api_key_secret) elif api_key_encoding == "base64": key = base64.b64decode(api_key_secret) else: diff --git a/lnbits/extensions/boltz/boltz.py b/lnbits/extensions/boltz/boltz.py index 424d0bf78..97ccb3adb 100644 --- a/lnbits/extensions/boltz/boltz.py +++ b/lnbits/extensions/boltz/boltz.py @@ -1,6 +1,5 @@ import asyncio import os -from binascii import hexlify, unhexlify from hashlib import sha256 from typing import Awaitable, Union @@ -56,7 +55,7 @@ async def create_swap(data: CreateSubmarineSwap) -> SubmarineSwap: raise refund_privkey = ec.PrivateKey(os.urandom(32), True, net) - refund_pubkey_hex = hexlify(refund_privkey.sec()).decode("UTF-8") + refund_pubkey_hex = bytes.hex(refund_privkey.sec()).decode("UTF-8") res = req_wrap( "post", @@ -121,7 +120,7 @@ async def create_reverse_swap( return False claim_privkey = ec.PrivateKey(os.urandom(32), True, net) - claim_pubkey_hex = hexlify(claim_privkey.sec()).decode("UTF-8") + claim_pubkey_hex = bytes.hex(claim_privkey.sec()).decode("UTF-8") preimage = os.urandom(32) preimage_hash = sha256(preimage).hexdigest() @@ -311,12 +310,12 @@ async def create_onchain_tx( sequence = 0xFFFFFFFE else: privkey = ec.PrivateKey.from_wif(swap.claim_privkey) - preimage = unhexlify(swap.preimage) + preimage = bytes.fromhex(swap.preimage) onchain_address = swap.onchain_address sequence = 0xFFFFFFFF locktime = swap.timeout_block_height - redeem_script = unhexlify(swap.redeem_script) + redeem_script = bytes.fromhex(swap.redeem_script) fees = get_fee_estimation() @@ -324,7 +323,7 @@ async def create_onchain_tx( script_pubkey = script.address_to_scriptpubkey(onchain_address) - vin = [TransactionInput(unhexlify(txid), vout_cnt, sequence=sequence)] + vin = [TransactionInput(bytes.fromhex(txid), vout_cnt, sequence=sequence)] vout = [TransactionOutput(vout_amount - fees, script_pubkey)] tx = Transaction(vin=vin, vout=vout) diff --git a/lnbits/extensions/boltz/mempool.py b/lnbits/extensions/boltz/mempool.py index a64cadad0..c7d572a91 100644 --- a/lnbits/extensions/boltz/mempool.py +++ b/lnbits/extensions/boltz/mempool.py @@ -1,6 +1,5 @@ import asyncio import json -from binascii import hexlify import httpx import websockets @@ -84,7 +83,7 @@ def get_mempool_blockheight() -> int: async def send_onchain_tx(tx: Transaction): - raw = hexlify(tx.serialize()) + raw = bytes.hex(tx.serialize()) logger.debug(f"Boltz - mempool sending onchain tx...") req_wrap( "post", diff --git a/lnbits/extensions/cashu/crud.py b/lnbits/extensions/cashu/crud.py index 773a11fde..23f808c11 100644 --- a/lnbits/extensions/cashu/crud.py +++ b/lnbits/extensions/cashu/crud.py @@ -1,7 +1,6 @@ import os import random import time -from binascii import hexlify, unhexlify from typing import Any, List, Optional, Union from cashu.core.base import MintKeyset diff --git a/lnbits/extensions/lndhub/utils.py b/lnbits/extensions/lndhub/utils.py index 3db6317a7..008650801 100644 --- a/lnbits/extensions/lndhub/utils.py +++ b/lnbits/extensions/lndhub/utils.py @@ -1,10 +1,8 @@ -from binascii import unhexlify - from lnbits.bolt11 import Invoice def to_buffer(payment_hash: str): - return {"type": "Buffer", "data": [b for b in unhexlify(payment_hash)]} + return {"type": "Buffer", "data": [b for b in bytes.fromhex(payment_hash)]} def decoded_as_lndhub(invoice: Invoice): diff --git a/lnbits/wallets/lndgrpc.py b/lnbits/wallets/lndgrpc.py index 914337ba6..6a1967759 100644 --- a/lnbits/wallets/lndgrpc.py +++ b/lnbits/wallets/lndgrpc.py @@ -8,7 +8,6 @@ except ImportError: # pragma: nocover import asyncio import base64 -import binascii import hashlib from os import environ, error from typing import AsyncGenerator, Dict, Optional @@ -229,8 +228,8 @@ class LndWallet(Wallet): try: r_hash = hex_to_bytes(checking_id) if len(r_hash) != 32: - raise binascii.Error - except binascii.Error: + raise ValueError + except ValueError: # this may happen if we switch between backend wallets # that use different checking_id formats return PaymentStatus(None) @@ -250,8 +249,8 @@ class LndWallet(Wallet): try: r_hash = hex_to_bytes(checking_id) if len(r_hash) != 32: - raise binascii.Error - except binascii.Error: + raise ValueError + except ValueError: # this may happen if we switch between backend wallets # that use different checking_id formats return PaymentStatus(None) diff --git a/tests/core/views/test_api.py b/tests/core/views/test_api.py index d1f101cad..fe41fd4e5 100644 --- a/tests/core/views/test_api.py +++ b/tests/core/views/test_api.py @@ -1,5 +1,4 @@ import hashlib -from binascii import hexlify import pytest import pytest_asyncio From e01683b387c9573be97e930bcd4860d5d60caca9 Mon Sep 17 00:00:00 2001 From: Gene Takavic <80261724+iWarpBTC@users.noreply.github.com> Date: Thu, 29 Dec 2022 21:50:53 +0100 Subject: [PATCH 03/14] Revert "Update BoltCard Extension README" --- lnbits/extensions/boltcards/README.md | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lnbits/extensions/boltcards/README.md b/lnbits/extensions/boltcards/README.md index 10740cf82..34a1c05c0 100644 --- a/lnbits/extensions/boltcards/README.md +++ b/lnbits/extensions/boltcards/README.md @@ -42,23 +42,18 @@ Updated for v0.1.3 - Or you can Click the "KEYS / AUTH LINK" button to copy the auth URL to the clipboard. Then paste it into the Android app (Create Bolt Card -> PASTE AUTH URL). - Click WRITE CARD NOW and approach the NFC card to set it up. DO NOT REMOVE THE CARD PREMATURELY! -## Rewriting / Erasing the card - Boltcard NFC Card Creator +## Erasing the card - Boltcard NFC Card Creator +Updated for v0.1.3 -It is possible not only to reset the keys but also to disable the SUN function and completely erase the card so it can be used again as a static tag or set up as a new Bolt Card. - -IMPORTANT: -* It is immanent that you have access to your old keys so do not erase this card in LNbits before you copied those strings! -* If you tried to write to them and failed you will need the same amount of positive writing sessions to unlock the card. - -- in the BoltCard-Extension click the QR code button next to your old card and copy Key0 -- in the BoltApp click Advanced - Reset keys and paste the Key0 into the first field named Key0 -- repeat with Key1/Key2/Key3/Key0 -- when done pasting all 4 keys scan your card with the BoltApp -- Thats it 🥳 -- If everything was successful the card can be safely deleted from LNbits (but keep the keys backed up anyway; batter safe than brick). - -You can watch a video of this process here https://www.youtube.com/watch?time_continue=230&v=Pe0YXHawHvQ&feature=emb_logo +Since v0.1.2 of Boltcard NFC Card Creator it is possible not only reset the keys but also disable the SUN function and do the complete erase so the card can be use again as a static tag (or set as a new Bolt Card, ofc). +- Click the QR code button next to a card to view its details and select WIPE +- OR click the red cross icon on the right side to reach the same +- In the android app (Advanced -> Reset Keys) + - Click SCAN QR CODE to scan the QR + - Or click WIPE DATA in LNbits to copy and paste in to the app (PASTE KEY JSON) +- Click RESET CARD NOW and approach the NFC card to erase it. DO NOT REMOVE THE CARD PREMATURELY! +- Now if there is all success the card can be safely delete from LNbits (but keep the keys backuped anyway; batter safe than brick). ## Setting the card - computer (hard way) From 0cc6c0db79f53c53ecabfab9bd728dd69c3a662c Mon Sep 17 00:00:00 2001 From: Gene Takavic <80261724+iWarpBTC@users.noreply.github.com> Date: Thu, 29 Dec 2022 22:03:46 +0100 Subject: [PATCH 04/14] Update README.md note on non-standard states --- lnbits/extensions/boltcards/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lnbits/extensions/boltcards/README.md b/lnbits/extensions/boltcards/README.md index 34a1c05c0..4afa83779 100644 --- a/lnbits/extensions/boltcards/README.md +++ b/lnbits/extensions/boltcards/README.md @@ -55,6 +55,8 @@ Since v0.1.2 of Boltcard NFC Card Creator it is possible not only reset the keys - Click RESET CARD NOW and approach the NFC card to erase it. DO NOT REMOVE THE CARD PREMATURELY! - Now if there is all success the card can be safely delete from LNbits (but keep the keys backuped anyway; batter safe than brick). +If you somehow find yourself in some non-standard state (for instance only k3 and k4 remains filled after previous unsuccessful reset), then you need edit the key fields manually (for instance leave k0-k2 to zeroes and provide the right k3 and k4). + ## Setting the card - computer (hard way) Follow the guide. From 2f377343f102cafcd5bbf602c7f7ce4e168f75a1 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 30 Dec 2022 00:09:14 +0100 Subject: [PATCH 05/14] extensions/gerty: remove duplicit functions probably merge error --- lnbits/extensions/gerty/helpers.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 24b22b5d3..65c690730 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -301,34 +301,6 @@ def gerty_should_sleep(utc_offset: int = 0): return False -def get_date_suffix(dayNumber): - if 4 <= dayNumber <= 20 or 24 <= dayNumber <= 30: - return "th" - else: - return ["st", "nd", "rd"][dayNumber % 10 - 1] - - -def get_time_remaining(seconds, granularity=2): - intervals = ( - # ('weeks', 604800), # 60 * 60 * 24 * 7 - ("days", 86400), # 60 * 60 * 24 - ("hours", 3600), # 60 * 60 - ("minutes", 60), - ("seconds", 1), - ) - - result = [] - - for name, count in intervals: - value = seconds // count - if value: - seconds -= value * count - if value == 1: - name = name.rstrip("s") - result.append("{} {}".format(round(value), name)) - return ", ".join(result[:granularity]) - - async def get_mining_stat(stat_slug: str, gerty): text = [] if stat_slug == "mining_current_hash_rate": From 4b388475ced32ab0f84e7889d6b6e123f3960931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Dec 2022 08:48:31 +0100 Subject: [PATCH 06/14] fix tipjar mypy issues --- lnbits/extensions/tipjar/crud.py | 17 +++------- lnbits/extensions/tipjar/models.py | 17 ++-------- lnbits/extensions/tipjar/views.py | 3 +- lnbits/extensions/tipjar/views_api.py | 48 +++++++++++++++------------ pyproject.toml | 1 - 5 files changed, 34 insertions(+), 52 deletions(-) diff --git a/lnbits/extensions/tipjar/crud.py b/lnbits/extensions/tipjar/crud.py index 046b94911..ff9220b1e 100644 --- a/lnbits/extensions/tipjar/crud.py +++ b/lnbits/extensions/tipjar/crud.py @@ -8,7 +8,7 @@ from .models import Tip, TipJar, createTipJar async def create_tip( - id: int, wallet: str, message: str, name: str, sats: int, tipjar: str + id: str, wallet: str, message: str, name: str, sats: int, tipjar: str ) -> Tip: """Create a new Tip""" await db.execute( @@ -33,11 +33,7 @@ async def create_tip( async def create_tipjar(data: createTipJar) -> TipJar: """Create a new TipJar""" - - returning = "" if db.type == SQLITE else "RETURNING ID" - method = db.execute if db.type == SQLITE else db.fetchone - - result = await (method)( + await db.execute( f""" INSERT INTO tipjar.TipJars ( name, @@ -46,16 +42,11 @@ async def create_tipjar(data: createTipJar) -> TipJar: onchain ) VALUES (?, ?, ?, ?) - {returning} """, (data.name, data.wallet, data.webhook, data.onchain), ) - if db.type == SQLITE: - tipjar_id = result._result_proxy.lastrowid - else: - tipjar_id = result[0] - - tipjar = await get_tipjar(tipjar_id) + row = await db.fetchone( "SELECT * FROM tipjar.TipJars LIMIT 1") + tipjar = TipJar(**row) assert tipjar return tipjar diff --git a/lnbits/extensions/tipjar/models.py b/lnbits/extensions/tipjar/models.py index 92f25ab3a..655888da6 100644 --- a/lnbits/extensions/tipjar/models.py +++ b/lnbits/extensions/tipjar/models.py @@ -1,20 +1,7 @@ from sqlite3 import Row from typing import Optional -from fastapi.param_functions import Query from pydantic import BaseModel -from pydantic.main import BaseModel - - -class CreateCharge(BaseModel): - onchainwallet: str = Query(None) - lnbitswallet: str = Query(None) - description: str = Query(...) - webhook: str = Query(None) - completelink: str = Query(None) - completelinktext: str = Query(None) - time: int = Query(..., ge=1) - amount: int = Query(..., ge=1) class createTip(BaseModel): @@ -44,8 +31,8 @@ class Tip(BaseModel): class createTipJar(BaseModel): name: str wallet: str - webhook: str = None - onchain: str = None + webhook: Optional[str] + onchain: Optional[str] class createTips(BaseModel): diff --git a/lnbits/extensions/tipjar/views.py b/lnbits/extensions/tipjar/views.py index 21a872469..21da0d2e4 100644 --- a/lnbits/extensions/tipjar/views.py +++ b/lnbits/extensions/tipjar/views.py @@ -1,8 +1,7 @@ from http import HTTPStatus -from fastapi import Request +from fastapi import Request, Depends from fastapi.param_functions import Query -from fastapi.params import Depends from fastapi.templating import Jinja2Templates from starlette.exceptions import HTTPException diff --git a/lnbits/extensions/tipjar/views_api.py b/lnbits/extensions/tipjar/views_api.py index 50c5138b0..bbc824e83 100644 --- a/lnbits/extensions/tipjar/views_api.py +++ b/lnbits/extensions/tipjar/views_api.py @@ -1,13 +1,13 @@ from http import HTTPStatus -from fastapi.param_functions import Query -from fastapi.params import Depends +from fastapi import Depends, Query from starlette.exceptions import HTTPException from lnbits.core.crud import get_user from lnbits.decorators import WalletTypeInfo, get_key_type from ..satspay.crud import create_charge +from ..satspay.models import CreateCharge from . import tipjar_ext from .crud import ( create_tip, @@ -22,7 +22,7 @@ from .crud import ( update_tipjar, ) from .helpers import get_charge_details -from .models import CreateCharge, createTipJar, createTips +from .models import createTipJar, createTip, createTips @tipjar_ext.post("/api/v1/tipjars") @@ -43,12 +43,16 @@ async def user_from_wallet(wallet: WalletTypeInfo = Depends(get_key_type)): @tipjar_ext.post("/api/v1/tips") async def api_create_tip(data: createTips): """Take data from tip form and return satspay charge""" - sats = data.sats + sats = int(data.sats) message = data.message if not message: message = "No message" - tipjar_id = data.tipjar + tipjar_id = int(data.tipjar) tipjar = await get_tipjar(tipjar_id) + if not tipjar: + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Tipjar does not exist." + ) webhook = tipjar.webhook charge_details = await get_charge_details(tipjar.id) @@ -62,13 +66,14 @@ async def api_create_tip(data: createTips): user=charge_details["user"], data=CreateCharge( amount=sats, - webhook=webhook, + webhook=webhook or "", description=description, onchainwallet=charge_details["onchainwallet"], lnbitswallet=charge_details["lnbitswallet"], completelink=charge_details["completelink"], completelinktext=charge_details["completelinktext"], time=charge_details["time"], + custom_css="", ), ) @@ -77,7 +82,7 @@ async def api_create_tip(data: createTips): wallet=tipjar.wallet, message=message, name=name, - sats=data.sats, + sats=int(data.sats), tipjar=data.tipjar, ) @@ -87,29 +92,31 @@ async def api_create_tip(data: createTips): @tipjar_ext.get("/api/v1/tipjars") async def api_get_tipjars(wallet: WalletTypeInfo = Depends(get_key_type)): """Return list of all tipjars assigned to wallet with given invoice key""" - wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids + user = await get_user(wallet.wallet.user) + if not user: + return [] tipjars = [] - for wallet_id in wallet_ids: + for wallet_id in user.wallet_ids: new_tipjars = await get_tipjars(wallet_id) tipjars += new_tipjars if new_tipjars else [] - return [tipjar.dict() for tipjar in tipjars] if tipjars else [] + return [tipjar.dict() for tipjar in tipjars] @tipjar_ext.get("/api/v1/tips") async def api_get_tips(wallet: WalletTypeInfo = Depends(get_key_type)): """Return list of all tips assigned to wallet with given invoice key""" - wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids + user = await get_user(wallet.wallet.user) + if not user: + return [] tips = [] - for wallet_id in wallet_ids: + for wallet_id in user.wallet_ids: new_tips = await get_tips(wallet_id) tips += new_tips if new_tips else [] - return [tip.dict() for tip in tips] if tips else [] + return [tip.dict() for tip in tips] @tipjar_ext.put("/api/v1/tips/{tip_id}") -async def api_update_tip( - wallet: WalletTypeInfo = Depends(get_key_type), tip_id: str = Query(None) -): +async def api_update_tip(data: createTip, wallet: WalletTypeInfo = Depends(get_key_type), tip_id: str = Query(None)): """Update a tip with the data given in the request""" if tip_id: tip = await get_tip(tip_id) @@ -125,7 +132,7 @@ async def api_update_tip( status_code=HTTPStatus.FORBIDDEN, detail="Not your tip." ) - tip = await update_tip(tip_id, **g.data) + tip = await update_tip(tip_id, **data.dict()) else: raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, detail="No tip ID specified" @@ -134,8 +141,7 @@ async def api_update_tip( @tipjar_ext.put("/api/v1/tipjars/{tipjar_id}") -async def api_update_tipjar( - wallet: WalletTypeInfo = Depends(get_key_type), tipjar_id: str = Query(None) +async def api_update_tipjar(data: createTipJar, wallet: WalletTypeInfo = Depends(get_key_type), tipjar_id: int = Query(None) ): """Update a tipjar with the data given in the request""" if tipjar_id: @@ -151,7 +157,7 @@ async def api_update_tipjar( status_code=HTTPStatus.FORBIDDEN, detail="Not your tipjar." ) - tipjar = await update_tipjar(tipjar_id, **data) + tipjar = await update_tipjar(str(tipjar_id), **data.dict()) else: raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, detail="No tipjar ID specified" @@ -181,7 +187,7 @@ async def api_delete_tip( @tipjar_ext.delete("/api/v1/tipjars/{tipjar_id}") async def api_delete_tipjar( - wallet: WalletTypeInfo = Depends(get_key_type), tipjar_id: str = Query(None) + wallet: WalletTypeInfo = Depends(get_key_type), tipjar_id: int = Query(None) ): """Delete the tipjar with the given tipjar_id""" tipjar = await get_tipjar(tipjar_id) diff --git a/pyproject.toml b/pyproject.toml index 573eef1be..0e660abec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,7 +110,6 @@ exclude = """(?x)( | ^lnbits/extensions/scrub. | ^lnbits/extensions/splitpayments. | ^lnbits/extensions/streamalerts. - | ^lnbits/extensions/tipjar. | ^lnbits/extensions/tpos. | ^lnbits/extensions/watchonly. | ^lnbits/extensions/withdraw. From bf69e91caed42131da3f9c40f43cf4c06b0dc38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Dec 2022 09:46:45 +0100 Subject: [PATCH 07/14] fix mypy for nostrnip5 ext --- lnbits/extensions/nostrnip5/crud.py | 4 +- lnbits/extensions/nostrnip5/tasks.py | 19 ++++----- lnbits/extensions/nostrnip5/views.py | 7 ++-- lnbits/extensions/nostrnip5/views_api.py | 50 +++++++++++++++--------- pyproject.toml | 1 - 5 files changed, 47 insertions(+), 34 deletions(-) diff --git a/lnbits/extensions/nostrnip5/crud.py b/lnbits/extensions/nostrnip5/crud.py index b445e9912..12adc05a6 100644 --- a/lnbits/extensions/nostrnip5/crud.py +++ b/lnbits/extensions/nostrnip5/crud.py @@ -71,7 +71,7 @@ async def get_all_addresses(wallet_ids: Union[str, List[str]]) -> List[Address]: q = ",".join(["?"] * len(wallet_ids)) rows = await db.fetchall( f""" - SELECT a.* + SELECT a.* FROM nostrnip5.addresses a JOIN nostrnip5.domains d ON d.id = a.domain_id WHERE d.wallet IN ({q}) @@ -139,7 +139,7 @@ async def delete_domain(domain_id) -> bool: return True -async def delete_address(address_id) -> bool: +async def delete_address(address_id): await db.execute( """ DELETE FROM nostrnip5.addresses WHERE id = ? diff --git a/lnbits/extensions/nostrnip5/tasks.py b/lnbits/extensions/nostrnip5/tasks.py index 3cedc9f5b..30e8cec61 100644 --- a/lnbits/extensions/nostrnip5/tasks.py +++ b/lnbits/extensions/nostrnip5/tasks.py @@ -1,9 +1,9 @@ import asyncio -import json + +from loguru import logger from lnbits.core.models import Payment -from lnbits.helpers import urlsafe_short_hash -from lnbits.tasks import internal_invoice_queue, register_invoice_listener +from lnbits.tasks import register_invoice_listener from .crud import activate_address @@ -18,17 +18,18 @@ async def wait_for_paid_invoices(): async def on_invoice_paid(payment: Payment) -> None: + if not payment.extra: + return if payment.extra.get("tag") != "nostrnip5": - # not relevant return domain_id = payment.extra.get("domain_id") address_id = payment.extra.get("address_id") - print("Activating NOSTR NIP-05") - print(domain_id) - print(address_id) - - active = await activate_address(domain_id, address_id) + if domain_id and address_id: + logger.info("Activating NOSTR NIP-05") + logger.info(domain_id) + logger.info(address_id) + await activate_address(domain_id, address_id) return diff --git a/lnbits/extensions/nostrnip5/views.py b/lnbits/extensions/nostrnip5/views.py index 8e49a9f53..fc897d5da 100644 --- a/lnbits/extensions/nostrnip5/views.py +++ b/lnbits/extensions/nostrnip5/views.py @@ -1,8 +1,7 @@ from datetime import datetime from http import HTTPStatus -from fastapi import FastAPI, Request -from fastapi.params import Depends +from fastapi import Depends, Request from fastapi.templating import Jinja2Templates from starlette.exceptions import HTTPException from starlette.responses import HTMLResponse @@ -24,7 +23,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)): @nostrnip5_ext.get("/signup/{domain_id}", response_class=HTMLResponse) -async def index(request: Request, domain_id: str): +async def signup(request: Request, domain_id: str): domain = await get_domain(domain_id) if not domain: @@ -43,7 +42,7 @@ async def index(request: Request, domain_id: str): @nostrnip5_ext.get("/rotate/{domain_id}/{address_id}", response_class=HTMLResponse) -async def index(request: Request, domain_id: str, address_id: str): +async def rotate(request: Request, domain_id: str, address_id: str): domain = await get_domain(domain_id) address = await get_address(domain_id, address_id) diff --git a/lnbits/extensions/nostrnip5/views_api.py b/lnbits/extensions/nostrnip5/views_api.py index bc4f72c7c..704a98c4b 100644 --- a/lnbits/extensions/nostrnip5/views_api.py +++ b/lnbits/extensions/nostrnip5/views_api.py @@ -1,10 +1,8 @@ import re from http import HTTPStatus -from typing import Optional from bech32 import bech32_decode, convertbits -from fastapi import Query, Request, Response -from fastapi.params import Depends +from fastapi import Depends, Query, Response from loguru import logger from starlette.exceptions import HTTPException @@ -38,7 +36,10 @@ async def api_domains( ): wallet_ids = [wallet.wallet.id] if all_wallets: - wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids + user = await get_user(wallet.wallet.user) + if not user: + return [] + wallet_ids = user.wallet_ids return [domain.dict() for domain in await get_domains(wallet_ids)] @@ -49,13 +50,20 @@ async def api_addresses( ): wallet_ids = [wallet.wallet.id] if all_wallets: - wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids + user = await get_user(wallet.wallet.user) + if not user: + return [] + wallet_ids = user.wallet_ids return [address.dict() for address in await get_all_addresses(wallet_ids)] -@nostrnip5_ext.get("/api/v1/domain/{domain_id}", status_code=HTTPStatus.OK) -async def api_invoice(domain_id: str, wallet: WalletTypeInfo = Depends(get_key_type)): +@nostrnip5_ext.get( + "/api/v1/domain/{domain_id}", + status_code=HTTPStatus.OK, + dependencies=[Depends(get_key_type)], +) +async def api_invoice(domain_id: str): domain = await get_domain(domain_id) if not domain: raise HTTPException( @@ -104,11 +112,11 @@ async def api_address_delete( @nostrnip5_ext.post( "/api/v1/domain/{domain_id}/address/{address_id}/activate", status_code=HTTPStatus.OK, + dependencies=[Depends(require_admin_key)], ) async def api_address_activate( domain_id: str, address_id: str, - wallet: WalletTypeInfo = Depends(require_admin_key), ): await activate_address(domain_id, address_id) @@ -126,9 +134,11 @@ async def api_address_rotate( ): if post_data.pubkey.startswith("npub"): - hrp, data = bech32_decode(post_data.pubkey) - decoded_data = convertbits(data, 5, 8, False) - post_data.pubkey = bytes(decoded_data).hex() + _, data = bech32_decode(post_data.pubkey) + if data: + decoded_data = convertbits(data, 5, 8, False) + if decoded_data: + post_data.pubkey = bytes(decoded_data).hex() if len(bytes.fromhex(post_data.pubkey)) != 32: raise HTTPException( @@ -173,10 +183,12 @@ async def api_address_create( status_code=HTTPStatus.NOT_FOUND, detail="Local part already exists." ) - if post_data.pubkey.startswith("npub"): - hrp, data = bech32_decode(post_data.pubkey) - decoded_data = convertbits(data, 5, 8, False) - post_data.pubkey = bytes(decoded_data).hex() + if post_data and post_data.pubkey.startswith("npub"): + _, data = bech32_decode(post_data.pubkey) + if data: + decoded_data = convertbits(data, 5, 8, False) + if decoded_data: + post_data.pubkey = bytes(decoded_data).hex() if len(bytes.fromhex(post_data.pubkey)) != 32: raise HTTPException( @@ -233,15 +245,17 @@ async def api_get_nostr_json( output = {} for address in addresses: - local_part = address.get("local_part").lower() + local_part = address.get("local_part") + if not local_part: + continue if address.get("active") == False: continue - if name and name.lower() != local_part: + if name and name.lower() != local_part.lower(): continue - output[local_part] = address.get("pubkey") + output[local_part.lower()] = address.get("pubkey") response.headers["Access-Control-Allow-Origin"] = "*" response.headers["Access-Control-Allow-Methods"] = "GET,OPTIONS" diff --git a/pyproject.toml b/pyproject.toml index 573eef1be..96a066e53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,6 @@ exclude = """(?x)( | ^lnbits/extensions/lnurldevice. | ^lnbits/extensions/lnurlp. | ^lnbits/extensions/lnurlpayout. - | ^lnbits/extensions/nostrnip5. | ^lnbits/extensions/offlineshop. | ^lnbits/extensions/paywall. | ^lnbits/extensions/satspay. From bb8e86addf6e1011a5a3b90031f992215287eb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Dec 2022 09:48:52 +0100 Subject: [PATCH 08/14] formatting --- lnbits/extensions/tipjar/crud.py | 2 +- lnbits/extensions/tipjar/views.py | 2 +- lnbits/extensions/tipjar/views_api.py | 13 ++++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lnbits/extensions/tipjar/crud.py b/lnbits/extensions/tipjar/crud.py index ff9220b1e..1b58a43d7 100644 --- a/lnbits/extensions/tipjar/crud.py +++ b/lnbits/extensions/tipjar/crud.py @@ -45,7 +45,7 @@ async def create_tipjar(data: createTipJar) -> TipJar: """, (data.name, data.wallet, data.webhook, data.onchain), ) - row = await db.fetchone( "SELECT * FROM tipjar.TipJars LIMIT 1") + row = await db.fetchone("SELECT * FROM tipjar.TipJars LIMIT 1") tipjar = TipJar(**row) assert tipjar return tipjar diff --git a/lnbits/extensions/tipjar/views.py b/lnbits/extensions/tipjar/views.py index 21da0d2e4..56f718e21 100644 --- a/lnbits/extensions/tipjar/views.py +++ b/lnbits/extensions/tipjar/views.py @@ -1,6 +1,6 @@ from http import HTTPStatus -from fastapi import Request, Depends +from fastapi import Depends, Request from fastapi.param_functions import Query from fastapi.templating import Jinja2Templates from starlette.exceptions import HTTPException diff --git a/lnbits/extensions/tipjar/views_api.py b/lnbits/extensions/tipjar/views_api.py index bbc824e83..d0c7ac7d7 100644 --- a/lnbits/extensions/tipjar/views_api.py +++ b/lnbits/extensions/tipjar/views_api.py @@ -22,7 +22,7 @@ from .crud import ( update_tipjar, ) from .helpers import get_charge_details -from .models import createTipJar, createTip, createTips +from .models import createTip, createTipJar, createTips @tipjar_ext.post("/api/v1/tipjars") @@ -116,7 +116,11 @@ async def api_get_tips(wallet: WalletTypeInfo = Depends(get_key_type)): @tipjar_ext.put("/api/v1/tips/{tip_id}") -async def api_update_tip(data: createTip, wallet: WalletTypeInfo = Depends(get_key_type), tip_id: str = Query(None)): +async def api_update_tip( + data: createTip, + wallet: WalletTypeInfo = Depends(get_key_type), + tip_id: str = Query(None), +): """Update a tip with the data given in the request""" if tip_id: tip = await get_tip(tip_id) @@ -141,7 +145,10 @@ async def api_update_tip(data: createTip, wallet: WalletTypeInfo = Depends(get_k @tipjar_ext.put("/api/v1/tipjars/{tipjar_id}") -async def api_update_tipjar(data: createTipJar, wallet: WalletTypeInfo = Depends(get_key_type), tipjar_id: int = Query(None) +async def api_update_tipjar( + data: createTipJar, + wallet: WalletTypeInfo = Depends(get_key_type), + tipjar_id: int = Query(None), ): """Update a tipjar with the data given in the request""" if tipjar_id: From f7a977ecc8ace7b7d96db988db61a3d7d0c3c260 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 30 Dec 2022 00:12:46 +0100 Subject: [PATCH 09/14] let's use unique function names so mypy is not confused --- lnbits/extensions/boltcards/views_api.py | 2 +- lnbits/extensions/invoices/views.py | 2 +- lnbits/extensions/nostrnip5/views.py | 4 ++-- lnbits/extensions/satspay/views_api.py | 2 +- lnbits/extensions/watchonly/views_api.py | 2 +- lnbits/extensions/withdraw/views.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lnbits/extensions/boltcards/views_api.py b/lnbits/extensions/boltcards/views_api.py index 80679556b..c18c33d05 100644 --- a/lnbits/extensions/boltcards/views_api.py +++ b/lnbits/extensions/boltcards/views_api.py @@ -147,7 +147,7 @@ async def api_hits( @boltcards_ext.get("/api/v1/refunds") -async def api_hits( +async def api_refunds( g: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False) ): wallet_ids = [g.wallet.id] diff --git a/lnbits/extensions/invoices/views.py b/lnbits/extensions/invoices/views.py index 08223df87..b492a67c6 100644 --- a/lnbits/extensions/invoices/views.py +++ b/lnbits/extensions/invoices/views.py @@ -30,7 +30,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)): @invoices_ext.get("/pay/{invoice_id}", response_class=HTMLResponse) -async def index(request: Request, invoice_id: str): +async def pay(request: Request, invoice_id: str): invoice = await get_invoice(invoice_id) if not invoice: diff --git a/lnbits/extensions/nostrnip5/views.py b/lnbits/extensions/nostrnip5/views.py index 8e49a9f53..faa22f8f5 100644 --- a/lnbits/extensions/nostrnip5/views.py +++ b/lnbits/extensions/nostrnip5/views.py @@ -24,7 +24,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)): @nostrnip5_ext.get("/signup/{domain_id}", response_class=HTMLResponse) -async def index(request: Request, domain_id: str): +async def signup(request: Request, domain_id: str): domain = await get_domain(domain_id) if not domain: @@ -43,7 +43,7 @@ async def index(request: Request, domain_id: str): @nostrnip5_ext.get("/rotate/{domain_id}/{address_id}", response_class=HTMLResponse) -async def index(request: Request, domain_id: str, address_id: str): +async def rotate(request: Request, domain_id: str, address_id: str): domain = await get_domain(domain_id) address = await get_address(domain_id, address_id) diff --git a/lnbits/extensions/satspay/views_api.py b/lnbits/extensions/satspay/views_api.py index 46dd73300..90a469293 100644 --- a/lnbits/extensions/satspay/views_api.py +++ b/lnbits/extensions/satspay/views_api.py @@ -171,7 +171,7 @@ async def api_themes_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)): @satspay_ext.delete("/api/v1/themes/{theme_id}") -async def api_charge_delete(theme_id, wallet: WalletTypeInfo = Depends(get_key_type)): +async def api_theme_delete(theme_id, wallet: WalletTypeInfo = Depends(get_key_type)): theme = await get_theme(theme_id) if not theme: diff --git a/lnbits/extensions/watchonly/views_api.py b/lnbits/extensions/watchonly/views_api.py index 97f731c3e..c6e15ea6f 100644 --- a/lnbits/extensions/watchonly/views_api.py +++ b/lnbits/extensions/watchonly/views_api.py @@ -292,7 +292,7 @@ async def api_psbt_create( @watchonly_ext.put("/api/v1/psbt/utxos") -async def api_psbt_extract_tx( +async def api_psbt_utxos_tx( req: Request, w: WalletTypeInfo = Depends(require_admin_key) ): """Extract previous unspent transaction outputs (tx_id, vout) from PSBT""" diff --git a/lnbits/extensions/withdraw/views.py b/lnbits/extensions/withdraw/views.py index 97fb12717..6d211ed48 100644 --- a/lnbits/extensions/withdraw/views.py +++ b/lnbits/extensions/withdraw/views.py @@ -117,7 +117,7 @@ async def print_qr(request: Request, link_id): @withdraw_ext.get("/csv/{link_id}", response_class=HTMLResponse) -async def print_qr(request: Request, link_id): +async def csv(request: Request, link_id): link = await get_withdraw_link(link_id) if not link: raise HTTPException( From aa97e3cb54fe3b4ec9af63b09ee05b5fb55ef219 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 30 Dec 2022 16:06:58 +0100 Subject: [PATCH 10/14] add -o to find opts meaning or (default is and) which returns no results --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4f99f1daa..ebf2a8729 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ format: prettier isort black check: mypy checkprettier checkisort checkblack -prettier: $(shell find lnbits -name "*.js" -name ".html") +prettier: $(shell find lnbits -name "*.js" -o -name ".html") ./node_modules/.bin/prettier --write lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js lnbits/extensions/*/static/components/*/*.js lnbits/extensions/*/static/components/*/*.html black: @@ -18,7 +18,7 @@ mypy: isort: poetry run isort . -checkprettier: $(shell find lnbits -name "*.js" -name ".html") +checkprettier: $(shell find lnbits -name "*.js" -o -name ".html") ./node_modules/.bin/prettier --check lnbits/static/js/*.js lnbits/core/static/js/*.js lnbits/extensions/*/templates/*/*.html ./lnbits/core/templates/core/*.html lnbits/templates/*.html lnbits/extensions/*/static/js/*.js lnbits/extensions/*/static/components/*/*.js lnbits/extensions/*/static/components/*/*.html checkblack: From 3824a108aa7563057270eee8e46a3ff57b981fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 2 Jan 2023 11:25:01 +0100 Subject: [PATCH 11/14] fix scrub for mypy --- lnbits/extensions/scrub/tasks.py | 6 +++--- lnbits/extensions/scrub/views.py | 3 +-- lnbits/extensions/scrub/views_api.py | 11 ++++------- pyproject.toml | 1 - 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lnbits/extensions/scrub/tasks.py b/lnbits/extensions/scrub/tasks.py index 852f3860c..096cbef95 100644 --- a/lnbits/extensions/scrub/tasks.py +++ b/lnbits/extensions/scrub/tasks.py @@ -25,9 +25,9 @@ async def wait_for_paid_invoices(): await on_invoice_paid(payment) -async def on_invoice_paid(payment: Payment) -> None: +async def on_invoice_paid(payment: Payment): # (avoid loops) - if payment.extra.get("tag") == "scrubed": + if payment.extra and payment.extra.get("tag") == "scrubed": # already scrubbed return @@ -53,7 +53,7 @@ async def on_invoice_paid(payment: Payment) -> None: timeout=40, ) if r.is_error: - raise httpx.ConnectError + raise httpx.ConnectError("issue with scrub callback") except (httpx.ConnectError, httpx.RequestError): raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, diff --git a/lnbits/extensions/scrub/views.py b/lnbits/extensions/scrub/views.py index 73c7ffd9d..509417e0d 100644 --- a/lnbits/extensions/scrub/views.py +++ b/lnbits/extensions/scrub/views.py @@ -1,5 +1,4 @@ -from fastapi import Request -from fastapi.params import Depends +from fastapi import Request, Depends from fastapi.templating import Jinja2Templates from starlette.responses import HTMLResponse diff --git a/lnbits/extensions/scrub/views_api.py b/lnbits/extensions/scrub/views_api.py index cc55c15d8..289a80d20 100644 --- a/lnbits/extensions/scrub/views_api.py +++ b/lnbits/extensions/scrub/views_api.py @@ -1,9 +1,6 @@ from http import HTTPStatus -from fastapi import Request -from fastapi.param_functions import Query -from fastapi.params import Depends -from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl # type: ignore +from fastapi import Query, Depends from starlette.exceptions import HTTPException from lnbits.core.crud import get_user @@ -23,14 +20,14 @@ from .models import CreateScrubLink @scrub_ext.get("/api/v1/links", status_code=HTTPStatus.OK) async def api_links( - req: Request, wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False), ): wallet_ids = [wallet.wallet.id] if all_wallets: - wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids + user = await get_user(wallet.wallet.user) + wallet_ids = user.wallet_ids if user else [] try: return [link.dict() for link in await get_scrub_links(wallet_ids)] @@ -44,7 +41,7 @@ async def api_links( @scrub_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK) async def api_link_retrieve( - r: Request, link_id, wallet: WalletTypeInfo = Depends(get_key_type) + link_id, wallet: WalletTypeInfo = Depends(get_key_type) ): link = await get_scrub_link(link_id) diff --git a/pyproject.toml b/pyproject.toml index 96a066e53..f207ea84e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,6 @@ exclude = """(?x)( | ^lnbits/extensions/offlineshop. | ^lnbits/extensions/paywall. | ^lnbits/extensions/satspay. - | ^lnbits/extensions/scrub. | ^lnbits/extensions/splitpayments. | ^lnbits/extensions/streamalerts. | ^lnbits/extensions/tipjar. From ff274e4eac4b84840019fd9f177ee6d9b96f97ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 2 Jan 2023 11:25:57 +0100 Subject: [PATCH 12/14] formatting --- lnbits/extensions/scrub/views.py | 2 +- lnbits/extensions/scrub/views_api.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lnbits/extensions/scrub/views.py b/lnbits/extensions/scrub/views.py index 509417e0d..489580133 100644 --- a/lnbits/extensions/scrub/views.py +++ b/lnbits/extensions/scrub/views.py @@ -1,4 +1,4 @@ -from fastapi import Request, Depends +from fastapi import Depends, Request from fastapi.templating import Jinja2Templates from starlette.responses import HTMLResponse diff --git a/lnbits/extensions/scrub/views_api.py b/lnbits/extensions/scrub/views_api.py index 289a80d20..eae0098d9 100644 --- a/lnbits/extensions/scrub/views_api.py +++ b/lnbits/extensions/scrub/views_api.py @@ -1,6 +1,6 @@ from http import HTTPStatus -from fastapi import Query, Depends +from fastapi import Depends, Query from starlette.exceptions import HTTPException from lnbits.core.crud import get_user @@ -40,9 +40,7 @@ async def api_links( @scrub_ext.get("/api/v1/links/{link_id}", status_code=HTTPStatus.OK) -async def api_link_retrieve( - link_id, wallet: WalletTypeInfo = Depends(get_key_type) -): +async def api_link_retrieve(link_id, wallet: WalletTypeInfo = Depends(get_key_type)): link = await get_scrub_link(link_id) if not link: From 2e572106232553a131931aa1ecde2511425715d6 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 30 Dec 2022 00:09:40 +0100 Subject: [PATCH 13/14] extensions/satspay: remove duplicit functions probably merge error --- lnbits/extensions/satspay/crud.py | 47 ------------------------------- 1 file changed, 47 deletions(-) diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py index 7cbcec5fd..784338387 100644 --- a/lnbits/extensions/satspay/crud.py +++ b/lnbits/extensions/satspay/crud.py @@ -131,53 +131,6 @@ async def check_address_balance(charge_id: str) -> Optional[Charges]: ################## SETTINGS ################### -async def save_theme(data: SatsPayThemes, css_id: str = None): - # insert or update - if css_id: - await db.execute( - """ - UPDATE satspay.themes SET custom_css = ?, title = ? WHERE css_id = ? - """, - (data.custom_css, data.title, css_id), - ) - else: - css_id = urlsafe_short_hash() - await db.execute( - """ - INSERT INTO satspay.themes ( - css_id, - title, - user, - custom_css - ) - VALUES (?, ?, ?, ?) - """, - ( - css_id, - data.title, - data.user, - data.custom_css, - ), - ) - return await get_theme(css_id) - - -async def get_theme(css_id: str) -> SatsPayThemes: - row = await db.fetchone("SELECT * FROM satspay.themes WHERE css_id = ?", (css_id,)) - return SatsPayThemes.from_row(row) if row else None - - -async def get_themes(user_id: str) -> List[SatsPayThemes]: - rows = await db.fetchall( - """SELECT * FROM satspay.themes WHERE "user" = ? ORDER BY "timestamp" DESC """, - (user_id,), - ) - return await get_config(row.user) - - -################## SETTINGS ################### - - async def save_theme(data: SatsPayThemes, css_id: str = None): # insert or update if css_id: From 15bb0f3924b6495b32e37ec9015a3f699f414ad3 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 3 Jan 2023 11:08:46 +0100 Subject: [PATCH 14/14] remove hivemind and lnurlpayout from mypy ignore list --- pyproject.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 96a066e53..db1828204 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,7 +94,6 @@ exclude = """(?x)( | ^lnbits/extensions/boltcards. | ^lnbits/extensions/events. | ^lnbits/extensions/gerty. - | ^lnbits/extensions/hivemind. | ^lnbits/extensions/invoices. | ^lnbits/extensions/livestream. | ^lnbits/extensions/lnaddress. @@ -102,7 +101,6 @@ exclude = """(?x)( | ^lnbits/extensions/lnticket. | ^lnbits/extensions/lnurldevice. | ^lnbits/extensions/lnurlp. - | ^lnbits/extensions/lnurlpayout. | ^lnbits/extensions/offlineshop. | ^lnbits/extensions/paywall. | ^lnbits/extensions/satspay.