Splitpayments booting, but not sure how to handle internal pays

This commit is contained in:
benarc
2021-10-18 13:02:28 +01:00
parent a574743080
commit 3285e9d3c9
3 changed files with 13 additions and 12 deletions

View File

@@ -8,11 +8,11 @@ from lnbits.tasks import catch_everything_and_restart
db = Database("ext_splitpayments") db = Database("ext_splitpayments")
copilot_static_files = [ splitpayments_static_files = [
{ {
"path": "/copilot/static", "path": "/splitpayments/static",
"app": StaticFiles(directory="lnbits/extensions/splitpayments/static"), "app": StaticFiles(directory="lnbits/extensions/splitpayments/static"),
"name": "copilot_static", "name": "splitpayments_static",
} }
] ]
splitpayments_ext: APIRouter = APIRouter( splitpayments_ext: APIRouter = APIRouter(

View File

@@ -3,7 +3,7 @@ import json
from lnbits.core.models import Payment from lnbits.core.models import Payment
from lnbits.core.crud import create_payment from lnbits.core.crud import create_payment
from lnbits.core import db as core_db from lnbits.core import db as core_db
from lnbits.tasks import register_invoice_listener, internal_invoice_paid from lnbits.tasks import register_invoice_listener # , internal_invoice_paid
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
from .crud import get_targets from .crud import get_targets
@@ -78,4 +78,5 @@ async def on_invoice_paid(payment: Payment) -> None:
) )
# manually send this for now # manually send this for now
await internal_invoice_paid.send(internal_checking_id) # await internal_invoice_paid.send(internal_checking_id)
return

View File

@@ -33,14 +33,14 @@ async def api_targets_set(
data: TargetPut, wallet: WalletTypeInfo = Depends(WalletAdminKeyChecker()) data: TargetPut, wallet: WalletTypeInfo = Depends(WalletAdminKeyChecker())
): ):
targets = [] targets = []
for entry in data["targets"]: for entry in data.targets:
wallet = await get_wallet(entry["wallet"]) wallet = await get_wallet(entry.wallet)
if not wallet: if not wallet:
wallet = await get_wallet_for_key(entry["wallet"], "invoice") wallet = await get_wallet_for_key(entry.wallet, "invoice")
if not wallet: if not wallet:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST, status_code=HTTPStatus.BAD_REQUEST,
detail=f"Invalid wallet '{entry['wallet']}'.", detail=f"Invalid wallet '{entry.wallet}'.",
) )
if wallet.id == wallet.wallet.id: if wallet.id == wallet.wallet.id:
@@ -49,14 +49,14 @@ async def api_targets_set(
detail="Can't split to itself.", detail="Can't split to itself.",
) )
if entry["percent"] < 0: if entry.percent < 0:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST, status_code=HTTPStatus.BAD_REQUEST,
detail=f"Invalid percent '{entry['percent']}'.", detail=f"Invalid percent '{entry.percent}'.",
) )
targets.append( targets.append(
Target(wallet.id, wallet.wallet.id, entry["percent"], entry["alias"] or "") Target(wallet.id, wallet.wallet.id, entry.percent, entry.alias or "")
) )
percent_sum = sum([target.percent for target in targets]) percent_sum = sum([target.percent for target in targets])