Added pydantic to models

This commit is contained in:
Ben Arc 2021-08-20 14:46:08 +01:00
parent c525655c15
commit 8dea1e28f0
18 changed files with 65 additions and 55 deletions

View file

@ -1,7 +1,9 @@
from typing import NamedTuple from sqlite3 import Row
from pydantic import BaseModel
#from typing import NamedTuple
class AMilk(NamedTuple): class AMilk(BaseModel):
id: str id: str
wallet: str wallet: str
lnurl: str lnurl: str

View file

@ -5,9 +5,11 @@ from lnbits import bolt11
from lnbits.core.services import pay_invoice from lnbits.core.services import pay_invoice
from . import db from . import db
from .helpers import get_callback_url, LnurlValidationError from .helpers import get_callback_url, LnurlValidationError
from sqlite3 import Row
from pydantic import BaseModel
class Bleskomat(NamedTuple): class Bleskomat(BaseModel):
id: str id: str
wallet: str wallet: str
api_key_id: str api_key_id: str
@ -19,7 +21,7 @@ class Bleskomat(NamedTuple):
fee: str fee: str
class BleskomatLnurl(NamedTuple): class BleskomatLnurl(BaseModel):
id: str id: str
bleskomat: str bleskomat: str
wallet: str wallet: str

View file

@ -1,10 +1,11 @@
import json import json
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple, Optional from pydantic import BaseModel
from typing import Optional
class Captcha(NamedTuple): class Captcha(BaseModel):
id: str id: str
wallet: str wallet: str
url: str url: str

View file

@ -5,9 +5,10 @@ from quart import url_for
from lnurl import Lnurl, encode as lnurl_encode # type: ignore from lnurl import Lnurl, encode as lnurl_encode # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore from lnurl.types import LnurlPayMetadata # type: ignore
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
from sqlite3 import Row
from pydantic import BaseModel
class Copilots(BaseModel):
class Copilots(NamedTuple):
id: str id: str
user: str user: str
title: str title: str

View file

@ -1,7 +1,8 @@
from typing import NamedTuple from typing import NamedTuple
from sqlite3 import Row
from pydantic import BaseModel
class Indexers(BaseModel):
class Indexers(NamedTuple):
id: str id: str
wallet: str wallet: str
shopname: str shopname: str
@ -15,7 +16,7 @@ class Indexers(NamedTuple):
email: str email: str
class Products(NamedTuple): class Products(BaseModel):
id: str id: str
wallet: str wallet: str
product: str product: str
@ -26,7 +27,7 @@ class Products(NamedTuple):
quantity: int quantity: int
class Orders(NamedTuple): class Orders(BaseModel):
id: str id: str
productid: str productid: str
wallet: str wallet: str

View file

@ -1,8 +1,8 @@
from typing import NamedTuple
from sqlite3 import Row from sqlite3 import Row
from pydantic import BaseModel
class Jukebox(NamedTuple): class Jukebox(BaseModel):
id: str id: str
user: str user: str
title: str title: str
@ -22,7 +22,7 @@ class Jukebox(NamedTuple):
return cls(**dict(row)) return cls(**dict(row))
class JukeboxPayment(NamedTuple): class JukeboxPayment(BaseModel):
payment_hash: str payment_hash: str
juke_id: str juke_id: str
song_id: str song_id: str

View file

@ -1,12 +1,13 @@
import json import json
from quart import url_for from quart import url_for
from typing import NamedTuple, Optional from typing import Optional
from lnurl import Lnurl, encode as lnurl_encode # type: ignore from lnurl import Lnurl, encode as lnurl_encode # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore from lnurl.types import LnurlPayMetadata # type: ignore
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
from sqlite3 import Row
from pydantic import BaseModel
class Livestream(BaseModel):
class Livestream(NamedTuple):
id: int id: int
wallet: str wallet: str
fee_pct: int fee_pct: int
@ -18,7 +19,7 @@ class Livestream(NamedTuple):
return lnurl_encode(url) return lnurl_encode(url)
class Track(NamedTuple): class Track(BaseModel):
id: int id: int
download_url: str download_url: str
price_msat: int price_msat: int
@ -74,7 +75,7 @@ class Track(NamedTuple):
) )
class Producer(NamedTuple): class Producer(BaseModel):
id: int id: int
user: str user: str
wallet: str wallet: str

View file

@ -1,7 +1,6 @@
from typing import NamedTuple from pydantic import BaseModel
class Forms(BaseModel):
class Forms(NamedTuple):
id: str id: str
wallet: str wallet: str
name: str name: str
@ -13,7 +12,7 @@ class Forms(NamedTuple):
time: int time: int
class Tickets(NamedTuple): class Tickets(BaseModel):
id: str id: str
form: str form: str
email: str email: str

View file

@ -1,13 +1,13 @@
import json import json
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
from quart import url_for from quart import url_for
from typing import NamedTuple, Optional, Dict from typing import Optional, Dict
from sqlite3 import Row
from lnbits.lnurl import encode as lnurl_encode # type: ignore from lnbits.lnurl import encode as lnurl_encode # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore from lnurl.types import LnurlPayMetadata # type: ignore
from sqlite3 import Row
from pydantic import BaseModel
class PayLink(BaseModel):
class PayLink(NamedTuple):
id: int id: int
wallet: str wallet: str
description: str description: str

View file

@ -3,17 +3,17 @@ import base64
import hashlib import hashlib
from collections import OrderedDict from collections import OrderedDict
from quart import url_for from quart import url_for
from typing import NamedTuple, Optional, List, Dict from typing import Optional, List, Dict
from lnurl import encode as lnurl_encode # type: ignore from lnurl import encode as lnurl_encode # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore from lnurl.types import LnurlPayMetadata # type: ignore
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
from pydantic import BaseModel
from .helpers import totp from .helpers import totp
shop_counters: Dict = {} shop_counters: Dict = {}
class ShopCounter(object): class ShopCounter(BaseModel):
fulfilled_payments: OrderedDict fulfilled_payments: OrderedDict
counter: int counter: int
@ -54,7 +54,7 @@ class ShopCounter(object):
return word return word
class Shop(NamedTuple): class Shop(BaseModel):
id: int id: int
wallet: str wallet: str
method: str method: str
@ -77,7 +77,7 @@ class Shop(NamedTuple):
return "" return ""
class Item(NamedTuple): class Item(BaseModel):
shop: int shop: int
id: int id: int
name: str name: str

View file

@ -1,10 +1,11 @@
import json import json
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple, Optional from pydantic import BaseModel
from typing import Optional
class Paywall(NamedTuple): class Paywall(BaseModel):
id: str id: str
wallet: str wallet: str
url: str url: str

View file

@ -1,9 +1,9 @@
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple from pydantic import BaseModel
import time import time
class Charges(NamedTuple): class Charges(BaseModel):
id: str id: str
user: str user: str
description: str description: str

View file

@ -1,7 +1,8 @@
from typing import NamedTuple
from pydantic import BaseModel
class Target(NamedTuple): class Target(BaseModel):
wallet: str wallet: str
source: str source: str
percent: int percent: int

View file

@ -1,8 +1,9 @@
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple, Optional from pydantic import BaseModel
from typing import Optional
class Donation(NamedTuple): class Donation(BaseModel):
"""A Donation simply contains all the necessary information about a """A Donation simply contains all the necessary information about a
user's donation to a streamer user's donation to a streamer
""" """
@ -22,7 +23,7 @@ class Donation(NamedTuple):
return cls(**dict(row)) return cls(**dict(row))
class Service(NamedTuple): class Service(BaseModel):
"""A Service represents an integration with a third-party API """A Service represents an integration with a third-party API
Currently, Streamlabs is the only supported Service. Currently, Streamlabs is the only supported Service.

View file

@ -1,7 +1,7 @@
from typing import NamedTuple
from pydantic import BaseModel
class Domains(NamedTuple): class Domains(BaseModel):
id: str id: str
wallet: str wallet: str
domain: str domain: str
@ -15,7 +15,7 @@ class Domains(NamedTuple):
allowed_record_types: str allowed_record_types: str
class Subdomains(NamedTuple): class Subdomains(BaseModel):
id: str id: str
wallet: str wallet: str
domain: str domain: str

View file

@ -1,8 +1,8 @@
from typing import NamedTuple
from sqlite3 import Row from sqlite3 import Row
from pydantic import BaseModel
class Users(NamedTuple): class Users(BaseModel):
id: str id: str
name: str name: str
admin: str admin: str
@ -10,7 +10,7 @@ class Users(NamedTuple):
password: str password: str
class Wallets(NamedTuple): class Wallets(BaseModel):
id: str id: str
admin: str admin: str
name: str name: str

View file

@ -1,8 +1,8 @@
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple from pydantic import BaseModel
class Wallets(NamedTuple): class Wallets(BaseModel):
id: str id: str
user: str user: str
masterpub: str masterpub: str
@ -15,7 +15,7 @@ class Wallets(NamedTuple):
return cls(**dict(row)) return cls(**dict(row))
class Mempool(NamedTuple): class Mempool(BaseModel):
user: str user: str
endpoint: str endpoint: str
@ -24,7 +24,7 @@ class Mempool(NamedTuple):
return cls(**dict(row)) return cls(**dict(row))
class Addresses(NamedTuple): class Addresses(BaseModel):
id: str id: str
address: str address: str
wallet: str wallet: str

View file

@ -1,11 +1,11 @@
from quart import url_for from quart import url_for
from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode # type: ignore from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode # type: ignore
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple from pydantic import BaseModel
import shortuuid # type: ignore import shortuuid # type: ignore
class WithdrawLink(NamedTuple): class WithdrawLink(BaseModel):
id: str id: str
wallet: str wallet: str
title: str title: str
@ -67,7 +67,7 @@ class WithdrawLink(NamedTuple):
) )
class HashCheck(NamedTuple): class HashCheck(BaseModel):
id: str id: str
lnurl_id: str lnurl_id: str