async def lnurl_response(ls_id): ls = await get_livestream(ls_id) if not ls: return jsonify({"status": "ERROR", "reason": "Livestream not found."}) track = await get_track(ls.current_track) if not track: return jsonify({ "status": "ERROR", "reason": "This livestream is offline." }) resp = LnurlPayResponse( callback=url_for("livestream.lnurl_callback", track_id=track.id, _external=True), min_sendable=track.min_sendable, max_sendable=track.max_sendable, metadata=await track.lnurlpay_metadata(), ) params = resp.dict() params["commentAllowed"] = 300 return jsonify(params)
async def api_lnurl_response(link_id): link = await increment_pay_link(link_id, served_meta=1) if not link: return ( jsonify({ "status": "ERROR", "reason": "LNURL-pay not found." }), HTTPStatus.OK, ) rate = await get_fiat_rate_satoshis(link.currency) if link.currency else 1 resp = LnurlPayResponse( callback=url_for("lnurlp.api_lnurl_callback", link_id=link.id, _external=True), min_sendable=math.ceil(link.min * rate) * 1000, max_sendable=round(link.max * rate) * 1000, metadata=link.lnurlpay_metadata, ) params = resp.dict() if link.comment_chars > 0: params["commentAllowed"] = link.comment_chars return jsonify(params), HTTPStatus.OK
def api_lnurl_response(link_id): link = increment_pay_link(link_id, served_meta=1) if not link: return jsonify({"status": "ERROR", "reason": "LNURL-pay not found."}), HTTPStatus.OK scheme = "https" if FORCE_HTTPS else None url = url_for("lnurlp.api_lnurl_callback", link_id=link.id, _external=True, _scheme=scheme) resp = LnurlPayResponse( callback=url, min_sendable=link.amount * 1000, max_sendable=link.amount * 1000, metadata=link.lnurlpay_metadata, ) return jsonify(resp.dict()), HTTPStatus.OK
async def lnurl_response(cp_id): cp = await get_copilot(cp_id) if not cp: return jsonify({"status": "ERROR", "reason": "Copilot not found."}) resp = LnurlPayResponse( callback=url_for("copilot.lnurl_callback", cp_id=cp_id, _external=True), min_sendable=10000, max_sendable=50000000, metadata=LnurlPayMetadata( json.dumps([["text/plain", str(cp.lnurl_title)]])), ) params = resp.dict() if cp.show_message: params["commentAllowed"] = 300 return jsonify(params)
async def lnurl_response(nonce, pos_id, payload): pos = await get_lnurlpos(pos_id) if not pos: return jsonify({"status": "ERROR", "reason": "lnurlpos not found."}) nonce1 = bytes.fromhex(nonce) payload1 = bytes.fromhex(payload) h = hashlib.sha256(nonce1) h.update(pos.key.encode()) s = h.digest() res = bytearray(payload1) for i in range(len(res)): res[i] = res[i] ^ s[i] decryptedAmount = float(int.from_bytes(res[2:6], "little") / 100) decryptedPin = int.from_bytes(res[:2], "little") if type(decryptedAmount) != float: return jsonify({"status": "ERROR", "reason": "Not an amount."}) price_msat = (await fiat_amount_as_satoshis(decryptedAmount, pos.currency) if pos.currency != "sat" else pos.currency) * 1000 lnurlpospayment = await create_lnurlpospayment(posid=pos.id, payload=payload, sats=price_msat, pin=decryptedPin) if not lnurlpospayment: return jsonify({ "status": "ERROR", "reason": "Could not create payment" }) resp = LnurlPayResponse( callback=url_for( "lnurlpos.lnurl_callback", paymentid=lnurlpospayment.id, _external=True, ), min_sendable=price_msat, max_sendable=price_msat, metadata=LnurlPayMetadata(json.dumps([["text/plain", str(pos.title)]])), ) params = resp.dict() return jsonify(params)
async def lnurl_response(item_id): item = await get_item(item_id) if not item: return jsonify({"status": "ERROR", "reason": "Item not found."}) if not item.enabled: return jsonify({"status": "ERROR", "reason": "Item disabled."}) price_msat = (await fiat_amount_as_satoshis(item.price, item.unit) if item.unit != "sat" else item.price) * 1000 resp = LnurlPayResponse( callback=url_for("offlineshop.lnurl_callback", item_id=item.id, _external=True), min_sendable=price_msat, max_sendable=price_msat, metadata=await item.lnurlpay_metadata(), ) return jsonify(resp.dict())
async def api_lnurlp_response(link_id): link = await get_satsdice_pay(link_id) if not link: return ( jsonify({ "status": "ERROR", "reason": "LNURL-payy not found." }), HTTPStatus.OK, ) resp = LnurlPayResponse( callback=url_for("satsdice.api_lnurlp_callback", link_id=link.id, _external=True), min_sendable=math.ceil(link.min_bet * 1) * 1000, max_sendable=round(link.max_bet * 1) * 1000, metadata=link.lnurlpay_metadata, ) params = resp.dict() return jsonify(params), HTTPStatus.OK