Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
formatting
  • Loading branch information
dni committed Nov 6, 2024
0 parents commit 01c27a1
Show file tree
Hide file tree
Showing 34 changed files with 4,406 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
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 }})'
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__
node_modules
.mypy_cache
.venv
12 changes: 12 additions & 0 deletions .prettierrc
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
}
21 changes: 21 additions & 0 deletions LICENSE
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.
47 changes: 47 additions & 0 deletions Makefile
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"
5 changes: 5 additions & 0 deletions README.md
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`
24 changes: 24 additions & 0 deletions __init__.py
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",
]
47 changes: 47 additions & 0 deletions config.json
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"
}
132 changes: 132 additions & 0 deletions crud.py
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})
5 changes: 5 additions & 0 deletions description.md
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`
Loading

0 comments on commit 01c27a1

Please sign in to comment.