|
|
@ -1,8 +1,9 @@ |
|
|
|
from flask import url_for |
|
|
|
from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode |
|
|
|
from os import getenv |
|
|
|
from typing import NamedTuple |
|
|
|
|
|
|
|
from lnbits.settings import FORCE_HTTPS |
|
|
|
|
|
|
|
|
|
|
|
class WithdrawLink(NamedTuple): |
|
|
|
id: str |
|
|
@ -22,19 +23,15 @@ class WithdrawLink(NamedTuple): |
|
|
|
def is_spent(self) -> bool: |
|
|
|
return self.used >= self.uses |
|
|
|
|
|
|
|
@property |
|
|
|
def is_onion(self) -> bool: |
|
|
|
return getenv("LNBITS_WITH_ONION", 1) == 1 |
|
|
|
|
|
|
|
@property |
|
|
|
def lnurl(self) -> Lnurl: |
|
|
|
scheme = None if self.is_onion else "https" |
|
|
|
scheme = "https" if FORCE_HTTPS else None |
|
|
|
url = url_for("withdraw.api_lnurl_response", unique_hash=self.unique_hash, _external=True, _scheme=scheme) |
|
|
|
return lnurl_encode(url) |
|
|
|
|
|
|
|
@property |
|
|
|
def lnurl_response(self) -> LnurlWithdrawResponse: |
|
|
|
scheme = None if self.is_onion else "https" |
|
|
|
scheme = "https" if FORCE_HTTPS else None |
|
|
|
url = url_for("withdraw.api_lnurl_callback", unique_hash=self.unique_hash, _external=True, _scheme=scheme) |
|
|
|
|
|
|
|
return LnurlWithdrawResponse( |
|
|
|