diff --git a/README.md b/README.md index d98b0e2..42678f1 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,11 @@ UI for diagnostics and management (key alow/ban lists, rate limiting) coming soo 1. Enable extension 2. Enable relay + + +### Development + +Create Symbolic Link: +``` +ln -s /Users/my-user/git-repos/nostr-relay-extension/ /Users/my-user/git-repos/lnbits/lnbits/extensions/nostrrelay +``` \ No newline at end of file diff --git a/models.py b/models.py index 071c3fe..d83f4ef 100644 --- a/models.py +++ b/models.py @@ -307,10 +307,14 @@ class NostrFilter(BaseModel): return inner_joins, where, values -class RelayJoin(BaseModel): +class BuyOrder(BaseModel): + action: str relay_id: str pubkey: str + units_to_buy = 0 + def is_valid_action(self): + return self.action in ['join', 'storage'] class NostrAccount(BaseModel): pubkey: str diff --git a/tasks.py b/tasks.py index 11dbc50..db09d7b 100644 --- a/tasks.py +++ b/tasks.py @@ -31,6 +31,11 @@ async def on_invoice_paid(payment: Payment): await invoice_paid_to_join(relay_id, pubkey) return + if payment.extra.get("action") == "storage": + storage_to_buy = payment.extra.get("storage_to_buy") + await invoice_paid_for_storage(relay_id, pubkey, storage_to_buy) + return + async def invoice_paid_to_join(relay_id: str, pubkey: str): try: account = await get_account(relay_id, pubkey) @@ -44,5 +49,22 @@ async def invoice_paid_to_join(relay_id: str, pubkey: str): account.paid_to_join = True await update_account(relay_id, account) + except Exception as ex: + logger.warning(ex) + + +async def invoice_paid_for_storage(relay_id: str, pubkey: str, storage_to_buy: int): + try: + account = await get_account(relay_id, pubkey) + if not account: + await create_account(relay_id, NostrAccount(pubkey=pubkey, storage=storage_to_buy)) + return + + if account.blocked: + return + + account.storage = storage_to_buy + await update_account(relay_id, account) + except Exception as ex: logger.warning(ex) \ No newline at end of file diff --git a/templates/nostrrelay/public.html b/templates/nostrrelay/public.html index 6c08824..29207a5 100644 --- a/templates/nostrrelay/public.html +++ b/templates/nostrrelay/public.html @@ -12,7 +12,7 @@
-