2021-10-14 11:45:30 +01:00
|
|
|
from sqlite3 import Row
|
2022-07-14 14:15:11 +03:00
|
|
|
from typing import List, Optional
|
2021-10-14 22:30:47 +01:00
|
|
|
from fastapi.param_functions import Query
|
|
|
|
from pydantic import BaseModel
|
2021-10-14 11:45:30 +01:00
|
|
|
|
2021-10-17 18:33:29 +01:00
|
|
|
|
2021-10-14 22:30:47 +01:00
|
|
|
class CreateWallet(BaseModel):
|
|
|
|
masterpub: str = Query("")
|
|
|
|
title: str = Query("")
|
2021-10-14 11:45:30 +01:00
|
|
|
|
2021-10-17 18:33:29 +01:00
|
|
|
|
2022-07-04 17:40:47 +03:00
|
|
|
class WalletAccount(BaseModel):
|
2021-10-14 11:45:30 +01:00
|
|
|
id: str
|
|
|
|
user: str
|
|
|
|
masterpub: str
|
2022-07-04 17:40:47 +03:00
|
|
|
fingerprint: str
|
2021-10-14 11:45:30 +01:00
|
|
|
title: str
|
|
|
|
address_no: int
|
|
|
|
balance: int
|
2022-07-04 17:40:47 +03:00
|
|
|
type: str = ""
|
2022-08-01 10:45:31 +03:00
|
|
|
network: str = "Mainnet"
|
2021-10-14 11:45:30 +01:00
|
|
|
|
|
|
|
@classmethod
|
2022-07-04 17:40:47 +03:00
|
|
|
def from_row(cls, row: Row) -> "WalletAccount":
|
2021-10-14 11:45:30 +01:00
|
|
|
return cls(**dict(row))
|
|
|
|
|
|
|
|
|
2022-07-04 17:40:47 +03:00
|
|
|
### TODO: fix statspay dependcy and remove
|
2021-10-14 22:30:47 +01:00
|
|
|
class Mempool(BaseModel):
|
2021-10-14 11:45:30 +01:00
|
|
|
user: str
|
|
|
|
endpoint: str
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_row(cls, row: Row) -> "Mempool":
|
|
|
|
return cls(**dict(row))
|
|
|
|
|
|
|
|
|
2022-07-04 17:40:47 +03:00
|
|
|
class Address(BaseModel):
|
2021-10-14 11:45:30 +01:00
|
|
|
id: str
|
|
|
|
address: str
|
|
|
|
wallet: str
|
2022-07-04 17:40:47 +03:00
|
|
|
amount: int = 0
|
|
|
|
branch_index: int = 0
|
|
|
|
address_index: int
|
|
|
|
note: str = None
|
|
|
|
has_activity: bool = False
|
2021-10-14 11:45:30 +01:00
|
|
|
|
|
|
|
@classmethod
|
2022-07-04 17:40:47 +03:00
|
|
|
def from_row(cls, row: Row) -> "Address":
|
2021-10-14 11:45:30 +01:00
|
|
|
return cls(**dict(row))
|
2022-07-04 17:40:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
class TransactionInput(BaseModel):
|
|
|
|
tx_id: str
|
|
|
|
vout: int
|
|
|
|
amount: int
|
|
|
|
address: str
|
|
|
|
branch_index: int
|
|
|
|
address_index: int
|
|
|
|
masterpub_fingerprint: str
|
|
|
|
tx_hex: str
|
|
|
|
|
|
|
|
|
|
|
|
class TransactionOutput(BaseModel):
|
|
|
|
amount: int
|
|
|
|
address: str
|
|
|
|
branch_index: int = None
|
|
|
|
address_index: int = None
|
|
|
|
masterpub_fingerprint: str = None
|
|
|
|
|
|
|
|
|
|
|
|
class MasterPublicKey(BaseModel):
|
|
|
|
public_key: str
|
|
|
|
fingerprint: str
|
|
|
|
|
|
|
|
|
|
|
|
class CreatePsbt(BaseModel):
|
|
|
|
masterpubs: List[MasterPublicKey]
|
|
|
|
inputs: List[TransactionInput]
|
|
|
|
outputs: List[TransactionOutput]
|
|
|
|
fee_rate: int
|
|
|
|
tx_size: int
|
|
|
|
|
|
|
|
|
2022-07-14 14:15:11 +03:00
|
|
|
class ExtractPsbt(BaseModel):
|
2022-07-15 09:02:50 +03:00
|
|
|
psbtBase64 = "" # // todo snake case
|
2022-07-19 18:48:39 +03:00
|
|
|
inputs: List[TransactionInput]
|
2022-07-14 14:15:11 +03:00
|
|
|
|
|
|
|
|
|
|
|
class SignedTransaction(BaseModel):
|
|
|
|
tx_hex: Optional[str]
|
|
|
|
tx_json: Optional[str]
|
|
|
|
|
|
|
|
|
2022-07-15 09:02:50 +03:00
|
|
|
class BroadcastTransaction(BaseModel):
|
|
|
|
tx_hex: str
|
|
|
|
|
|
|
|
|
2022-07-04 17:40:47 +03:00
|
|
|
class Config(BaseModel):
|
|
|
|
mempool_endpoint = "https://mempool.space"
|
|
|
|
receive_gap_limit = 20
|
|
|
|
change_gap_limit = 5
|
|
|
|
sats_denominated = True
|
2022-08-01 10:45:31 +03:00
|
|
|
network = "Mainnet"
|