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",