fee reserve fix

This commit is contained in:
callebtc
2022-09-17 01:36:33 +03:00
parent e878893146
commit 3591a6fe71
2 changed files with 8 additions and 5 deletions

View File

@@ -155,13 +155,13 @@ class Ledger:
await update_lightning_invoice(payment_hash, issued=True, db=self.db) await update_lightning_invoice(payment_hash, issued=True, db=self.db)
return status.paid return status.paid
async def _pay_lightning_invoice(self, invoice): async def _pay_lightning_invoice(self, invoice, amount):
"""Returns an invoice from the Lightning backend.""" """Returns an invoice from the Lightning backend."""
error, balance = await WALLET.status() error, balance = await WALLET.status()
if error: if error:
raise Exception(f"Lightning wallet not responding: {error}") raise Exception(f"Lightning wallet not responding: {error}")
ok, checking_id, fee_msat, preimage, error_message = await WALLET.pay_invoice( ok, checking_id, fee_msat, preimage, error_message = await WALLET.pay_invoice(
invoice, fee_limit_msat=10 invoice, fee_limit_msat=amount * (1 - LIGHTNING_FEE)
) )
return ok, preimage return ok, preimage
@@ -217,7 +217,7 @@ class Ledger:
"provided proofs not enough for Lightning payment." "provided proofs not enough for Lightning payment."
) )
status, preimage = await self._pay_lightning_invoice(invoice) status, preimage = await self._pay_lightning_invoice(invoice, amount)
if status == True: if status == True:
await self._invalidate_proofs(proofs) await self._invalidate_proofs(proofs)
return status, preimage return status, preimage

View File

@@ -72,7 +72,10 @@ async def mint(ctx, amount: int, hash: str):
if "pr" in r: if "pr" in r:
print(f"Pay this invoice to mint {amount} sat:") print(f"Pay this invoice to mint {amount} sat:")
print(f"Invoice: {r['pr']}") print(f"Invoice: {r['pr']}")
print(f"Hash: {r['hash']}") print("")
print(
f"After paying the invoice, run this command:\ncashu mint {amount} --hash {r['hash']}"
)
elif amount and hash: elif amount and hash:
await wallet.mint(amount, hash) await wallet.mint(amount, hash)
wallet.status() wallet.status()
@@ -142,7 +145,7 @@ async def pay(ctx, invoice: str):
decoded_invoice.amount_msat / 1000 * LIGHTNING_FEE decoded_invoice.amount_msat / 1000 * LIGHTNING_FEE
) # 1% fee for Lightning ) # 1% fee for Lightning
print( print(
f"Paying Lightning invoice of {decoded_invoice.amount_msat // 1000} sat ({amount} sat with fees)" f"Paying Lightning invoice of {decoded_invoice.amount_msat // 1000} sat ({amount} sat incl. fees)"
) )
assert amount > 0, "amount is not positive" assert amount > 0, "amount is not positive"
if wallet.available_balance < amount: if wallet.available_balance < amount: