save lightning invoices

This commit is contained in:
callebtc
2022-10-18 11:16:30 +02:00
parent 990e46fbb0
commit c110715f28
6 changed files with 144 additions and 128 deletions

View File

@@ -12,15 +12,6 @@ class P2SHScript(BaseModel):
signature: str
address: Union[str, None] = None
@classmethod
def from_row(cls, row: Row):
return cls(
address=row[0],
script=row[1],
signature=row[2],
used=row[3],
)
class Proof(BaseModel):
id: str = ""
@@ -28,36 +19,10 @@ class Proof(BaseModel):
secret: str = ""
C: str = ""
script: Union[P2SHScript, None] = None
reserved: bool = False # whether this proof is reserved for sending
send_id: str = "" # unique ID of send attempt
time_created: str = ""
time_reserved: str = ""
@classmethod
def from_row(cls, row: Row):
return cls(
amount=row[0],
C=row[1],
secret=row[2],
reserved=row[3] or False,
send_id=row[4] or "",
time_created=row[5] or "",
time_reserved=row[6] or "",
id=row[7] or "",
)
@classmethod
def from_dict(cls, d: dict):
assert "amount" in d, "no amount in proof"
return cls(
amount=d.get("amount"),
C=d.get("C"),
secret=d.get("secret") or "",
reserved=d.get("reserved") or False,
send_id=d.get("send_id") or "",
time_created=d.get("time_created") or "",
time_reserved=d.get("time_reserved") or "",
)
reserved: Union[None, bool] = False # whether this proof is reserved for sending
send_id: Union[None, str] = "" # unique ID of send attempt
time_created: Union[None, str] = ""
time_reserved: Union[None, str] = ""
def to_dict(self):
return dict(id=self.id, amount=self.amount, secret=self.secret, C=self.C)
@@ -81,17 +46,12 @@ class Proofs(BaseModel):
class Invoice(BaseModel):
amount: int
pr: str
hash: str
issued: bool = False
@classmethod
def from_row(cls, row: Row):
return cls(
amount=int(row[0]),
pr=str(row[1]),
hash=str(row[2]),
issued=bool(row[3]),
)
hash: Union[None, str] = None
preimage: Union[str, None] = None
issued: Union[None, bool] = False
paid: Union[None, bool] = False
time_created: Union[None, str, int, float] = ""
time_paid: Union[None, str, int, float] = ""
class BlindedMessage(BaseModel):
@@ -104,14 +64,6 @@ class BlindedSignature(BaseModel):
amount: int
C_: str
@classmethod
def from_dict(cls, d: dict):
return cls(
id=d.get("id"),
amount=d["amount"],
C_=d["C_"],
)
class MintRequest(BaseModel):
blinded_messages: List[BlindedMessage] = []
@@ -173,16 +125,6 @@ class KeyBase(BaseModel):
amount: int
pubkey: str
@classmethod
def from_row(cls, row: Row):
if row is None:
return cls
return cls(
id=row[0],
amount=int(row[1]),
pubkey=row[2],
)
class WalletKeyset:
id: str
@@ -213,19 +155,6 @@ class WalletKeyset:
self.public_keys = pubkeys
self.id = derive_keyset_id(self.public_keys)
@classmethod
def from_row(cls, row: Row):
if row is None:
return cls
return cls(
id=row[0],
mint_url=row[1],
valid_from=row[2],
valid_to=row[3],
first_seen=row[4],
active=row[5],
)
class MintKeyset:
id: str
@@ -266,20 +195,6 @@ class MintKeyset:
self.public_keys = derive_pubkeys(self.private_keys)
self.id = derive_keyset_id(self.public_keys)
@classmethod
def from_row(cls, row: Row):
if row is None:
return cls
return cls(
id=row[0],
derivation_path=row[1],
valid_from=row[2],
valid_to=row[3],
first_seen=row[4],
active=row[5],
version=row[6],
)
def get_keybase(self):
return {
k: KeyBase(id=self.id, amount=k, pubkey=v.serialize().hex())