Skip to content

Commit

Permalink
re-named extension
Browse files Browse the repository at this point in the history
  • Loading branch information
echennells committed Oct 7, 2024
1 parent 47a2000 commit d553e9d
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 261 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
`The README.md typically serves as a guide for using the extension.`

# MyExtension - An [LNbits](https://github.com/lnbits/lnbits) Extension
# LnurlUniversal - An [LNbits](https://github.com/lnbits/lnbits) Extension

## A Starter Template for Your Own Extension

Expand All @@ -10,12 +10,12 @@ Ready to start hacking? Once you've forked this extension, you can incorporate f

> This guide assumes you're using this extension as a base for a new one, and have installed LNbits using https://github.com/lnbits/lnbits/blob/main/docs/guide/installation.md#option-1-recommended-poetry.
1. Install and enable the extension either through the official LNbits manifest or by adding https://raw.githubusercontent.com/lnbits/myextension/main/manifest.json to `"Server"/"Server"/"Extension Sources"`. ![Extension Sources](https://i.imgur.com/MUGwAU3.png) ![image](https://github.com/lnbits/myextension/assets/33088785/4133123b-c747-4458-ba6c-5cc7c0f124d8)
1. Install and enable the extension either through the official LNbits manifest or by adding https://raw.githubusercontent.com/lnbits/lnurluniversal/main/manifest.json to `"Server"/"Server"/"Extension Sources"`. ![Extension Sources](https://i.imgur.com/MUGwAU3.png) ![image](https://github.com/lnbits/lnurluniversal/assets/33088785/4133123b-c747-4458-ba6c-5cc7c0f124d8)

2. `Ctrl c` shut down your LNbits installation.
3. Download the extension files from https://github.com/lnbits/myextension to a folder outside of `/lnbits`, and initialize the folder with `git`. Alternatively, create a repo, copy the myextension extension files into it, then `git clone` the extension to a location outside of `/lnbits`.
3. Download the extension files from https://github.com/lnbits/lnurluniversal to a folder outside of `/lnbits`, and initialize the folder with `git`. Alternatively, create a repo, copy the lnurluniversal extension files into it, then `git clone` the extension to a location outside of `/lnbits`.
4. Remove the installed extension from `lnbits/lnbits/extensions`.
5. Create a symbolic link using `ln -s /home/ben/Projects/<name of your extension> /home/ben/Projects/lnbits/lnbits/extensions`.
6. Restart your LNbits installation. You can now modify your extension and `git push` changes to a repo.
7. When you're ready to share your manifest so others can install it, edit `/lnbits/myextension/manifest.json` to include the git credentials of your extension.
7. When you're ready to share your manifest so others can install it, edit `/lnbits/lnurluniversal/manifest.json` to include the git credentials of your extension.
8. IMPORTANT: If you want your extension to be added to the official LNbits manifest, please follow the guidelines here: https://github.com/lnbits/lnbits-extensions#important
36 changes: 18 additions & 18 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@

from .crud import db
from .tasks import wait_for_paid_invoices
from .views import myextension_generic_router
from .views_api import myextension_api_router
from .views_lnurl import myextension_lnurl_router
from .views import lnurluniversal_generic_router
from .views_api import lnurluniversal_api_router
from .views_lnurl import lnurluniversal_lnurl_router

logger.debug(
"This logged message is from myextension/__init__.py, you can debug in your "
"This logged message is from lnurluniversal/__init__.py, you can debug in your "
"extension using 'import logger from loguru' and 'logger.debug(<thing-to-log>)'."
)


myextension_ext: APIRouter = APIRouter(prefix="/myextension", tags=["MyExtension"])
myextension_ext.include_router(myextension_generic_router)
myextension_ext.include_router(myextension_api_router)
myextension_ext.include_router(myextension_lnurl_router)
lnurluniversal_ext: APIRouter = APIRouter(prefix="/lnurluniversal", tags=["LnurlUniversal"])
lnurluniversal_ext.include_router(lnurluniversal_generic_router)
lnurluniversal_ext.include_router(lnurluniversal_api_router)
lnurluniversal_ext.include_router(lnurluniversal_lnurl_router)

