-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format add ci fixup ci
- Loading branch information
Showing
26 changed files
with
3,202 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
uses: lnbits/lnbits/.github/workflows/lint.yml@dev | ||
tests: | ||
runs-on: ubuntu-latest | ||
needs: [lint] | ||
strategy: | ||
matrix: | ||
python-version: ['3.9', '3.10'] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: lnbits/lnbits/.github/actions/prepare@dev | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Run pytest | ||
uses: pavelzw/pytest-action@v2 | ||
env: | ||
LNBITS_BACKEND_WALLET_CLASS: FakeWallet | ||
PYTHONUNBUFFERED: 1 | ||
DEBUG: true | ||
with: | ||
verbose: true | ||
job-summary: true | ||
emoji: false | ||
click-to-expand: true | ||
custom-pytest: poetry run pytest | ||
report-title: 'test (${{ matrix.python-version }})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
__pycache__ | ||
__pycache__ | ||
node_modules | ||
.mypy_cache | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"semi": false, | ||
"arrowParens": "avoid", | ||
"insertPragma": false, | ||
"printWidth": 80, | ||
"proseWrap": "preserve", | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"useTabs": false, | ||
"bracketSameLine": false, | ||
"bracketSpacing": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
all: format check | ||
|
||
format: prettier black ruff | ||
|
||
check: mypy pyright checkblack checkruff checkprettier | ||
|
||
prettier: | ||
poetry run ./node_modules/.bin/prettier --write . | ||
pyright: | ||
poetry run ./node_modules/.bin/pyright | ||
|
||
mypy: | ||
poetry run mypy . | ||
|
||
black: | ||
poetry run black . | ||
|
||
ruff: | ||
poetry run ruff check . --fix | ||
|
||
checkruff: | ||
poetry run ruff check . | ||
|
||
checkprettier: | ||
poetry run ./node_modules/.bin/prettier --check . | ||
|
||
checkblack: | ||
poetry run black --check . | ||
|
||
checkeditorconfig: | ||
editorconfig-checker | ||
|
||
test: | ||
PYTHONUNBUFFERED=1 \ | ||
DEBUG=true \ | ||
poetry run pytest | ||
install-pre-commit-hook: | ||
@echo "Installing pre-commit hook to git" | ||
@echo "Uninstall the hook with poetry run pre-commit uninstall" | ||
poetry run pre-commit install | ||
|
||
pre-commit: | ||
poetry run pre-commit run --all-files | ||
|
||
|
||
checkbundle: | ||
@echo "skipping checkbundle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,77 @@ | ||
from typing import List, Optional, Union | ||
from typing import Optional, Union | ||
|
||
from lnbits.helpers import urlsafe_short_hash | ||
from lnbits.lnurl import encode as lnurl_encode | ||
from . import db | ||
from .models import CreateMyExtensionData, MyExtension | ||
from fastapi import Request | ||
from lnurl import encode as lnurl_encode | ||
import shortuuid | ||
from lnbits.db import Database | ||
from lnbits.helpers import insert_query, update_query | ||
|
||
from .models import MyExtension | ||
|
||
async def create_myextension( | ||
wallet_id: str, data: CreateMyExtensionData, req: Request | ||
) -> MyExtension: | ||
myextension_id = urlsafe_short_hash() | ||
db = Database("ext_myextension") | ||
table_name = "myextension.maintable" | ||
|
||
|
||
async def create_myextension(data: MyExtension) -> MyExtension: | ||
await db.execute( | ||
""" | ||
INSERT INTO myextension.maintable (id, wallet, name, lnurlpayamount, lnurlwithdrawamount) | ||
VALUES (?, ?, ?, ?, ?) | ||
""", | ||
( | ||
myextension_id, | ||
wallet_id, | ||
data.name, | ||
data.lnurlpayamount, | ||
data.lnurlwithdrawamount, | ||
), | ||
insert_query(table_name, data), | ||
(*data.dict().values(),), | ||
) | ||
myextension = await get_myextension(myextension_id, req) | ||
assert myextension, "Newly created table couldn't be retrieved" | ||
return myextension | ||
return data | ||
|
||
# this is how we used to do it | ||
|
||
async def get_myextension( | ||
myextension_id: str, req: Optional[Request] = None | ||
) -> Optional[MyExtension]: | ||
# myextension_id = urlsafe_short_hash() | ||
# await db.execute( | ||
# """ | ||
# INSERT INTO myextension.maintable | ||
# (id, wallet, name, lnurlpayamount, lnurlwithdrawamount) | ||
# VALUES (?, ?, ?, ?, ?) | ||
# """, | ||
# ( | ||
# myextension_id, | ||
# wallet_id, | ||
# data.name, | ||
# data.lnurlpayamount, | ||
# data.lnurlwithdrawamount, | ||
# ), | ||
# ) | ||
# myextension = await get_myextension(myextension_id) | ||
# assert myextension, "Newly created table couldn't be retrieved" | ||
|
||
|
||
async def get_myextension(myextension_id: str) -> Optional[MyExtension]: | ||
row = await db.fetchone( | ||
"SELECT * FROM myextension.maintable WHERE id = ?", (myextension_id,) | ||
f"SELECT * FROM {table_name} WHERE id = ?", (myextension_id,) | ||
) | ||
if not row: | ||
return None | ||
rowAmended = MyExtension(**row) | ||
if req: | ||
rowAmended.lnurlpay = lnurl_encode( | ||
req.url_for("myextension.api_lnurl_pay", myextension_id=row.id)._url | ||
) | ||
rowAmended.lnurlwithdraw = lnurl_encode( | ||
req.url_for( | ||
"myextension.api_lnurl_withdraw", | ||
myextension_id=row.id, | ||
tickerhash=shortuuid.uuid(name=rowAmended.id + str(rowAmended.ticker)), | ||
)._url | ||
) | ||
return rowAmended | ||
|
||
|
||
async def get_myextensions( | ||
wallet_ids: Union[str, List[str]], req: Optional[Request] = None | ||
) -> List[MyExtension]: | ||
return MyExtension(**row) if row else None | ||
|
||
|
||
async def get_myextensions(wallet_ids: Union[str, list[str]]) -> list[MyExtension]: | ||
if isinstance(wallet_ids, str): | ||
wallet_ids = [wallet_ids] | ||
|
||
q = ",".join(["?"] * len(wallet_ids)) | ||
rows = await db.fetchall( | ||
f"SELECT * FROM myextension.maintable WHERE wallet IN ({q})", (*wallet_ids,) | ||
f"SELECT * FROM {table_name} WHERE wallet IN ({q})", (*wallet_ids,) | ||
) | ||
tempRows = [MyExtension(**row) for row in rows] | ||
if req: | ||
for row in tempRows: | ||
row.lnurlpay = lnurl_encode( | ||
req.url_for("myextension.api_lnurl_pay", myextension_id=row.id)._url | ||
) | ||
row.lnurlwithdraw = lnurl_encode( | ||
req.url_for( | ||
"myextension.api_lnurl_withdraw", | ||
myextension_id=row.id, | ||
tickerhash=shortuuid.uuid(name=row.id + str(row.ticker)), | ||
)._url | ||
) | ||
return tempRows | ||
|
||
|
||
async def update_myextension( | ||
myextension_id: str, req: Optional[Request] = None, **kwargs | ||
) -> MyExtension: | ||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) | ||
return [MyExtension(**row) for row in rows] | ||
|
||
|
||
async def update_myextension(data: MyExtension) -> MyExtension: | ||
await db.execute( | ||
f"UPDATE myextension.maintable SET {q} WHERE id = ?", | ||
(*kwargs.values(), myextension_id), | ||
update_query(table_name, data), | ||
( | ||
*data.dict().values(), | ||
data.id, | ||
), | ||
) | ||
myextension = await get_myextension(myextension_id, req) | ||
assert myextension, "Newly updated myextension couldn't be retrieved" | ||
return myextension | ||
return data | ||
# this is how we used to do it | ||
|
||
# q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) | ||
# await db.execute( | ||
# f"UPDATE myextension.maintable SET {q} WHERE id = ?", | ||
# (*kwargs.values(), myextension_id), | ||
# ) | ||
|
||
|
||
async def delete_myextension(myextension_id: str) -> None: | ||
await db.execute( | ||
"DELETE FROM myextension.maintable WHERE id = ?", (myextension_id,) | ||
) | ||
await db.execute(f"DELETE FROM {table_name} WHERE id = ?", (myextension_id,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.