nostrclient/models.py
Vlad Stan 16ae9d15a1
Stabilize (#24)
* refactor: clean-up

* refactor: extra logs plus try-catch

* refactor: do not use bare `except`

* refactor: clean-up redundant fields

* chore: pass code checks

* chore: code format

* refactor: code clean-up

* fix: refactoring stuff

* refactor: remove un-used file

* chore: code clean-up

* chore: code clean-up

* chore: code-format fix

* refactor: remove nostr.client wrapper

* refactor: code clean-up

* chore: code format

* refactor: remove `RelayList` class

* refactor: extract smaller methods with try-catch

* fix: better exception handling

* fix: remove redundant filters

* fix: simplify event

* chore: code format

* fix: code check

* fix: code check

* fix: simplify `REQ`

* fix: more clean-ups

* refactor: use simpler method

* refactor: re-order and rename

* fix: stop logic

* fix: subscription close before disconnect

* chore: play commit
2023-11-01 17:46:42 +02:00

44 lines
1 KiB
Python

from sqlite3 import Row
from typing import List, Optional
from pydantic import BaseModel
from lnbits.helpers import urlsafe_short_hash
class RelayStatus(BaseModel):
num_sent_events: Optional[int] = 0
num_received_events: Optional[int] = 0
error_counter: Optional[int] = 0
error_list: Optional[List] = []
notice_list: Optional[List] = []
class Relay(BaseModel):
id: Optional[str] = None
url: Optional[str] = None
connected: Optional[bool] = None
connected_string: Optional[str] = None
status: Optional[RelayStatus] = None
active: Optional[bool] = None
ping: Optional[int] = None
def _init__(self):
if not self.id:
self.id = urlsafe_short_hash()
@classmethod
def from_row(cls, row: Row) -> "Relay":
return cls(**dict(row))
class TestMessage(BaseModel):
sender_private_key: Optional[str]
reciever_public_key: str
message: str
class TestMessageResponse(BaseModel):
private_key: str
public_key: str
event_json: str