update to cashu 0.5.3 with db fix

This commit is contained in:
callebtc 2022-11-26 02:14:39 +01:00
parent d37d94f509
commit 0735b5bf7d
4 changed files with 11 additions and 192 deletions

View file

@ -42,25 +42,6 @@ async def create_cashu(
return cashu
# async def update_cashu_keys(cashu_id, wif: str = None) -> Optional[Cashu]:
# entropy = bytes([random.getrandbits(8) for i in range(16)])
# mnemonic = bip39.mnemonic_from_bytes(entropy)
# seed = bip39.mnemonic_to_seed(mnemonic)
# root = bip32.HDKey.from_seed(seed, version=NETWORKS["main"]["xprv"])
# bip44_xprv = root.derive("m/44h/1h/0h")
# bip44_xpub = bip44_xprv.to_public()
# await db.execute(
# "UPDATE cashu.cashu SET prv = ?, pub = ? WHERE id = ?",
# bip44_xprv.to_base58(),
# bip44_xpub.to_base58(),
# cashu_id,
# )
# row = await db.fetchone("SELECT * FROM cashu.cashu WHERE id = ?", (cashu_id,))
# return Cashu(**row) if row else None
async def get_cashu(cashu_id) -> Optional[Cashu]:
row = await db.fetchone("SELECT * FROM cashu.cashu WHERE id = ?", (cashu_id,))
return Cashu(**row) if row else None
@ -80,166 +61,3 @@ async def get_cashus(wallet_ids: Union[str, List[str]]) -> List[Cashu]:
async def delete_cashu(cashu_id) -> None:
await db.execute("DELETE FROM cashu.cashu WHERE id = ?", (cashu_id,))
# ##########################################
# ###############MINT STUFF#################
# ##########################################
# async def store_promises(
# amounts: List[int], B_s: List[str], C_s: List[str], cashu_id: str
# ):
# for amount, B_, C_ in zip(amounts, B_s, C_s):
# await store_promise(amount, B_, C_, cashu_id)
# async def store_promise(amount: int, B_: str, C_: str, cashu_id: str):
# promise_id = urlsafe_short_hash()
# await db.execute(
# """
# INSERT INTO cashu.promises
# (id, amount, B_b, C_b, cashu_id)
# VALUES (?, ?, ?, ?, ?)
# """,
# (promise_id, amount, str(B_), str(C_), cashu_id),
# )
# async def get_promises(cashu_id) -> Optional[Cashu]:
# row = await db.fetchall(
# "SELECT * FROM cashu.promises WHERE cashu_id = ?", (cashu_id,)
# )
# return Promises(**row) if row else None
# async def get_proofs_used(
# db: Database,
# conn: Optional[Connection] = None,
# ):
# rows = await (conn or db).fetchall(
# """
# SELECT secret from cashu.proofs_used
# """
# )
# return [row[0] for row in rows]
# async def invalidate_proof(cashu_id: str, proof: Proof):
# invalidate_proof_id = urlsafe_short_hash()
# await db.execute(
# """
# INSERT INTO cashu.proofs_used
# (id, amount, C, secret, cashu_id)
# VALUES (?, ?, ?, ?, ?)
# """,
# (invalidate_proof_id, proof.amount, str(proof.C), str(proof.secret), cashu_id),
# )
# ########################################
# ############ MINT INVOICES #############
# ########################################
# async def store_lightning_invoice(cashu_id: str, invoice: Invoice):
# await db.execute(
# """
# INSERT INTO cashu.invoices
# (cashu_id, amount, pr, hash, issued)
# VALUES (?, ?, ?, ?, ?)
# """,
# (
# cashu_id,
# invoice.amount,
# invoice.pr,
# invoice.hash,
# invoice.issued,
# ),
# )
# async def get_lightning_invoice(cashu_id: str, hash: str):
# row = await db.fetchone(
# """
# SELECT * from cashu.invoices
# WHERE cashu_id =? AND hash = ?
# """,
# (
# cashu_id,
# hash,
# ),
# )
# return Invoice.from_row(row)
# async def update_lightning_invoice(cashu_id: str, hash: str, issued: bool):
# await db.execute(
# "UPDATE cashu.invoices SET issued = ? WHERE cashu_id = ? AND hash = ?",
# (
# issued,
# cashu_id,
# hash,
# ),
# )
##############################
######### KEYSETS ############
##############################
# async def store_keyset(
# keyset: MintKeyset,
# db: Database = None,
# conn: Optional[Connection] = None,
# ):
# await (conn or db).execute( # type: ignore
# """
# INSERT INTO cashu.keysets
# (id, derivation_path, valid_from, valid_to, first_seen, active, version)
# VALUES (?, ?, ?, ?, ?, ?, ?)
# """,
# (
# keyset.id,
# keyset.derivation_path,
# keyset.valid_from or db.timestamp_now,
# keyset.valid_to or db.timestamp_now,
# keyset.first_seen or db.timestamp_now,
# True,
# keyset.version,
# ),
# )
# async def get_keyset(
# id: str = None,
# derivation_path: str = "",
# db: Database = None,
# conn: Optional[Connection] = None,
# ):
# clauses = []
# values: List[Any] = []
# clauses.append("active = ?")
# values.append(True)
# if id:
# clauses.append("id = ?")
# values.append(id)
# if derivation_path:
# clauses.append("derivation_path = ?")
# values.append(derivation_path)
# where = ""
# if clauses:
# where = f"WHERE {' AND '.join(clauses)}"
# rows = await (conn or db).fetchall( # type: ignore
# f"""
# SELECT * from cashu.keysets
# {where}
# """,
# tuple(values),
# )
# return [MintKeyset.from_row(row) for row in rows]

View file

@ -262,7 +262,7 @@ async def melt_coins(
# TOKENS
assert all([p.id == cashu.keyset_id for p in proofs]), HTTPException(
status_code=HTTPStatus.METHOD_NOT_ALLOWED,
detail="Tokens are from another mint.",
detail="Error: Tokens are from another mint.",
)
assert all([ledger._verify_proof(p) for p in proofs]), HTTPException(
@ -354,9 +354,10 @@ async def split(
# !!!!!!! MAKE SURE THAT PROOFS ARE ONLY FROM THIS CASHU KEYSET ID
# THIS IS NECESSARY BECAUSE THE CASHU BACKEND WILL ACCEPT ANY VALID
# TOKENS
assert all([p.id == cashu.keyset_id for p in proofs]), HTTPException(
if not all([p.id == cashu.keyset_id for p in proofs]):
raise HTTPException(
status_code=HTTPStatus.METHOD_NOT_ALLOWED,
detail="Tokens are from another mint.",
detail="Error: Tokens are from another mint.",
)
amount = payload.amount

8
poetry.lock generated
View file

@ -123,7 +123,7 @@ uvloop = ["uvloop (>=0.15.2)"]
[[package]]
name = "cashu"
version = "0.5.1"
version = "0.5.3"
description = "Ecash wallet and mint with Bitcoin Lightning support"
category = "main"
optional = false
@ -1144,7 +1144,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
[metadata]
lock-version = "1.1"
python-versions = "^3.10 | ^3.9 | ^3.8 | ^3.7"
content-hash = "c5d3b28864bf6b86385e38f63e3ba16d95804a812773e930b6ed818d4f09938a"
content-hash = "8d464511b1fad4883bc4745ab6b0e52ac9c2f67389194d3854245b5790ffb0a0"
[metadata.files]
aiofiles = [
@ -1208,8 +1208,8 @@ black = [
{file = "black-22.10.0.tar.gz", hash = "sha256:f513588da599943e0cde4e32cc9879e825d58720d6557062d1098c5ad80080e1"},
]
cashu = [
{file = "cashu-0.5.1-py3-none-any.whl", hash = "sha256:893f6bc098331e73cb6a5d0108c929dc7f2299d3d5405ae3b29e0868d9cd78c9"},
{file = "cashu-0.5.1.tar.gz", hash = "sha256:c4533c72a09b0e1439836739653d3d79a7de00a1106e6676cb8f660f894006a7"},
{file = "cashu-0.5.3-py3-none-any.whl", hash = "sha256:60acaa80a7ee18034e410e32e3df8a29ec335582d1fefa3c3df2e2d6693a4597"},
{file = "cashu-0.5.3.tar.gz", hash = "sha256:8f14c291e79b64cf30cff34e75f969741b1ab96be178fab0c9f9a4f764958533"},
]
Cerberus = [
{file = "Cerberus-1.3.4.tar.gz", hash = "sha256:d1b21b3954b2498d9a79edf16b3170a3ac1021df88d197dc2ce5928ba519237c"},

View file

@ -64,7 +64,7 @@ protobuf = "^4.21.6"
Cerberus = "^1.3.4"
async-timeout = "^4.0.2"
pyln-client = "0.11.1"
cashu = "^0.5.1"
cashu = "^0.5.3"
[tool.poetry.dev-dependencies]