myextension_static_files = [
lnurluniversal_static_files = [
{
"path": "/myextension/static",
"name": "myextension_static",
"path": "/lnurluniversal/static",
"name": "lnurluniversal_static",
}
]

scheduled_tasks: list[asyncio.Task] = []


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


def myextension_start():
def lnurluniversal_start():
from lnbits.tasks import create_permanent_unique_task

task = create_permanent_unique_task("ext_myextension", wait_for_paid_invoices)
task = create_permanent_unique_task("ext_lnurluniversal", wait_for_paid_invoices)
scheduled_tasks.append(task)


__all__ = [
"db",
"myextension_ext",
"myextension_static_files",
"myextension_start",
"myextension_stop",
"lnurluniversal_ext",
"lnurluniversal_static_files",
"lnurluniversal_start",
"lnurluniversal_stop",
]
14 changes: 7 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "MyExtension",
"name": "LnurlUniversal",
"short_description": "Minimal extension to build on",
"tile": "/myextension/static/image/myextension.png",
"tile": "/lnurluniversal/static/image/lnurluniversal.png",
"min_lnbits_version": "0.12.5",
"contributors": [
{
Expand All @@ -22,17 +22,17 @@
],
"images": [
{
"uri": "https://raw.githubusercontent.com/lnbits/myextension/main/static/image/1.png",
"uri": "https://raw.githubusercontent.com/lnbits/lnurluniversal/main/static/image/1.png",
"link": "https://www.youtube.com/embed/SkkIwO_X4i4?si=9JJh1Fc6GfHDZK6b"
},
{
"uri": "https://raw.githubusercontent.com/lnbits/myextension/main/static/image/2.png"
"uri": "https://raw.githubusercontent.com/lnbits/lnurluniversal/main/static/image/2.png"
},
{
"uri": "https://raw.githubusercontent.com/lnbits/myextension/main/static/image/3.png"
"uri": "https://raw.githubusercontent.com/lnbits/lnurluniversal/main/static/image/3.png"
}
],
"description_md": "https://raw.githubusercontent.com/lnbits/myextension/main/description.md",
"terms_and_conditions_md": "https://raw.githubusercontent.com/lnbits/myextension/main/toc.md",
"description_md": "https://raw.githubusercontent.com/lnbits/lnurluniversal/main/description.md",
"terms_and_conditions_md": "https://raw.githubusercontent.com/lnbits/lnurluniversal/main/toc.md",
"license": "MIT"
}
38 changes: 19 additions & 19 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from lnbits.db import Database
from lnbits.helpers import insert_query, update_query

from .models import MyExtension
from .models import LnurlUniversal

db = Database("ext_myextension")
table_name = "myextension.maintable"
db = Database("ext_lnurluniversal")
table_name = "lnurluniversal.maintable"


async def create_myextension(data: MyExtension) -> MyExtension:
async def create_lnurluniversal(data: LnurlUniversal) -> LnurlUniversal:
await db.execute(
insert_query(table_name, data),
(*data.dict().values(),),
Expand All @@ -18,44 +18,44 @@ async def create_myextension(data: MyExtension) -> MyExtension:

# this is how we used to do it

# myextension_id = urlsafe_short_hash()
# lnurluniversal_id = urlsafe_short_hash()
# await db.execute(
# """
# INSERT INTO myextension.maintable
# INSERT INTO lnurluniversal.maintable
# (id, wallet, name, lnurlpayamount, lnurlwithdrawamount)
# VALUES (?, ?, ?, ?, ?)
# """,
# (
# myextension_id,
# lnurluniversal_id,
# wallet_id,
# data.name,
# data.lnurlpayamount,
# data.lnurlwithdrawamount,
# ),
# )
# myextension = await get_myextension(myextension_id)
# assert myextension, "Newly created table couldn't be retrieved"
# lnurluniversal = await get_lnurluniversal(lnurluniversal_id)
# assert lnurluniversal, "Newly created table couldn't be retrieved"


async def get_myextension(myextension_id: str) -> Optional[MyExtension]:
async def get_lnurluniversal(lnurluniversal_id: str) -> Optional[LnurlUniversal]:
row = await db.fetchone(
f"SELECT * FROM {table_name} WHERE id = ?", (myextension_id,)
f"SELECT * FROM {table_name} WHERE id = ?", (lnurluniversal_id,)
)
return MyExtension(**row) if row else None
return LnurlUniversal(**row) if row else None


async def get_myextensions(wallet_ids: Union[str, list[str]]) -> list[MyExtension]:
async def get_lnurluniversals(wallet_ids: Union[str, list[str]]) -> list[LnurlUniversal]:
if isinstance(wallet_ids, str):
wallet_ids = [wallet_ids]

q = ",".join(["?"] * len(wallet_ids))
rows = await db.fetchall(
f"SELECT * FROM {table_name} WHERE wallet IN ({q})", (*wallet_ids,)
)
return [MyExtension(**row) for row in rows]
return [LnurlUniversal(**row) for row in rows]


async def update_myextension(data: MyExtension) -> MyExtension:
async def update_lnurluniversal(data: LnurlUniversal) -> LnurlUniversal:
await db.execute(
update_query(table_name, data),
(
Expand All @@ -68,10 +68,10 @@ async def update_myextension(data: MyExtension) -> MyExtension:

# 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),
# f"UPDATE lnurluniversal.maintable SET {q} WHERE id = ?",
# (*kwargs.values(), lnurluniversal_id),
# )


async def delete_myextension(myextension_id: str) -> None:
await db.execute(f"DELETE FROM {table_name} WHERE id = ?", (myextension_id,))
async def delete_lnurluniversal(lnurluniversal_id: str) -> None:
await db.execute(f"DELETE FROM {table_name} WHERE id = ?", (lnurluniversal_id,))
2 changes: 1 addition & 1 deletion description.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MyExtension can be used as a template for building new extensions, it includes a bunch of functions that can be edited/deleted as you need them.
LnurlUniversal can be used as a template for building new extensions, it includes a bunch of functions that can be edited/deleted as you need them.

This is a longform description that will be used in the advanced description when users click on the "more" button on the extension cards.

Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"repos": [
{
"id": "myextension",
"organisation": "lnbits",
"repository": "myextension"
"id": "lnurluniversal",
"organisation": "echennells",
"repository": "lnurl-universal"
}
]
}
2 changes: 1 addition & 1 deletion migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def m001_initial(db):
"""
await db.execute(
"""
CREATE TABLE myextension.maintable (
CREATE TABLE lnurluniversal.maintable (
id TEXT PRIMARY KEY,
wallet TEXT NOT NULL,
name TEXT NOT NULL,
Expand Down
4 changes: 2 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from pydantic import BaseModel


class CreateMyExtensionData(BaseModel):
class CreateLnurlUniversalData(BaseModel):
name: str
lnurlpayamount: int
lnurlwithdrawamount: int
wallet: Optional[str] = None
total: int = 0


class MyExtension(BaseModel):
class LnurlUniversal(BaseModel):
id: str
wallet: str
lnurlpayamount: int
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "myextension"
name = "lnurluniversal"
version = "0.0.0"
description = "Eightball is a simple API that allows you to create a random number generator."
authors = ["benarc", "dni <[email protected]>"]
Expand Down
26 changes: 13 additions & 13 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from lnbits.helpers import get_current_extension_name
from lnbits.tasks import register_invoice_listener

from .crud import get_myextension, update_myextension
from .crud import get_lnurluniversal, update_lnurluniversal

#######################################
########## RUN YOUR TASKS HERE ########
Expand All @@ -26,32 +26,32 @@ async def wait_for_paid_invoices():


async def on_invoice_paid(payment: Payment) -> None:
if payment.extra.get("tag") != "MyExtension":
if payment.extra.get("tag") != "LnurlUniversal":
return

myextension_id = payment.extra.get("myextensionId")
assert myextension_id, "myextensionId not set in invoice"
myextension = await get_myextension(myextension_id)
assert myextension, "MyExtension does not exist"
lnurluniversal_id = payment.extra.get("lnurluniversalId")
assert lnurluniversal_id, "lnurluniversalId not set in invoice"
lnurluniversal = await get_lnurluniversal(lnurluniversal_id)
assert lnurluniversal, "LnurlUniversal does not exist"

# update something in the db
if payment.extra.get("lnurlwithdraw"):
total = myextension.total - payment.amount
total = lnurluniversal.total - payment.amount
else:
total = myextension.total + payment.amount
total = lnurluniversal.total + payment.amount

myextension.total = total
await update_myextension(myextension)
lnurluniversal.total = total
await update_lnurluniversal(lnurluniversal)

# here we could send some data to a websocket on
# wss://<your-lnbits>/api/v1/ws/<myextension_id> and then listen to it on
# wss://<your-lnbits>/api/v1/ws/<lnurluniversal_id> and then listen to it on
# the frontend, which we do with index.html connectWebocket()

some_payment_data = {
"name": myextension.name,
"name": lnurluniversal.name,
"amount": payment.amount,
"fee": payment.fee,
"checking_id": payment.checking_id,
}

await websocket_updater(myextension_id, str(some_payment_data))
await websocket_updater(lnurluniversal_id, str(some_payment_data))
2 changes: 1 addition & 1 deletion templates/myextension/_api_docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
label="API info"
:content-inset-level="0.5"
>
<q-btn flat label="Swagger API" type="a" href="../docs#/MyExtension"></q-btn>
<q-btn flat label="Swagger API" type="a" href="../docs#/LnurlUniversal"></q-btn>
</q-expansion-item>
4 changes: 2 additions & 2 deletions templates/myextension/_myextension.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
>Repo
<a
class="text-secondary"
href="https://github.com/lnbits/myextension"
href="https://github.com/lnbits/lnurluniversal"
target="_blank"
>MyExtension</a
>LnurlUniversal</a
>.</small
>
</q-card-section>
Expand Down
Loading

0 comments on commit d553e9d

Please sign in to comment.