mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 19:14:19 +01:00
new command: invoices
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "cashu"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
description = "Ecash wallet and mint."
|
||||
authors = ["calle <callebtc@protonmail.com>"]
|
||||
license = "MIT"
|
||||
|
||||
2
setup.py
2
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",
|
||||
|
||||
Reference in New Issue
Block a user