From c110715f28aa3db7f872e93a3907403f0572c081 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:16:30 +0200 Subject: [PATCH 1/7] save lightning invoices --- cashu/core/base.py | 105 ++++--------------------------------- cashu/mint/crud.py | 4 +- cashu/wallet/cli.py | 16 +++--- cashu/wallet/crud.py | 84 +++++++++++++++++++++++++++-- cashu/wallet/migrations.py | 34 +++++++----- cashu/wallet/wallet.py | 29 ++++++++-- 6 files changed, 144 insertions(+), 128 deletions(-) diff --git a/cashu/core/base.py b/cashu/core/base.py index 7db5eb2..5a94360 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -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()) diff --git a/cashu/mint/crud.py b/cashu/mint/crud.py index 6ce7120..e07d2f2 100644 --- a/cashu/mint/crud.py +++ b/cashu/mint/crud.py @@ -135,7 +135,7 @@ async def get_lightning_invoice( """, (hash,), ) - return Invoice.from_row(row) + return Invoice(**row) async def update_lightning_invoice( @@ -204,4 +204,4 @@ async def get_keyset( """, tuple(values), ) - return [MintKeyset.from_row(row) for row in rows] + return [MintKeyset(**row) for row in rows] diff --git a/cashu/wallet/cli.py b/cashu/wallet/cli.py index 9e906dc..719e02a 100755 --- a/cashu/wallet/cli.py +++ b/cashu/wallet/cli.py @@ -85,14 +85,14 @@ async def invoice(ctx, amount: int, hash: str): if not LIGHTNING: r = await wallet.mint(amount) elif amount and not hash: - r = await wallet.request_mint(amount) - if "pr" in r: + invoice = await wallet.request_mint(amount) + if invoice.pr: print(f"Pay invoice to mint {amount} sat:") print("") - print(f"Invoice: {r['pr']}") + print(f"Invoice: {invoice.pr}") print("") print( - f"Execute this command if you abort the check:\ncashu invoice {amount} --hash {r['hash']}" + f"Execute this command if you abort the check:\ncashu invoice {amount} --hash {invoice.hash}" ) check_until = time.time() + 5 * 60 # check for five minutes print("") @@ -105,7 +105,7 @@ async def invoice(ctx, amount: int, hash: str): while time.time() < check_until and not paid: time.sleep(3) try: - await wallet.mint(amount, r["hash"]) + await wallet.mint(amount, invoice.hash) paid = True print(" Invoice paid.") except Exception as e: @@ -221,7 +221,7 @@ async def receive(ctx, coin: str, lock: str): signature = p2shscripts[0].signature else: script, signature = None, None - proofs = [Proof.from_dict(p) for p in json.loads(base64.urlsafe_b64decode(coin))] + proofs = [Proof(**p) for p in json.loads(base64.urlsafe_b64decode(coin))] _, _ = await wallet.redeem(proofs, scnd_script=script, scnd_siganture=signature) wallet.status() @@ -250,9 +250,7 @@ async def burn(ctx, coin: str, all: bool, force: bool): proofs = wallet.proofs else: # check only the specified ones - proofs = [ - Proof.from_dict(p) for p in json.loads(base64.urlsafe_b64decode(coin)) - ] + proofs = [Proof(**p) for p in json.loads(base64.urlsafe_b64decode(coin))] wallet.status() await wallet.invalidate(proofs) wallet.status() diff --git a/cashu/wallet/crud.py b/cashu/wallet/crud.py index d6f8c47..ed0f3b4 100644 --- a/cashu/wallet/crud.py +++ b/cashu/wallet/crud.py @@ -1,7 +1,7 @@ import time from typing import Any, List, Optional -from cashu.core.base import KeyBase, P2SHScript, Proof, WalletKeyset +from cashu.core.base import Invoice, KeyBase, P2SHScript, Proof, WalletKeyset from cashu.core.db import Connection, Database @@ -31,7 +31,7 @@ async def get_proofs( SELECT * from proofs """ ) - return [Proof.from_row(r) for r in rows] + return [Proof(**dict(r)) for r in rows] async def get_reserved_proofs( @@ -45,7 +45,7 @@ async def get_reserved_proofs( WHERE reserved """ ) - return [Proof.from_row(r) for r in rows] + return [Proof(**r) for r in rows] async def invalidate_proof( @@ -162,7 +162,7 @@ async def get_unused_locks( """, tuple(args), ) - return [P2SHScript.from_row(r) for r in rows] + return [P2SHScript(**r) for r in rows] async def update_p2sh_used( @@ -233,4 +233,78 @@ async def get_keyset( """, tuple(values), ) - return WalletKeyset.from_row(row) if row is not None else None + return WalletKeyset(**row) if row is not None else None + + +async def store_lightning_invoice( + db: Database, + invoice: Invoice, + conn: Optional[Connection] = None, +): + + await (conn or db).execute( + f""" + INSERT INTO invoices + (amount, pr, hash, preimage, paid, time_created, time_paid) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, + ( + invoice.amount, + invoice.pr, + invoice.hash, + invoice.preimage, + invoice.paid, + invoice.time_created, + invoice.time_paid, + ), + ) + + +async def get_lightning_invoice( + db: Database, + hash: str = None, + conn: Optional[Connection] = None, +): + clauses = [] + values: List[Any] = [] + if hash: + clauses.append("hash = ?") + values.append(hash) + + where = "" + if clauses: + where = f"WHERE {' AND '.join(clauses)}" + + row = await (conn or db).fetchone( + f""" + SELECT * from invoices + {where} + """, + (hash,), + ) + return Invoice(**row) + + +async def update_lightning_invoice( + db: Database, + hash: str, + paid: bool, + time_paid: int = None, + conn: Optional[Connection] = None, +): + clauses = [] + values: List[Any] = [] + clauses.append("paid = ?") + values.append(paid) + + if time_paid: + clauses.append("time_paid = ?") + values.append(time_paid) + + await (conn or db).execute( + f"UPDATE invoices SET {', '.join(clauses)} WHERE hash = ?", + ( + *values, + hash, + ), + ) diff --git a/cashu/wallet/migrations.py b/cashu/wallet/migrations.py index 0a0a73e..2bf9a3a 100644 --- a/cashu/wallet/migrations.py +++ b/cashu/wallet/migrations.py @@ -119,18 +119,28 @@ async def m005_wallet_keysets(db: Database): ); """ ) - # await db.execute( - # f""" - # CREATE TABLE IF NOT EXISTS mint_pubkeys ( - # id TEXT NOT NULL, - # amount INTEGER NOT NULL, - # pubkey TEXT NOT NULL, - - # UNIQUE (id, pubkey) - - # ); - # """ - # ) await db.execute("ALTER TABLE proofs ADD COLUMN id TEXT") await db.execute("ALTER TABLE proofs_used ADD COLUMN id TEXT") + + +async def m006_invoices(db: Database): + """ + Stores Lightning invoices. + """ + await db.execute( + f""" + CREATE TABLE IF NOT EXISTS invoices ( + amount INTEGER NOT NULL, + pr TEXT NOT NULL, + hash TEXT, + preimage TEXT, + paid BOOL DEFAULT FALSE, + time_created TIMESTAMP DEFAULT {db.timestamp_now}, + time_paid TIMESTAMP DEFAULT {db.timestamp_now}, + + UNIQUE (hash) + + ); + """ + ) diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index aacf92d..8c55e68 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -1,6 +1,7 @@ import base64 import json import secrets as scrts +import time import uuid from itertools import groupby from typing import Dict, List @@ -14,6 +15,7 @@ from cashu.core.base import ( BlindedSignature, CheckFeesRequest, CheckRequest, + Invoice, MeltRequest, MintRequest, P2SHScript, @@ -38,8 +40,10 @@ from cashu.wallet.crud import ( invalidate_proof, secret_used, store_keyset, + store_lightning_invoice, store_p2sh, store_proof, + update_lightning_invoice, update_proof_reserved, ) @@ -175,7 +179,7 @@ class LedgerAPI: resp.raise_for_status() return_dict = resp.json() self.raise_on_error(return_dict) - return return_dict + return Invoice(amount=amount, pr=return_dict["pr"], hash=return_dict["hash"]) async def mint(self, amounts, payment_hash=None): """Mints new coins and returns a proof of promise.""" @@ -192,7 +196,7 @@ class LedgerAPI: promises_list = resp.json() self.raise_on_error(promises_list) - promises = [BlindedSignature.from_dict(p) for p in promises_list] + promises = [BlindedSignature(**p) for p in promises_list] return self._construct_proofs(promises, secrets, rs) async def split(self, proofs, amount, scnd_secret: str = None): @@ -246,8 +250,8 @@ class LedgerAPI: promises_dict = resp.json() self.raise_on_error(promises_dict) - promises_fst = [BlindedSignature.from_dict(p) for p in promises_dict["fst"]] - promises_snd = [BlindedSignature.from_dict(p) for p in promises_dict["snd"]] + promises_fst = [BlindedSignature(**p) for p in promises_dict["fst"]] + promises_snd = [BlindedSignature(**p) for p in promises_dict["snd"]] # Construct proofs from promises (i.e., unblind signatures) frst_proofs = self._construct_proofs( promises_fst, secrets[: len(promises_fst)], rs[: len(promises_fst)] @@ -340,7 +344,10 @@ class Wallet(LedgerAPI): return {key: list(group) for key, group in groupby(proofs, lambda p: p.id)} async def request_mint(self, amount): - return super().request_mint(amount) + invoice = super().request_mint(amount) + invoice.time_created = int(time.time()) + await store_lightning_invoice(db=self.db, invoice=invoice) + return invoice async def mint(self, amount: int, payment_hash: str = None): split = amount_split(amount) @@ -348,6 +355,10 @@ class Wallet(LedgerAPI): if proofs == []: raise Exception("received no proofs.") await self._store_proofs(proofs) + if payment_hash: + await update_lightning_invoice( + db=self.db, hash=payment_hash, paid=True, time_paid=int(time.time()) + ) self.proofs += proofs return proofs @@ -389,6 +400,14 @@ class Wallet(LedgerAPI): status = await super().pay_lightning(proofs, invoice) if status["paid"] == True: await self.invalidate(proofs) + invoice_obj = Invoice( + amount=-sum_proofs(proofs), + pr=invoice, + preimage=status.get("preimage"), + paid=True, + time_paid=time.time(), + ) + await store_lightning_invoice(db=self.db, invoice=invoice_obj) else: raise Exception("could not pay invoice.") return status["paid"] From a58458b3a239ec7b122d369f175c546396791857 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:41:25 +0200 Subject: [PATCH 2/7] new command: invoices --- README.md | 2 +- cashu/core/settings.py | 2 +- cashu/wallet/cli.py | 41 ++++++++++++++++++++++++++++++++++++++++- cashu/wallet/crud.py | 28 +++++++++++++++++++++++++++- pyproject.toml | 2 +- setup.py | 2 +- 6 files changed, 71 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 45e7eeb..2299159 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ cashu info Returns: ```bash -Version: 0.4.0 +Version: 0.4.1 Debug: False Cashu dir: /home/user/.cashu Wallet: wallet diff --git a/cashu/core/settings.py b/cashu/core/settings.py index 15f9a1d..3ab3bc7 100644 --- a/cashu/core/settings.py +++ b/cashu/core/settings.py @@ -48,4 +48,4 @@ LNBITS_ENDPOINT = env.str("LNBITS_ENDPOINT", default=None) LNBITS_KEY = env.str("LNBITS_KEY", default=None) MAX_ORDER = 64 -VERSION = "0.4.0" +VERSION = "0.4.1" diff --git a/cashu/wallet/cli.py b/cashu/wallet/cli.py index 719e02a..1588427 100755 --- a/cashu/wallet/cli.py +++ b/cashu/wallet/cli.py @@ -24,7 +24,11 @@ from cashu.core.helpers import fee_reserve, sum_proofs from cashu.core.migrations import migrate_databases from cashu.core.settings import CASHU_DIR, DEBUG, ENV_FILE, LIGHTNING, MINT_URL, VERSION from cashu.wallet import migrations -from cashu.wallet.crud import get_reserved_proofs, get_unused_locks +from cashu.wallet.crud import ( + get_reserved_proofs, + get_unused_locks, + get_lightning_invoices, +) from cashu.wallet.wallet import Wallet as Wallet @@ -328,6 +332,41 @@ async def locks(ctx): return True +@cli.command("invoices", help="List of all pending invoices.") +@click.pass_context +@coro +async def invoices(ctx): + wallet: Wallet = ctx.obj["WALLET"] + invoices = await get_lightning_invoices(db=wallet.db) + if len(invoices): + print("") + print(f"--------------------------\n") + for invoice in invoices: + print(f"Paid: {invoice.paid}") + print(f"Incoming: {invoice.amount > 0}") + print(f"Amount: {abs(invoice.amount)}") + if invoice.hash: + print(f"Hash: {invoice.hash}") + if invoice.preimage: + print(f"Preimage: {invoice.preimage}") + if invoice.time_created: + d = datetime.utcfromtimestamp( + int(float(invoice.time_created)) + ).strftime("%Y-%m-%d %H:%M:%S") + print(f"Created: {d}") + if invoice.time_paid: + d = datetime.utcfromtimestamp(int(float(invoice.time_paid))).strftime( + "%Y-%m-%d %H:%M:%S" + ) + print(f"Paid: {d}") + print("") + print(f"Payment request: {invoice.pr}") + print("") + print(f"--------------------------\n") + else: + print("No invoices found.") + + @cli.command("wallets", help="List of all available wallets.") @click.pass_context @coro diff --git a/cashu/wallet/crud.py b/cashu/wallet/crud.py index ed0f3b4..25a46f8 100644 --- a/cashu/wallet/crud.py +++ b/cashu/wallet/crud.py @@ -280,11 +280,37 @@ async def get_lightning_invoice( SELECT * from invoices {where} """, - (hash,), + tuple(values), ) return Invoice(**row) +async def get_lightning_invoices( + db: Database, + paid: bool = None, + conn: Optional[Connection] = None, +): + clauses: List[Any] = [] + values: List[Any] = [] + + if paid is not None: + clauses.append("paid = ?") + values.append(paid) + + where = "" + if clauses: + where = f"WHERE {' AND '.join(clauses)}" + + rows = await (conn or db).fetchall( + f""" + SELECT * from invoices + {where} + """, + tuple(values), + ) + return [Invoice(**r) for r in rows] + + async def update_lightning_invoice( db: Database, hash: str, diff --git a/pyproject.toml b/pyproject.toml index d96b757..963a5ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cashu" -version = "0.4.0" +version = "0.4.1" description = "Ecash wallet and mint." authors = ["calle "] license = "MIT" diff --git a/setup.py b/setup.py index 1769ca8..cde2042 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ entry_points = {"console_scripts": ["cashu = cashu.wallet.cli:cli"]} setuptools.setup( name="cashu", - version="0.4.0", + version="0.4.1", description="Ecash wallet and mint with Bitcoin Lightning support", long_description=long_description, long_description_content_type="text/markdown", From 9875ad636ed2f1a0ce521a9ac88a1c01360a6831 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:50:52 +0200 Subject: [PATCH 3/7] disable codecov --- .github/codecov.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/codecov.yml diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..b966124 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,9 @@ +coverage: + status: + patch: off + project: + default: + target: auto + # adjust accordingly based on how flaky your tests are + # this allows a 10% drop from the previous base commit coverage + threshold: 10% From 32058ccc65dc303cd311b920faebd90c06cfeb7e Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:52:27 +0200 Subject: [PATCH 4/7] make format --- cashu/wallet/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cashu/wallet/cli.py b/cashu/wallet/cli.py index 1588427..3bd4bd1 100755 --- a/cashu/wallet/cli.py +++ b/cashu/wallet/cli.py @@ -25,9 +25,9 @@ from cashu.core.migrations import migrate_databases from cashu.core.settings import CASHU_DIR, DEBUG, ENV_FILE, LIGHTNING, MINT_URL, VERSION from cashu.wallet import migrations from cashu.wallet.crud import ( + get_lightning_invoices, get_reserved_proofs, get_unused_locks, - get_lightning_invoices, ) from cashu.wallet.wallet import Wallet as Wallet From d8b4e592e8c9dc30a0a37e3af481253f570ed661 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:44:08 +0200 Subject: [PATCH 5/7] refactor cli --- cashu/wallet/cli.py | 11 ++--------- cashu/wallet/wallet.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cashu/wallet/cli.py b/cashu/wallet/cli.py index 3bd4bd1..b500c99 100755 --- a/cashu/wallet/cli.py +++ b/cashu/wallet/cli.py @@ -134,17 +134,10 @@ async def pay(ctx, invoice: str, yes: bool): wallet: Wallet = ctx.obj["WALLET"] await wallet.load_mint() wallet.status() - decoded_invoice: Invoice = bolt11.decode(invoice) - - # check if it's an internal payment - fees = (await wallet.check_fees(invoice))["fee"] - amount = math.ceil( - (decoded_invoice.amount_msat + fees * 1000) / 1000 - ) # 1% fee for Lightning - + amount, fees = await wallet.get_pay_amount_with_fees(invoice) if not yes: click.confirm( - f"Pay {decoded_invoice.amount_msat//1000} sat ({amount} sat incl. fees)?", + f"Pay {amount - fees} sat ({amount} sat incl. fees)?", abort=True, default=True, ) diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index 8c55e68..b1c3338 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -3,11 +3,14 @@ import json import secrets as scrts import time import uuid +import math from itertools import groupby from typing import Dict, List import requests from loguru import logger +import cashu.core.bolt11 as bolt11 +from cashu.core.bolt11 import Invoice as InvoiceBolt11 import cashu.core.b_dhke as b_dhke from cashu.core.base import ( @@ -436,6 +439,25 @@ class Wallet(LedgerAPI): proofs = [p for p in proofs if not p.reserved] return proofs + async def get_pay_amount_with_fees(self, invoice: str): + """ + Decodes the amount from a Lightning invoice and returns the + total amount (amount+fees) to be paid. + """ + decoded_invoice: InvoiceBolt11 = bolt11.decode(invoice) + # check if it's an internal payment + fees = int((await self.check_fees(invoice))["fee"]) + amount = math.ceil((decoded_invoice.amount_msat + fees * 1000) / 1000) # 1% fee + return amount, fees + + async def split_to_pay(self, invoice: str): + """ + Splits proofs such that a Lightning invoice can be paid. + """ + amount, _ = await self.get_pay_amount_with_fees(invoice) + _, send_proofs = await self.split_to_send(self.proofs, amount) + return send_proofs + async def split_to_send( self, proofs: List[Proof], From fedc32d81dd6ae0d729136d5fc8e3db3ab921aa7 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:44:55 +0200 Subject: [PATCH 6/7] make format --- cashu/wallet/cli.py | 5 +---- cashu/wallet/wallet.py | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cashu/wallet/cli.py b/cashu/wallet/cli.py index b500c99..683959a 100755 --- a/cashu/wallet/cli.py +++ b/cashu/wallet/cli.py @@ -3,7 +3,6 @@ import asyncio import base64 import json -import math import os import sys import time @@ -17,10 +16,8 @@ from os.path import isdir, join import click from loguru import logger -import cashu.core.bolt11 as bolt11 from cashu.core.base import Proof -from cashu.core.bolt11 import Invoice, decode -from cashu.core.helpers import fee_reserve, sum_proofs +from cashu.core.helpers import sum_proofs from cashu.core.migrations import migrate_databases from cashu.core.settings import CASHU_DIR, DEBUG, ENV_FILE, LIGHTNING, MINT_URL, VERSION from cashu.wallet import migrations diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index b1c3338..011aeb9 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -1,18 +1,17 @@ import base64 import json +import math import secrets as scrts import time import uuid -import math from itertools import groupby from typing import Dict, List import requests from loguru import logger -import cashu.core.bolt11 as bolt11 -from cashu.core.bolt11 import Invoice as InvoiceBolt11 import cashu.core.b_dhke as b_dhke +import cashu.core.bolt11 as bolt11 from cashu.core.base import ( BlindedMessage, BlindedSignature, @@ -26,6 +25,7 @@ from cashu.core.base import ( SplitRequest, WalletKeyset, ) +from cashu.core.bolt11 import Invoice as InvoiceBolt11 from cashu.core.db import Database from cashu.core.helpers import sum_proofs from cashu.core.script import ( From 41acd32fc4c81f3b342f27e3a512c1d004b3c750 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 18 Oct 2022 18:11:22 +0200 Subject: [PATCH 7/7] turn off recurse for env --- cashu/core/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cashu/core/settings.py b/cashu/core/settings.py index 3ab3bc7..441d873 100644 --- a/cashu/core/settings.py +++ b/cashu/core/settings.py @@ -14,7 +14,7 @@ if os.path.isfile(ENV_FILE): env.read_env(ENV_FILE) else: ENV_FILE = "" - env.read_env() + env.read_env(recurse=False) DEBUG = env.bool("DEBUG", default=False) if not DEBUG: