Merge pull request #8 from lnbits/code_format_23.03.2023

chore: code format
This commit is contained in:
calle 2023-03-23 10:01:21 +01:00 committed by GitHub
commit a24dbc0a4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 31 deletions

View file

@ -2,6 +2,4 @@
`nostrclient` is an always-on extension that can open multiple connections to nostr relays and act as a multiplexer for other clients: You open a single websocket to `nostrclient` which then sends the data to multiple relays. The responses from these relays are then sent back to the client.
![2023-03-08 18 11 07](https://user-images.githubusercontent.com/93376500/225265727-369f0f8a-196e-41df-a0d1-98b50a0228be.jpg)

View file

@ -1,8 +1,9 @@
from fastapi import APIRouter
from starlette.staticfiles import StaticFiles
from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
from starlette.staticfiles import StaticFiles
db = Database("ext_nostrclient")

View file

@ -1,6 +1,7 @@
from typing import List, Optional, Union
import shortuuid
from lnbits.helpers import urlsafe_short_hash
from . import db

View file

@ -3,9 +3,10 @@ from typing import Dict, List, Optional
from fastapi import Request
from fastapi.param_functions import Query
from lnbits.helpers import urlsafe_short_hash
from pydantic import BaseModel, Field
from lnbits.helpers import urlsafe_short_hash
class Relay(BaseModel):
id: Optional[str] = None

View file

@ -3,16 +3,16 @@ import json
from typing import List, Union
from fastapi import WebSocket, WebSocketDisconnect
from lnbits.helpers import urlsafe_short_hash
from .nostr.client.client import NostrClient as NostrClientLib
from .models import Event, Filter, Filters, Relay, RelayList
from .nostr.client.client import NostrClient as NostrClientLib
from .nostr.event import Event as NostrEvent
from .nostr.filter import Filter as NostrFilter
from .nostr.filter import Filters as NostrFilters
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
received_subscription_events: dict[str, list[Event]] = {}
received_subscription_notices: dict[str, list[NoticeMessage]] = {}
received_subscription_eosenotices: dict[str, EndOfStoredEventsMessage] = {}

View file

@ -2,20 +2,18 @@ import asyncio
import ssl
import threading
from .crud import get_relays
from .nostr.event import Event
from .nostr.key import PublicKey
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
from .nostr.relay_manager import RelayManager
from .services import (
nostr,
received_subscription_events,
received_subscription_eosenotices,
received_subscription_events,
)
from .crud import get_relays
async def init_relays():
# reinitialize the entire client
nostr.__init__()

View file

@ -75,11 +75,16 @@
</q-tr>
</template>
</q-table>
</q-card-section>
<q-card-section>
<div class="text-weight-bold"> Your endpoint:
<q-badge outline class="q-ml-sm text-subtitle2" color="primary" :label="`wss://${host}/nostrclient/api/v1/relay`" />
<div class="text-weight-bold">
Your endpoint:
<q-badge
outline
class="q-ml-sm text-subtitle2"
color="primary"
:label="`wss://${host}/nostrclient/api/v1/relay`"
/>
</div>
</q-card-section>
</q-card>
@ -88,7 +93,13 @@
<q-form class="q-gutter-md q-y-md" @submit="addRelay">
<div class="row">
<div class="col q-mx-md q-my-sm">
<q-input outlined v-model="relayToAdd" dense filled label="Relay URL"></q-input>
<q-input
outlined
v-model="relayToAdd"
dense
filled
label="Relay URL"
></q-input>
</div>
<div class="col q-mx-md items-align flex items-center justify-right">
<q-btn unelevated color="primary" type="submit">Add relay </q-btn>
@ -104,17 +115,20 @@
<h6 class="text-subtitle1 q-my-none">Nostrclient Extension</h6>
<p>
This extension is a always-on nostr client that other extensions can
use to send and receive events on nostr.
use to send and receive events on nostr. Add multiple nostr relays to
connect to. The extension then opens a websocket for you to use at
</p>
Add multiple nostr relays to connect to. The extension then opens a websocket for you to use
at
<p>
<!-- wss://{{host}}nostrclient/api/v1/relay -->
<q-badge outline class="q-ml-sm text-subtitle2" color="primary" :label="`wss://${host}/nostrclient/api/v1/relay`" />
</p>
Only Admin users can manage
this extension.
<q-badge
outline
class="q-ml-sm text-subtitle2"
color="primary"
:label="`wss://${host}/nostrclient/api/v1/relay`"
/>
</p>
Only Admin users can manage this extension.
<q-card-section></q-card-section>
</q-card-section>
</q-card>
@ -217,7 +231,7 @@
message: `Invalid relay URL.`,
caption: "Should start with 'wss://'' or 'ws://'"
})
return false;
return false
}
console.log('ADD RELAY ' + this.relayToAdd)
let that = this
@ -229,7 +243,7 @@
{url: this.relayToAdd}
)
.then(function (response) {
console.log("response:", response)
console.log('response:', response)
if (response.data) {
response.data.map(maplrelays)
that.nostrrelayLinks = response.data
@ -239,7 +253,7 @@
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
return false;
return false
},
deleteRelay(url) {
console.log('DELETE RELAY ' + url)

View file

@ -6,11 +6,12 @@ from fastapi import Request
from fastapi.param_functions import Query
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.responses import HTMLResponse
from lnbits.core.crud import update_payment_status
from lnbits.core.models import User
from lnbits.core.views.api import api_payment
from lnbits.decorators import check_admin, check_user_exists
from starlette.responses import HTMLResponse
from . import nostr_renderer, nostrclient_ext

View file

@ -3,11 +3,12 @@ from http import HTTPStatus
from typing import Optional
from fastapi import Depends, WebSocket
from lnbits.decorators import check_admin
from lnbits.helpers import urlsafe_short_hash
from loguru import logger
from starlette.exceptions import HTTPException
from lnbits.decorators import check_admin
from lnbits.helpers import urlsafe_short_hash
from . import nostrclient_ext
from .crud import add_relay, delete_relay, get_relays
from .models import Relay, RelayList