mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-12 06:02:16 +02:00
No idea why satsdice isnt working
This commit is contained in:
@ -66,9 +66,6 @@ async def get_satsdice_pay(link_id: str) -> Optional[satsdiceLink]:
|
|||||||
async def get_satsdice_pays(wallet_ids: Union[str, List[str]]) -> List[satsdiceLink]:
|
async def get_satsdice_pays(wallet_ids: Union[str, List[str]]) -> List[satsdiceLink]:
|
||||||
if isinstance(wallet_ids, str):
|
if isinstance(wallet_ids, str):
|
||||||
wallet_ids = [wallet_ids]
|
wallet_ids = [wallet_ids]
|
||||||
print("wallet_ids")
|
|
||||||
print(wallet_ids)
|
|
||||||
print("wallet_ids")
|
|
||||||
|
|
||||||
q = ",".join(["?"] * len(wallet_ids))
|
q = ",".join(["?"] * len(wallet_ids))
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
|
@ -157,43 +157,22 @@ async def api_lnurlw_callback(
|
|||||||
k1: str = Query(None),
|
k1: str = Query(None),
|
||||||
pr: str = Query(None),
|
pr: str = Query(None),
|
||||||
):
|
):
|
||||||
|
|
||||||
link = await get_satsdice_withdraw_by_hash(unique_hash)
|
link = await get_satsdice_withdraw_by_hash(unique_hash)
|
||||||
paylink = await get_satsdice_pay(link.satsdice_pay)
|
|
||||||
payment_request = pr
|
|
||||||
now = int(datetime.now().timestamp())
|
|
||||||
|
|
||||||
if not link:
|
if not link:
|
||||||
raise HTTPException(
|
return {"status": "ERROR", "reason": "no withdraw"}
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-satsdice not found."
|
|
||||||
)
|
|
||||||
|
|
||||||
if link.used:
|
if link.used:
|
||||||
raise HTTPException(status_code=HTTPStatus.OK, detail="satsdice is spent.")
|
return {"status": "ERROR", "reason": "spent"}
|
||||||
|
|
||||||
if link.k1 != k1:
|
paylink = await get_satsdice_pay(link.satsdice_pay)
|
||||||
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST, detail="Bad request..")
|
|
||||||
|
|
||||||
if now < link.open_time:
|
await update_satsdice_withdraw(link.id, used=1)
|
||||||
return {"status": "ERROR", "reason": f"Wait {link.open_time - now} seconds."}
|
print("cunt")
|
||||||
|
await pay_invoice(
|
||||||
try:
|
wallet_id=paylink.wallet,
|
||||||
await update_satsdice_withdraw(link.id, used=1)
|
payment_request=pr,
|
||||||
|
max_sat=link.value,
|
||||||
await pay_invoice(
|
extra={"tag": "withdraw"},
|
||||||
wallet_id=paylink.wallet,
|
)
|
||||||
payment_request=payment_request,
|
|
||||||
max_sat=link.value,
|
|
||||||
extra={"tag": "withdraw"},
|
|
||||||
)
|
|
||||||
|
|
||||||
except ValueError as e:
|
|
||||||
await update_satsdice_withdraw(link.id, used=1)
|
|
||||||
return {"status": "ERROR", "reason": str(e)}
|
|
||||||
except PermissionError:
|
|
||||||
await update_satsdice_withdraw(link.id, used=1)
|
|
||||||
return {"status": "ERROR", "reason": "satsdice link is empty."}
|
|
||||||
except Exception as e:
|
|
||||||
await update_satsdice_withdraw(link.id, used=1)
|
|
||||||
return {"status": "ERROR", "reason": str(e)}
|
|
||||||
|
|
||||||
return {"status": "OK"}
|
return {"status": "OK"}
|
||||||
|
@ -63,8 +63,6 @@ async def displaywin(
|
|||||||
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
|
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
await api_payment(payment_hash)
|
|
||||||
|
|
||||||
withdrawLink = await get_satsdice_withdraw(payment_hash)
|
withdrawLink = await get_satsdice_withdraw(payment_hash)
|
||||||
if withdrawLink:
|
if withdrawLink:
|
||||||
return satsdice_renderer().TemplateResponse(
|
return satsdice_renderer().TemplateResponse(
|
||||||
@ -79,58 +77,24 @@ async def displaywin(
|
|||||||
"lost": False,
|
"lost": False,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
rand = random.randint(0, 100)
|
||||||
payment = await get_standalone_payment(payment_hash) or abort(
|
chance = satsdicelink.chance
|
||||||
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
|
print(rand)
|
||||||
)
|
print(chance)
|
||||||
|
print(rand < chance)
|
||||||
if payment.pending == 1:
|
status = await api_payment(payment_hash)
|
||||||
await api_payment(payment_hash)
|
if not rand < chance or not status["paid"]:
|
||||||
payment = await get_standalone_payment(payment_hash) or abort(
|
return satsdice_renderer().TemplateResponse(
|
||||||
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
|
"satsdice/error.html",
|
||||||
|
{
|
||||||
|
"request": request,
|
||||||
|
"link": satsdicelink.id,
|
||||||
|
"paid": False,
|
||||||
|
"lost": True,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if payment.pending == 1:
|
|
||||||
return satsdice_renderer().TemplateResponse(
|
|
||||||
"satsdice/error.html",
|
|
||||||
{
|
|
||||||
"request": request,
|
|
||||||
"link": satsdicelink.id,
|
|
||||||
"paid": False,
|
|
||||||
"lost": True,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
await update_satsdice_payment(payment_hash, paid=1)
|
await update_satsdice_payment(payment_hash, paid=1)
|
||||||
paylink = await get_satsdice_payment(payment_hash)
|
paylink = await get_satsdice_payment(payment_hash)
|
||||||
if not paylink:
|
|
||||||
|
|
||||||
return satsdice_renderer().TemplateResponse(
|
|
||||||
"satsdice/error.html",
|
|
||||||
{
|
|
||||||
"request": request,
|
|
||||||
"link": satsdicelink.id,
|
|
||||||
"paid": False,
|
|
||||||
"lost": True,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
rand1 = random.randint(0, 100)
|
|
||||||
rand2 = random.randint(0, 100)
|
|
||||||
rand3 = random.randint(0, 100)
|
|
||||||
rand4 = random.randint(0, 100)
|
|
||||||
rand = (rand1 + rand2 + rand3 + rand4) / 4
|
|
||||||
print(rand)
|
|
||||||
chance = satsdicelink.chance
|
|
||||||
if rand > chance:
|
|
||||||
await update_satsdice_payment(payment_hash, lost=1)
|
|
||||||
return satsdice_renderer().TemplateResponse(
|
|
||||||
"satsdice/error.html",
|
|
||||||
{
|
|
||||||
"request": request,
|
|
||||||
"link": satsdicelink.id,
|
|
||||||
"paid": False,
|
|
||||||
"lost": True,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
data: CreateSatsDiceWithdraw = {
|
data: CreateSatsDiceWithdraw = {
|
||||||
"satsdice_pay": satsdicelink.id,
|
"satsdice_pay": satsdicelink.id,
|
||||||
|
Reference in New Issue
Block a user