cleanup
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
from lnbits.core import db as core_db
|
||||
from lnbits.core.crud import create_payment
|
||||
from lnbits.core.models import Payment
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
from lnbits.tasks import internal_invoice_queue, register_invoice_listener
|
||||
from lnbits.tasks import register_invoice_listener
|
||||
|
||||
from .crud import get_cashu
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append("/Users/cc/git/cashu")
|
||||
from cashu.mint import migrations
|
||||
from cashu.core.migrations import migrate_databases
|
||||
from . import db, ledger
|
||||
@@ -35,51 +29,6 @@ async def wait_for_paid_invoices():
|
||||
|
||||
|
||||
async def on_invoice_paid(payment: Payment) -> None:
|
||||
if payment.extra.get("tag") == "cashu" and payment.extra.get("tipSplitted"):
|
||||
# already splitted, ignore
|
||||
if not payment.extra.get("tag") == "cashu":
|
||||
return
|
||||
|
||||
# now we make some special internal transfers (from no one to the receiver)
|
||||
cashu = await get_cashu(payment.extra.get("cashuId"))
|
||||
tipAmount = payment.extra.get("tipAmount")
|
||||
|
||||
if tipAmount is None:
|
||||
# no tip amount
|
||||
return
|
||||
|
||||
tipAmount = tipAmount * 1000
|
||||
amount = payment.amount - tipAmount
|
||||
|
||||
# mark the original payment with one extra key, "splitted"
|
||||
# (this prevents us from doing this process again and it's informative)
|
||||
# and reduce it by the amount we're going to send to the producer
|
||||
await core_db.execute(
|
||||
"""
|
||||
UPDATE apipayments
|
||||
SET extra = ?, amount = ?
|
||||
WHERE hash = ?
|
||||
AND checking_id NOT LIKE 'internal_%'
|
||||
""",
|
||||
(
|
||||
json.dumps(dict(**payment.extra, tipSplitted=True)),
|
||||
amount,
|
||||
payment.payment_hash,
|
||||
),
|
||||
)
|
||||
|
||||
# perform the internal transfer using the same payment_hash
|
||||
internal_checking_id = f"internal_{urlsafe_short_hash()}"
|
||||
await create_payment(
|
||||
wallet_id=cashu.tip_wallet,
|
||||
checking_id=internal_checking_id,
|
||||
payment_request="",
|
||||
payment_hash=payment.payment_hash,
|
||||
amount=tipAmount,
|
||||
memo=f"Tip for {payment.memo}",
|
||||
pending=False,
|
||||
extra={"tipSplitted": True},
|
||||
)
|
||||
|
||||
# manually send this for now
|
||||
await internal_invoice_queue.put(internal_checking_id)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user