feat: add NIP-52 Nostr publish + sync of calendar events
Approved events are mirrored to Nostr as NIP-52 calendar events (kind
31922) signed by the wallet owner's pubkey, and incoming kind 31922/31923
events from subscribed relays are synced into the local DB so events
created on other LNbits instances or Nostr clients show up locally.
- m009 stores nostr_event_id + nostr_event_created_at on each event
(used for replaceable updates and NIP-09 deletes); m011 adds location
+ JSON-encoded categories list (NIP-52 location/`t` tags).
- models: Event/PublicEvent/CreateEvent gain location, categories,
nostr_event_id, nostr_event_created_at; parse_categories validator
decodes the JSON column on read.
- nostr/{event,nostr_client}.py: Schnorr signing, websocket relay client,
and a NostrEvent model (publish-only and subscribe variants).
- nostr_publisher.py: build/sign NIP-52 kind 31922 events and NIP-09
delete events; publish via the relay client.
- nostr_sync.py: subscribe to kinds 31922/31923, dedupe by nostr_event_id
/ d-tag, upsert Events; auto-approves discovered Nostr events since
they're already public.
- nostr_hooks.py: thin bridge that views_api handlers call to publish
or delete a NIP-52 event for a given local event. Lives in its own
module to keep `from . import nostr_client` out of the view layer
and avoid the views_api -> publisher import cycle.
- views_api: hooks publish_or_delete_nostr_event into create-on-approved,
update-when-already-published, cancel (delete), delete (delete), and
approve (publish).
- __init__.py: 3-task lifespan — wait_for_paid_invoices (upstream),
NostrClient bootstrap, and the NIP-52 sync loop. Module-level
nostr_client global is set by the bootstrap and read dynamically by
publish_or_delete_nostr_event so the import order works regardless of
whether nostrclient is up at startup.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c7e95c5452
commit
6aa280680e
9 changed files with 575 additions and 5 deletions
21
models.py
21
models.py
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field, root_validator, validator
|
||||
|
|
@ -42,6 +43,8 @@ class CreateEvent(BaseModel):
|
|||
amount_tickets: int = 0 # 0 = unlimited / not ticketed
|
||||
price_per_ticket: float = 0 # 0 = free
|
||||
banner: str | None = None
|
||||
location: str | None = None # venue/address (NIP-52 'location' tag)
|
||||
categories: list[str] = Field(default_factory=list) # NIP-52 't' tags
|
||||
extra: EventExtra = Field(default_factory=EventExtra)
|
||||
status: str = "approved" # proposed, approved, rejected
|
||||
|
||||
|
|
@ -63,8 +66,18 @@ class Event(BaseModel):
|
|||
time: datetime
|
||||
sold: int = 0
|
||||
banner: str | None = None
|
||||
location: str | None = None
|
||||
categories: list[str] = Field(default_factory=list)
|
||||
extra: EventExtra = Field(default_factory=EventExtra)
|
||||
status: str = "approved"
|
||||
nostr_event_id: str | None = None
|
||||
nostr_event_created_at: int | None = None
|
||||
|
||||
@validator("categories", pre=True)
|
||||
def parse_categories(cls, v):
|
||||
if isinstance(v, str):
|
||||
return json.loads(v) if v else []
|
||||
return v or []
|
||||
|
||||
|
||||
class PublicEvent(BaseModel):
|
||||
|
|
@ -80,9 +93,17 @@ class PublicEvent(BaseModel):
|
|||
fiat_currency: str = "GBP"
|
||||
price_per_ticket: float
|
||||
banner: str | None
|
||||
location: str | None = None
|
||||
categories: list[str] = Field(default_factory=list)
|
||||
extra: EventExtra = Field(default_factory=EventExtra)
|
||||
status: str = "approved" # surfaces "proposed"/"rejected" so SFC can render banner
|
||||
|
||||
@validator("categories", pre=True)
|
||||
def parse_categories(cls, v):
|
||||
if isinstance(v, str):
|
||||
return json.loads(v) if v else []
|
||||
return v or []
|
||||
|
||||
|
||||
class EventsSettings(BaseModel):
|
||||
"""Extension-level settings for the events extension."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue