back
This commit is contained in:
+30
-24
@@ -2,6 +2,7 @@ import asyncio
|
||||
import json
|
||||
import httpx
|
||||
from os import getenv
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional, Dict, AsyncGenerator
|
||||
import hashlib
|
||||
from ..bolt11 import encode
|
||||
@@ -13,60 +14,65 @@ from .base import (
|
||||
Wallet,
|
||||
)
|
||||
|
||||
|
||||
class FakeWallet(Wallet):
|
||||
"""https://github.com/lnbits/lnbits"""
|
||||
async def status(self) -> StatusResponse:
|
||||
print("This backend does nothing, it is here just as a placeholder, you must configure an actual backend before being able to do anything useful with LNbits.")
|
||||
return StatusResponse(
|
||||
None,
|
||||
21000000000,
|
||||
|
||||
print(
|
||||
"The FakeWallet backend is for using LNbits as a centralised, stand-alone payment system."
|
||||
)
|
||||
return StatusResponse(None, 21000000000)
|
||||
|
||||
async def create_invoice(
|
||||
self,
|
||||
amount: int,
|
||||
memo: Optional[str] = None,
|
||||
description_hash: Optional[bytes] = None,
|
||||
) -> InvoiceResponse:
|
||||
|
||||
options.amount = amount
|
||||
options.timestamp = datetime.now().timestamp()
|
||||
class options:
|
||||
def __init__(self, amount, timestamp, payments_hash, privkey, memo, ):
|
||||
self.name = name
|
||||
self.age = age
|
||||
async def status(self) -> StatusResponse:
|
||||
|
||||
randomHash = hashlib.sha256(b"some random data").hexdigest()
|
||||
options.payments_hash = hex(randomHash)
|
||||
options.privkey = "v3qrevqrevm39qin0vq3r0ivmrewvmq3rimq03ig"
|
||||
options = {
|
||||
"amount": amount,
|
||||
"timestamp": datetime.now().timestamp(),
|
||||
"payments_hash": randomHash,
|
||||
"privkey": "v3qrevqrevm39qin0vq3r0ivmrewvmq3rimq03ig",
|
||||
"memo": "",
|
||||
"description_hashed": "",
|
||||
}
|
||||
if description_hash:
|
||||
options.description_hashed = description_hash
|
||||
else:
|
||||
options.memo = memo
|
||||
payment_request = encode(options)
|
||||
print(payment_request)
|
||||
checking_id = randomHash
|
||||
|
||||
return InvoiceResponse(ok, checking_id, payment_request)
|
||||
|
||||
async def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
||||
|
||||
|
||||
return ""
|
||||
|
||||
async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
||||
|
||||
return ""
|
||||
return ""
|
||||
|
||||
async def get_payment_status(self, checking_id: str) -> PaymentStatus:
|
||||
|
||||
|
||||
return ""
|
||||
|
||||
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
||||
url = f"{self.endpoint}/api/v1/payments/sse"
|
||||
print("lost connection to lnbits /payments/sse, retrying in 5 seconds")
|
||||
await asyncio.sleep(5)
|
||||
yield ""
|
||||
|
||||
|
||||
#invoice = "lnbc"
|
||||
#invoice += str(data.amount) + "m1"
|
||||
#invoice += str(datetime.now().timestamp()).to_bytes(35, byteorder='big'))
|
||||
#invoice += str(hashlib.sha256(b"some random data").hexdigest()) # hash of preimage, can be fake as invoice handled internally
|
||||
#invoice += "dpl" # d then pl (p = 1, l = 31; 1 * 32 + 31 == 63)
|
||||
#invoice += "2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq" #description, how do I encode this?
|
||||
#invoice += str(hashlib.sha224("lnbc" + str(data.amount) + "m1").hexdigest())
|
||||
# invoice = "lnbc"
|
||||
# invoice += str(data.amount) + "m1"
|
||||
# invoice += str(datetime.now().timestamp()).to_bytes(35, byteorder='big'))
|
||||
# invoice += str(hashlib.sha256(b"some random data").hexdigest()) # hash of preimage, can be fake as invoice handled internally
|
||||
# invoice += "dpl" # d then pl (p = 1, l = 31; 1 * 32 + 31 == 63)
|
||||
# invoice += "2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq" #description, how do I encode this?
|
||||
# invoice += str(hashlib.sha224("lnbc" + str(data.amount) + "m1").hexdigest())
|
||||
|
||||
@@ -23,8 +23,7 @@ class LndRestWallet(Wallet):
|
||||
endpoint = getenv("LND_REST_ENDPOINT")
|
||||
endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
|
||||
endpoint = (
|
||||
"https://" +
|
||||
endpoint if not endpoint.startswith("http") else endpoint
|
||||
"https://" + endpoint if not endpoint.startswith("http") else endpoint
|
||||
)
|
||||
self.endpoint = endpoint
|
||||
|
||||
@@ -103,10 +102,7 @@ class LndRestWallet(Wallet):
|
||||
r = await client.post(
|
||||
url=f"{self.endpoint}/v1/channels/transactions",
|
||||
headers=self.auth,
|
||||
json={
|
||||
"payment_request": bolt11,
|
||||
"fee_limit": lnrpcFeeLimit,
|
||||
},
|
||||
json={"payment_request": bolt11, "fee_limit": lnrpcFeeLimit},
|
||||
timeout=180,
|
||||
)
|
||||
|
||||
@@ -183,8 +179,7 @@ class LndRestWallet(Wallet):
|
||||
except:
|
||||
continue
|
||||
|
||||
payment_hash = base64.b64decode(
|
||||
inv["r_hash"]).hex()
|
||||
payment_hash = base64.b64decode(inv["r_hash"]).hex()
|
||||
yield payment_hash
|
||||
except (OSError, httpx.ConnectError, httpx.ReadError):
|
||||
pass
|
||||
|
||||
@@ -20,11 +20,10 @@ class VoidWallet(Wallet):
|
||||
raise Unsupported("")
|
||||
|
||||
async def status(self) -> StatusResponse:
|
||||
print("This backend does nothing, it is here just as a placeholder, you must configure an actual backend before being able to do anything useful with LNbits.")
|
||||
return StatusResponse(
|
||||
None,
|
||||
0,
|
||||
print(
|
||||
"This backend does nothing, it is here just as a placeholder, you must configure an actual backend before being able to do anything useful with LNbits."
|
||||
)
|
||||
return StatusResponse(None, 0)
|
||||
|
||||
async def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
||||
raise Unsupported("")
|
||||
|
||||
Reference in New Issue
Block a user