mirror of https://github.com/lukechilds/lnbits.git
Eneko Illarramendi
5 years ago
5 changed files with 70 additions and 22 deletions
@ -1,2 +1,6 @@ |
|||
FLASK_APP=lnbits |
|||
FLASK_ENV=development |
|||
|
|||
LNTXBOT_API_ENDPOINT=https://lntxbot.bigsun.xyz/ |
|||
LNTXBOT_ADMIN_KEY=LNTXBOT_ADMIN_KEY |
|||
LNTXBOT_INVOICE_KEY=LNTXBOT_INVOICE_KEY |
|||
|
@ -1,8 +1,16 @@ |
|||
import os |
|||
|
|||
INVOICE_KEY = os.getenv("INVOICE_KEY") |
|||
ADMIN_KEY = os.getenv("ADMIN_KEY") |
|||
API_ENDPOINT = os.getenv("API_ENDPOINT") |
|||
from .wallets import LntxbotWallet # OR LndHubWallet |
|||
|
|||
|
|||
WALLET = LntxbotWallet( |
|||
endpoint=os.getenv("LNTXBOT_API_ENDPOINT"), |
|||
admin_key=os.getenv("LNTXBOT_ADMIN_KEY"), |
|||
invoice_key=os.getenv("LNTXBOT_INVOICE_KEY"), |
|||
) |
|||
|
|||
# OR |
|||
# WALLET = LndHubWallet(uri=os.getenv("LNDHUB_URI")) |
|||
|
|||
LNBITS_PATH = os.path.dirname(os.path.realpath(__file__)) |
|||
DATABASE_PATH= os.getenv("DATABASE_PATH") or os.path.join(LNBITS_PATH, "data", "database.sqlite3") |
|||
DATABASE_PATH = os.getenv("DATABASE_PATH") or os.path.join(LNBITS_PATH, "data", "database.sqlite3") |
|||
|
@ -0,0 +1,45 @@ |
|||
import requests |
|||
|
|||
from abc import ABC, abstractmethod |
|||
from requests import Response |
|||
|
|||
|
|||
class WalletResponse(Response): |
|||
"""TODO: normalize different wallet responses |
|||
""" |
|||
|
|||
|
|||
class Wallet(ABC): |
|||
@abstractmethod |
|||
def create_invoice(self, amount: int, memo: str = "") -> WalletResponse: |
|||
pass |
|||
|
|||
@abstractmethod |
|||
def pay_invoice(self, bolt11: str) -> WalletResponse: |
|||
pass |
|||
|
|||
def get_invoice_status(self, payment_hash: str) -> WalletResponse: |
|||
pass |
|||
|
|||
|
|||
class LndHubWallet(Wallet): |
|||
def __init__(self, *, uri: str): |
|||
raise NotImplementedError |
|||
|
|||
|
|||
class LntxbotWallet(Wallet): |
|||
def __init__(self, *, endpoint: str, admin_key: str, invoice_key: str) -> WalletResponse: |
|||
self.endpoint = endpoint |
|||
self.auth_admin = {"Authorization": f"Basic {admin_key}"} |
|||
self.auth_invoice = {"Authorization": f"Basic {invoice_key}"} |
|||
|
|||
def create_invoice(self, amount: int, memo: str = "") -> WalletResponse: |
|||
return requests.post( |
|||
url=f"{self.endpoint}/addinvoice", headers=self.auth_invoice, json={"amt": amount, "memo": memo} |
|||
) |
|||
|
|||
def pay_invoice(self, bolt11: str) -> WalletResponse: |
|||
return requests.post(url=f"{self.endpoint}/payinvoice", headers=self.auth_admin, json={"invoice": bolt11}) |
|||
|
|||
def get_invoice_status(self, payment_hash: str) -> Response: |
|||
return requests.post(url=f"{self.endpoint}/invoicestatus/{payment_hash}", headers=self.auth_invoice) |
Loading…
Reference in new issue