mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-15 23:31:44 +02:00
No idea why satsdice isnt working
This commit is contained in:
parent
fd79815c83
commit
f58775a78f
@ -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]:
|
||||
if isinstance(wallet_ids, str):
|
||||
wallet_ids = [wallet_ids]
|
||||
print("wallet_ids")
|
||||
print(wallet_ids)
|
||||
print("wallet_ids")
|
||||
|
||||
q = ",".join(["?"] * len(wallet_ids))
|
||||
rows = await db.fetchall(
|
||||
|
@ -157,43 +157,22 @@ async def api_lnurlw_callback(
|
||||
k1: str = Query(None),
|
||||
pr: str = Query(None),
|
||||
):
|
||||
|
||||
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:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-satsdice not found."
|
||||
)
|
||||
|
||||
return {"status": "ERROR", "reason": "no withdraw"}
|
||||
if link.used:
|
||||
raise HTTPException(status_code=HTTPStatus.OK, detail="satsdice is spent.")
|
||||
return {"status": "ERROR", "reason": "spent"}
|
||||
|
||||
if link.k1 != k1:
|
||||
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST, detail="Bad request..")
|
||||
paylink = await get_satsdice_pay(link.satsdice_pay)
|
||||
|
||||
if now < link.open_time:
|
||||
return {"status": "ERROR", "reason": f"Wait {link.open_time - now} seconds."}
|
||||
|
||||
try:
|
||||
await update_satsdice_withdraw(link.id, used=1)
|
||||
|
||||
await pay_invoice(
|
||||
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)}
|
||||
await update_satsdice_withdraw(link.id, used=1)
|
||||
print("cunt")
|
||||
await pay_invoice(
|
||||
wallet_id=paylink.wallet,
|
||||
payment_request=pr,
|
||||
max_sat=link.value,
|
||||
extra={"tag": "withdraw"},
|
||||
)
|
||||
|
||||
return {"status": "OK"}
|
||||
|
@ -63,8 +63,6 @@ async def displaywin(
|
||||
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
|
||||
)
|
||||
|
||||
await api_payment(payment_hash)
|
||||
|
||||
withdrawLink = await get_satsdice_withdraw(payment_hash)
|
||||
if withdrawLink:
|
||||
return satsdice_renderer().TemplateResponse(
|
||||
@ -79,58 +77,24 @@ async def displaywin(
|
||||
"lost": False,
|
||||
},
|
||||
)
|
||||
|
||||
payment = await get_standalone_payment(payment_hash) or abort(
|
||||
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
|
||||
)
|
||||
|
||||
if payment.pending == 1:
|
||||
await api_payment(payment_hash)
|
||||
payment = await get_standalone_payment(payment_hash) or abort(
|
||||
HTTPStatus.NOT_FOUND, "satsdice link does not exist."
|
||||
rand = random.randint(0, 100)
|
||||
chance = satsdicelink.chance
|
||||
print(rand)
|
||||
print(chance)
|
||||
print(rand < chance)
|
||||
status = await api_payment(payment_hash)
|
||||
if not rand < chance or not status["paid"]:
|
||||
return satsdice_renderer().TemplateResponse(
|
||||
"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)
|
||||
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 = {
|
||||
"satsdice_pay": satsdicelink.id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user