Skip to content

Commit

Permalink
feat: code quality (#6)
Browse files Browse the repository at this point in the history
* feat: code quality
  • Loading branch information
dni authored Aug 30, 2024
1 parent a671e02 commit 5615863
Show file tree
Hide file tree
Showing 24 changed files with 3,089 additions and 271 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 }})'
15 changes: 7 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:

release:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -34,12 +33,12 @@ jobs:
- 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"
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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +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
}
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"
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Bleskomat - <small>[LNbits](https://github.com/lnbits/lnbits) extension</small>

<small>For more about LNBits extension check [this tutorial](https://github.com/lnbits/lnbits/wiki/LNbits-Extensions)</small>

This extension allows you to connect a Bleskomat ATM to an lnbits wallet. It will work with both the [open-source DIY Bleskomat ATM project](https://github.com/samotari/bleskomat) as well as the [commercial Bleskomat ATM](https://www.bleskomat.com/).


## Connect Your Bleskomat ATM

* Click the "Add Bleskomat" button on this page to begin.
* Choose a wallet. This will be the wallet that is used to pay satoshis to your ATM customers.
* Choose the fiat currency. This should match the fiat currency that your ATM accepts.
* Pick an exchange rate provider. This is the API that will be used to query the fiat to satoshi exchange rate at the time your customer attempts to withdraw their funds.
* Set your ATM's fee percentage.
* Click the "Done" button.
* Find the new Bleskomat in the list and then click the export icon to download a new configuration file for your ATM.
* Copy the configuration file ("bleskomat.conf") to your ATM's SD card.
* Restart Your Bleskomat ATM. It should automatically reload the configurations from the SD card.

- Click the "Add Bleskomat" button on this page to begin.
- Choose a wallet. This will be the wallet that is used to pay satoshis to your ATM customers.
- Choose the fiat currency. This should match the fiat currency that your ATM accepts.
- Pick an exchange rate provider. This is the API that will be used to query the fiat to satoshi exchange rate at the time your customer attempts to withdraw their funds.
- Set your ATM's fee percentage.
- Click the "Done" button.
- Find the new Bleskomat in the list and then click the export icon to download a new configuration file for your ATM.
- Copy the configuration file ("bleskomat.conf") to your ATM's SD card.
- Restart Your Bleskomat ATM. It should automatically reload the configurations from the SD card.

## How Does It Work?

Expand Down
20 changes: 8 additions & 12 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from fastapi import APIRouter

from lnbits.db import Database
from lnbits.helpers import template_renderer

db = Database("ext_bleskomat")
from .db import db
from .views import bleskomat_generic_router
from .views_api import bleskomat_api_router
from .views_lnurl import bleskomat_lnurl_router

bleskomat_static_files = [
{
Expand All @@ -13,12 +13,8 @@
]

bleskomat_ext: APIRouter = APIRouter(prefix="/bleskomat", tags=["Bleskomat"])
bleskomat_ext.include_router(bleskomat_generic_router)
bleskomat_ext.include_router(bleskomat_api_router)
bleskomat_ext.include_router(bleskomat_lnurl_router)


def bleskomat_renderer():
return template_renderer(["bleskomat/templates"])


from .lnurl_api import * # noqa: F401,F403
from .views import * # noqa: F401,F403
from .views_api import * # noqa: F401,F403
__all__ = ["bleskomat_ext", "bleskomat_static_files", "db"]
10 changes: 5 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Bleskomat",
"short_description": "Connect a Bleskomat ATM to an lnbits",
"tile": "/bleskomat/static/image/bleskomat.png",
"contributors": ["chill117"],
"min_lnbits_version": "0.12.6"
"name": "Bleskomat",
"short_description": "Connect a Bleskomat ATM to an lnbits",
"tile": "/bleskomat/static/image/bleskomat.png",
"contributors": ["chill117"],
"min_lnbits_version": "0.12.6"
}
21 changes: 14 additions & 7 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Optional, Union
from uuid import uuid4

from . import db
from .db import db
from .helpers import generate_bleskomat_lnurl_hash
from .models import Bleskomat, BleskomatLnurl, CreateBleskomat

Expand All @@ -15,7 +15,11 @@ async def create_bleskomat(data: CreateBleskomat, wallet_id: str) -> Bleskomat:
api_key_encoding = "hex"
await db.execute(
"""
INSERT INTO bleskomat.bleskomats (id, wallet, api_key_id, api_key_secret, api_key_encoding, name, fiat_currency, exchange_rate_provider, fee)
INSERT INTO bleskomat.bleskomats
(
id, wallet, api_key_id, api_key_secret, api_key_encoding,
name, fiat_currency, exchange_rate_provider, fee
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
Expand Down Expand Up @@ -79,18 +83,21 @@ async def create_bleskomat_lnurl(
*, bleskomat: Bleskomat, secret: str, tag: str, params: str, uses: int = 1
) -> BleskomatLnurl:
bleskomat_lnurl_id = uuid4().hex
hash = generate_bleskomat_lnurl_hash(secret)
lnurl_hash = generate_bleskomat_lnurl_hash(secret)
now = int(time.time())
await db.execute(
"""
INSERT INTO bleskomat.bleskomat_lnurls (id, bleskomat, wallet, hash, tag, params, api_key_id, initial_uses, remaining_uses, created_time, updated_time)
INSERT INTO bleskomat.bleskomat_lnurls (
id, bleskomat, wallet, hash, tag, params, api_key_id,
initial_uses, remaining_uses, created_time, updated_time
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
bleskomat_lnurl_id,
bleskomat.id,
bleskomat.wallet,
hash,
lnurl_hash,
tag,
params,
bleskomat.api_key_id,
Expand All @@ -106,8 +113,8 @@ async def create_bleskomat_lnurl(


async def get_bleskomat_lnurl(secret: str) -> Optional[BleskomatLnurl]:
hash = generate_bleskomat_lnurl_hash(secret)
lnurl_hash = generate_bleskomat_lnurl_hash(secret)
row = await db.fetchone(
"SELECT * FROM bleskomat.bleskomat_lnurls WHERE hash = ?", (hash,)
"SELECT * FROM bleskomat.bleskomat_lnurls WHERE hash = ?", (lnurl_hash,)
)
return BleskomatLnurl(**row) if row else None
3 changes: 3 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from lnbits.db import Database

db = Database("ext_bleskomat")
1 change: 0 additions & 1 deletion exchange_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
os.path.join(
os.path.dirname(os.path.realpath(__file__)), "fiat_currencies.json"
),
"r",
)
)

Expand Down
Loading

0 comments on commit 5615863

Please sign in to comment.