Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Oct 31, 2024
0 parents commit 4d5e989
Show file tree
Hide file tree
Showing 32 changed files with 4,683 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 "[email protected]"
- 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"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Bitcoin Switch - <small>[LNbits](https://github.com/lnbits/lnbits) extension</small>

Turn things on with bitcoin!

[bitcoinswitch.lnbits.com](https://bitcoinswitch.lnbits.com)

`Author: Ben Arc` `Author: DNI`
49 changes: 49 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import asyncio

from fastapi import APIRouter
from loguru import logger

from .crud import db
from .tasks import wait_for_paid_invoices
from .views import bitcoinswitch_generic_router
from .views_api import bitcoinswitch_api_router
from .views_lnurl import bitcoinswitch_lnurl_router

bitcoinswitch_ext: APIRouter = APIRouter(
prefix="/bitcoinswitch", tags=["bitcoinswitch"]
)
bitcoinswitch_ext.include_router(bitcoinswitch_generic_router)
bitcoinswitch_ext.include_router(bitcoinswitch_api_router)
bitcoinswitch_ext.include_router(bitcoinswitch_lnurl_router)

bitcoinswitch_static_files = [
{
"path": "/bitcoinswitch/static",
"name": "bitcoinswitch_static",
}
]
scheduled_tasks: list[asyncio.Task] = []


def bitcoinswitch_stop():
for task in scheduled_tasks:
try:
task.cancel()
except Exception as ex:
logger.warning(ex)


def bitcoinswitch_start():
from lnbits.tasks import create_permanent_unique_task

task = create_permanent_unique_task("ext_bitcoinswitch", wait_for_paid_invoices)
scheduled_tasks.append(task)


__all__ = [
"db",
"bitcoinswitch_ext",
"bitcoinswitch_static_files",
"bitcoinswitch_start",
"bitcoinswitch_stop",
]
47 changes: 47 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "Bitcoin Switch",
"short_description": "Hardware focused LNURL helper",
"tile": "/bitcoinswitch/static/image/lnurldevice.png",
"min_lnbits_version": "1.0.0",
"contributors": [
{
"name": "Ben Arc",
"uri": "mailto:[email protected]",
"role": "Developer"
},
{
"name": "BlackCoffee",
"uri": "https://github.com/blackcoffee",
"role": "Developer"
},
{
"name": "Vlad Stan",
"uri": "https://github.com/motorina1",
"role": "Developer"
},
{
"name": "dni",
"uri": "https://github.com/dni",
"role": "Developer"
}
],
"images": [
{
"uri": "https://raw.githubusercontent.com/lnbits/bitcoinswitch/main/static/image/oS5VEEf.png"
},
{
"uri": "https://raw.githubusercontent.com/lnbits/bitcoinswitch/main/static/image/U8dgtSl.png"
},
{
"uri": "https://raw.githubusercontent.com/lnbits/bitcoinswitch/main/static/image/7Nz9PyU.png"
},
{
"uri": "https://raw.githubusercontent.com/lnbits/bitcoinswitch/main/static/image/uPxF8SO.png",
"link": "https://www.youtube.com/watch?v=98VYC99s770",
"tooltip": "demo video"
}
],
"description_md": "https://raw.githubusercontent.com/lnbits/bitcoinswitch/main/description.md",
"terms_and_conditions_md": "https://raw.githubusercontent.com/lnbits/bitcoinswitch/main/toc.md",
"license": "MIT"
}
Loading

0 comments on commit 4d5e989

Please sign in to comment.