-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
formatting
- Loading branch information
0 parents
commit 01c27a1
Showing
34 changed files
with
4,406 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Create github release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
tag: ${{ github.ref_name }} | ||
run: | | ||
gh release create "$tag" --generate-notes | ||
pullrequest: | ||
needs: [release] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
token: ${{ secrets.EXT_GITHUB }} | ||
repository: lnbits/lnbits-extensions | ||
path: './lnbits-extensions' | ||
|
||
- name: setup git user | ||
run: | | ||
git config --global user.name "alan" | ||
git config --global user.email "alan@lnbits.com" | ||
- name: Create pull request in extensions repo | ||
env: | ||
GH_TOKEN: ${{ secrets.EXT_GITHUB }} | ||
repo_name: '${{ github.event.repository.name }}' | ||
tag: '${{ github.ref_name }}' | ||
branch: 'update-${{ github.event.repository.name }}-${{ github.ref_name }}' | ||
title: '[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}' | ||
body: 'https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}' | ||
archive: 'https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip' | ||
run: | | ||
cd lnbits-extensions | ||
git checkout -b $branch | ||
# if there is another open PR | ||
git pull origin $branch || echo "branch does not exist" | ||
sh util.sh update_extension $repo_name $tag | ||
git add -A | ||
git commit -am "$title" | ||
git push origin $branch | ||
# check if pr exists before creating it | ||
gh config set pager cat | ||
check=$(gh pr list -H $branch | wc -l) | ||
test $check -ne 0 || gh pr create --title "$title" --body "$body" --repo lnbits/lnbits-extensions |
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,4 @@ | ||
__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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 LNbits | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# LNPoS - <small>[LNbits](https://github.com/lnbits/lnbits) extension</small> | ||
|
||
<small>LNbits extension for Point of Sale (PoS) terminals</small> | ||
|
||
`Author: Ben Arc` `Author: DNI` |
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,24 @@ | ||
from fastapi import APIRouter | ||
|
||
from .crud import db | ||
from .views import lnpos_generic_router | ||
from .views_api import lnpos_api_router | ||
from .views_lnurl import lnpos_lnurl_router | ||
|
||
lnpos_ext: APIRouter = APIRouter(prefix="/lnpos", tags=["lnpos"]) | ||
lnpos_ext.include_router(lnpos_generic_router) | ||
lnpos_ext.include_router(lnpos_api_router) | ||
lnpos_ext.include_router(lnpos_lnurl_router) | ||
|
||
lnpos_static_files = [ | ||
{ | ||
"path": "/lnpos/static", | ||
"name": "lnpos_static", | ||
} | ||
] | ||
|
||
__all__ = [ | ||
"db", | ||
"lnpos_ext", | ||
"lnpos_static_files", | ||
] |
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 @@ | ||
{ | ||
"name": "LNPoS", | ||
"short_description": "LNPoS lightning point of sale", | ||
"tile": "/lnpos/static/image/lnpos.png", | ||
"min_lnbits_version": "1.0.0", | ||
"contributors": [ | ||
{ | ||
"name": "Ben Arc", | ||
"uri": "mailto:ben@lnbits.com", | ||
"role": "Developer" | ||
}, | ||
{ | ||
"name": "BlackCoffee", | ||
"uri": "https://github.com/blackcoffee", | ||
"role": "Developer" | ||
}, | ||
{ | ||
"name": "Vlad Stan", | ||
"uri": "https://github.com/arcbtc", | ||
"role": "Developer" | ||
}, | ||
{ | ||
"name": "dni", | ||
"uri": "https://github.com/dni", | ||
"role": "Developer" | ||
} | ||
], | ||
"images": [ | ||
{ | ||
"uri": "https://raw.githubusercontent.com/lnbits/lnpos/main/static/image/oS5VEEf.png" | ||
}, | ||
{ | ||
"uri": "https://raw.githubusercontent.com/lnbits/lnpos/main/static/image/U8dgtSl.png" | ||
}, | ||
{ | ||
"uri": "https://raw.githubusercontent.com/lnbits/lnpos/main/static/image/7Nz9PyU.png" | ||
}, | ||
{ | ||
"uri": "https://raw.githubusercontent.com/lnbits/lnpos/main/static/image/uPxF8SO.png", | ||
"link": "https://www.youtube.com/watch?v=98VYC99s770", | ||
"tooltip": "demo video" | ||
} | ||
], | ||
"description_md": "https://raw.githubusercontent.com/lnbits/lnpos/main/description.md", | ||
"terms_and_conditions_md": "https://raw.githubusercontent.com/lnbits/lnpos/main/toc.md", | ||
"license": "MIT" | ||
} |
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,132 @@ | ||
from typing import Optional | ||
|
||
import shortuuid | ||
from lnbits.db import Database | ||
from lnbits.helpers import urlsafe_short_hash | ||
|
||
from .models import CreateLnpos, Lnpos, LnposPayment | ||
|
||
db = Database("ext_lnpos") | ||
|
||
|
||
async def create_lnpos(data: CreateLnpos) -> Lnpos: | ||
|
||
if data.device == "pos" or data.device == "atm": | ||
lnpos_id = shortuuid.uuid()[:5] | ||
else: | ||
lnpos_id = urlsafe_short_hash() | ||
|
||
lnpos_key = urlsafe_short_hash() | ||
|
||
device = Lnpos( | ||
id=lnpos_id, | ||
key=lnpos_key, | ||
title=data.title, | ||
wallet=data.wallet, | ||
profit=data.profit, | ||
currency=data.currency, | ||
device=data.device, | ||
) | ||
|
||
await db.insert("lnpos.lnpos", device) | ||
|
||
return device | ||
|
||
|
||
async def update_lnpos(device: Lnpos) -> Lnpos: | ||
await db.update("lnpos.lnpos", device) | ||
return device | ||
|
||
|
||
async def get_lnpos(lnpos_id: str) -> Optional[Lnpos]: | ||
return await db.fetchone( | ||
"SELECT * FROM lnpos.lnpos WHERE id = :id", | ||
{"id": lnpos_id}, | ||
Lnpos, | ||
) | ||
|
||
|
||
async def get_lnposs(wallet_ids: list[str]) -> list[Lnpos]: | ||
|
||
q = ",".join([f"'{w}'" for w in wallet_ids]) | ||
return await db.fetchall( | ||
f""" | ||
SELECT * FROM lnpos.lnpos WHERE wallet IN ({q}) | ||
ORDER BY id | ||
""", | ||
model=Lnpos, | ||
) | ||
|
||
|
||
async def delete_lnpos(lnpos_id: str) -> None: | ||
await db.execute("DELETE FROM lnpos.lnpos WHERE id = :id", {"id": lnpos_id}) | ||
|
||
|
||
async def create_lnpos_payment(payment: LnposPayment) -> LnposPayment: | ||
await db.insert("lnpos.lnpos_payment", payment) | ||
return payment | ||
|
||
|
||
async def update_lnpos_payment( | ||
lnpos_payment: LnposPayment, | ||
) -> LnposPayment: | ||
await db.update("lnpos.lnpos_payment", lnpos_payment) | ||
return lnpos_payment | ||
|
||
|
||
async def get_lnpos_payment( | ||
lnpos_payment_id: str, | ||
) -> Optional[LnposPayment]: | ||
return await db.fetchone( | ||
"SELECT * FROM lnpos.lnpos_payment WHERE id = :id", | ||
{"id": lnpos_payment_id}, | ||
) | ||
|
||
|
||
async def get_lnpos_payments( | ||
lnpos_ids: list[str], | ||
) -> list[LnposPayment]: | ||
if len(lnpos_ids) == 0: | ||
return [] | ||
q = ",".join([f"'{w}'" for w in lnpos_ids]) | ||
return await db.fetchall( | ||
f""" | ||
SELECT * FROM lnpos.lnpos_payment WHERE deviceid IN ({q}) | ||
ORDER BY id | ||
""", | ||
model=LnposPayment, | ||
) | ||
|
||
|
||
async def get_lnpos_payment_by_payhash( | ||
payhash: str, | ||
) -> Optional[LnposPayment]: | ||
return await db.fetchone( | ||
"SELECT * FROM lnpos.lnpos_payment WHERE payhash = :payhash", | ||
{"payhash": payhash}, | ||
) | ||
|
||
|
||
async def get_lnpos_payment_by_payload( | ||
payload: str, | ||
) -> Optional[LnposPayment]: | ||
return await db.fetchone( | ||
"SELECT * FROM lnpos.lnpos_payment WHERE payload = :payload", | ||
{"payload": payload}, | ||
LnposPayment, | ||
) | ||
|
||
|
||
async def get_recent_lnpos_payment(payload: str) -> Optional[LnposPayment]: | ||
return await db.fetchone( | ||
""" | ||
SELECT * FROM lnpos.lnpos_payment | ||
WHERE payload = :payload ORDER BY timestamp DESC LIMIT 1 | ||
""", | ||
{"payload": payload}, | ||
LnposPayment, | ||
) | ||
|
||
|
||
async def delete_atm_payment_link(atm_id: str) -> None: | ||
await db.execute("DELETE FROM lnpos.lnpos_payment WHERE id = :id", {"id": atm_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# LNPoS - <small>[LNbits](https://github.com/lnbits/lnbits) extension</small> | ||
|
||
<small>LNbits extension for Point of Sale (PoS) terminals</small> | ||
|
||
`Author: Ben Arc` `Author: DNI` |
Oops, something went wrong.