From 886070755c10542a7543423fd6a432e6fa34e55a Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 23 Dec 2022 15:35:06 +0000 Subject: [PATCH 1/6] hacky lnurlpos bump --- lnbits/extensions/lnurldevice/crud.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lnbits/extensions/lnurldevice/crud.py b/lnbits/extensions/lnurldevice/crud.py index e02d23b8..b1fe24aa 100644 --- a/lnbits/extensions/lnurldevice/crud.py +++ b/lnbits/extensions/lnurldevice/crud.py @@ -11,7 +11,8 @@ from .models import createLnurldevice, lnurldevicepayment, lnurldevices async def create_lnurldevice( data: createLnurldevice, ) -> lnurldevices: - lnurldevice_id = urlsafe_short_hash() + if data.device == "pos": + lnurldevice_id = get_lnurldeviceposcount() lnurldevice_key = urlsafe_short_hash() await db.execute( """ @@ -79,13 +80,18 @@ async def update_lnurldevice(lnurldevice_id: str, **kwargs) -> Optional[lnurldev return lnurldevices(**row) if row else None +async def get_lnurldeviceposcount() -> int: + row = await db.fetchall( + "SELECT * FROM lnurldevice.lnurldevices WHERE device = pos" + ) + return len(row) + 1 + async def get_lnurldevice(lnurldevice_id: str) -> lnurldevices: row = await db.fetchone( "SELECT * FROM lnurldevice.lnurldevices WHERE id = ?", (lnurldevice_id,) ) return lnurldevices(**row) if row else None - async def get_lnurldevices(wallet_ids: Union[str, List[str]]) -> List[lnurldevices]: wallet_ids = [wallet_ids] q = ",".join(["?"] * len(wallet_ids[0])) From 03846adbfb25ed5fef2fd6bcacc6f5f90fb5c4a7 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 23 Dec 2022 15:40:05 +0000 Subject: [PATCH 2/6] unsupported type --- lnbits/extensions/lnurldevice/crud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/lnurldevice/crud.py b/lnbits/extensions/lnurldevice/crud.py index b1fe24aa..f5165abe 100644 --- a/lnbits/extensions/lnurldevice/crud.py +++ b/lnbits/extensions/lnurldevice/crud.py @@ -12,7 +12,7 @@ async def create_lnurldevice( data: createLnurldevice, ) -> lnurldevices: if data.device == "pos": - lnurldevice_id = get_lnurldeviceposcount() + lnurldevice_id = str(get_lnurldeviceposcount()) lnurldevice_key = urlsafe_short_hash() await db.execute( """ From 0ce987a20eb2e58384044c0041587659d9a99feb Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 23 Dec 2022 15:40:52 +0000 Subject: [PATCH 3/6] await --- lnbits/extensions/lnurldevice/crud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/lnurldevice/crud.py b/lnbits/extensions/lnurldevice/crud.py index f5165abe..ebcadd9a 100644 --- a/lnbits/extensions/lnurldevice/crud.py +++ b/lnbits/extensions/lnurldevice/crud.py @@ -12,7 +12,7 @@ async def create_lnurldevice( data: createLnurldevice, ) -> lnurldevices: if data.device == "pos": - lnurldevice_id = str(get_lnurldeviceposcount()) + lnurldevice_id = str(await get_lnurldeviceposcount()) lnurldevice_key = urlsafe_short_hash() await db.execute( """ From dce50105c9ad287e76d1888c374b14f89ac56fb7 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 23 Dec 2022 15:41:59 +0000 Subject: [PATCH 4/6] no such column --- lnbits/extensions/lnurldevice/crud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/lnurldevice/crud.py b/lnbits/extensions/lnurldevice/crud.py index ebcadd9a..d761edf4 100644 --- a/lnbits/extensions/lnurldevice/crud.py +++ b/lnbits/extensions/lnurldevice/crud.py @@ -82,7 +82,7 @@ async def update_lnurldevice(lnurldevice_id: str, **kwargs) -> Optional[lnurldev async def get_lnurldeviceposcount() -> int: row = await db.fetchall( - "SELECT * FROM lnurldevice.lnurldevices WHERE device = pos" + "SELECT * FROM lnurldevice.lnurldevices WHERE device" ) return len(row) + 1 From cd6f4c909f9693a11ac7f34f8f83a7c8544468b9 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 23 Dec 2022 22:38:19 +0000 Subject: [PATCH 5/6] swaps pos id for number --- lnbits/extensions/lnurldevice/crud.py | 6 ++++-- lnbits/extensions/lnurldevice/models.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/lnurldevice/crud.py b/lnbits/extensions/lnurldevice/crud.py index d761edf4..708827b0 100644 --- a/lnbits/extensions/lnurldevice/crud.py +++ b/lnbits/extensions/lnurldevice/crud.py @@ -11,8 +11,10 @@ from .models import createLnurldevice, lnurldevicepayment, lnurldevices async def create_lnurldevice( data: createLnurldevice, ) -> lnurldevices: - if data.device == "pos": + if data.device == "pos" or data.device == "atm": lnurldevice_id = str(await get_lnurldeviceposcount()) + else: + lnurldevice_id = urlsafe_short_hash() lnurldevice_key = urlsafe_short_hash() await db.execute( """ @@ -82,7 +84,7 @@ async def update_lnurldevice(lnurldevice_id: str, **kwargs) -> Optional[lnurldev async def get_lnurldeviceposcount() -> int: row = await db.fetchall( - "SELECT * FROM lnurldevice.lnurldevices WHERE device" + "SELECT * FROM lnurldevice.lnurldevices WHERE device = ? OR device = ?", ("pos", "atm",) ) return len(row) + 1 diff --git a/lnbits/extensions/lnurldevice/models.py b/lnbits/extensions/lnurldevice/models.py index c27470b7..66b215f2 100644 --- a/lnbits/extensions/lnurldevice/models.py +++ b/lnbits/extensions/lnurldevice/models.py @@ -17,8 +17,8 @@ class createLnurldevice(BaseModel): wallet: str currency: str device: str - profit: float - amount: int + profit: float = 0 + amount: Optional[int] = 0 pin: int = 0 profit1: float = 0 amount1: int = 0 From dd90c3a2eb35f40ea3aa5fc660d336962bf55193 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 23 Dec 2022 22:47:14 +0000 Subject: [PATCH 6/6] format --- lnbits/extensions/lnurldevice/crud.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/lnurldevice/crud.py b/lnbits/extensions/lnurldevice/crud.py index 708827b0..18451848 100644 --- a/lnbits/extensions/lnurldevice/crud.py +++ b/lnbits/extensions/lnurldevice/crud.py @@ -84,16 +84,22 @@ async def update_lnurldevice(lnurldevice_id: str, **kwargs) -> Optional[lnurldev async def get_lnurldeviceposcount() -> int: row = await db.fetchall( - "SELECT * FROM lnurldevice.lnurldevices WHERE device = ? OR device = ?", ("pos", "atm",) + "SELECT * FROM lnurldevice.lnurldevices WHERE device = ? OR device = ?", + ( + "pos", + "atm", + ), ) return len(row) + 1 + async def get_lnurldevice(lnurldevice_id: str) -> lnurldevices: row = await db.fetchone( "SELECT * FROM lnurldevice.lnurldevices WHERE id = ?", (lnurldevice_id,) ) return lnurldevices(**row) if row else None + async def get_lnurldevices(wallet_ids: Union[str, List[str]]) -> List[lnurldevices]: wallet_ids = [wallet_ids] q = ",".join(["?"] * len(wallet_ids[0]))