This commit is contained in:
Ben Arc 2022-02-01 20:51:40 +00:00
parent 615abffeb4
commit 3f0a855526
3 changed files with 41 additions and 43 deletions

View File

@ -123,26 +123,26 @@ def decode(pr: str) -> Invoice:
def encode(options):
"""Convert options into LnAddr and pass it to the encoder"""
addr = LnAddr()
addr.currency = options.currency
addr.fallback = options.fallback if options.fallback else None
if options.amount:
addr.amount = options.amount
if options.timestamp:
addr.date = int(options.timestamp)
addr.currency = options["currency"]
addr.fallback = options["fallback"] if options["fallback"] else None
if options["amount"]:
addr.amount = options["amount"]
if options["timestamp"]:
addr.date = int(options["timestamp"])
addr.paymenthash = unhexlify(options.paymenthash)
addr.paymenthash = unhexlify(options["paymenthash"])
if options.description:
addr.tags.append(("d", options.description))
if options.description_hash:
addr.tags.append(("h", options.description_hash))
if options.expires:
addr.tags.append(("x", options.expires))
if options["description"]:
addr.tags.append(("d", options["description"]))
if options["description_hash"]:
addr.tags.append(("h", options["description_hash"]))
if options["expires"]:
addr.tags.append(("x", options["expires"]))
if options.fallback:
addr.tags.append(("f", options.fallback))
if options.route:
for r in options.route:
if options["fallback"]:
addr.tags.append(("f", options["fallback"]))
if options["route"]:
for r in options["route"]:
splits = r.split("/")
route = []
while len(splits) >= 5:
@ -158,7 +158,7 @@ def encode(options):
splits = splits[5:]
assert len(splits) == 0
addr.tags.append(("r", route))
return lnencode(addr, options.privkey)
return lnencode(addr, options["privkey"])
def lnencode(addr, privkey):

View File

@ -82,7 +82,7 @@ async def api_update_balance(
checking_id=payHash,
payment_request="selfPay",
payment_hash=payHash,
amount=amount*1000,
amount=amount * 1000,
memo="selfPay",
fee=0,
)

View File

@ -17,20 +17,8 @@ from .base import (
Wallet,
)
class FakeWallet(Wallet):
def __init__(self):
self.amount = 0
self.timestamp = 0
self.currency = "bc"
self.paymenthash = ""
self.privkey = getenv("FAKE_WALLET_KEY")
self.memo = ""
self.description_hash = ""
self.description = ""
self.fallback = None
self.expires = None
self.route = None
class FakeWallet(Wallet):
async def status(self) -> StatusResponse:
print(
"FakeWallet funding source is for using LNbits as a centralised, stand-alone payment system with brrrrrr."
@ -43,22 +31,32 @@ class FakeWallet(Wallet):
memo: Optional[str] = None,
description_hash: Optional[bytes] = None,
) -> InvoiceResponse:
self.amount = amount
self.timestamp = datetime.now().timestamp()
data: Dict = {
"out": False,
"amount": amount,
"currency": "bc",
"privkey": getenv("FAKE_WALLET_KEY"),
"memo": None,
"description_hash": None,
"description": "",
"fallback": None,
"expires": None,
"route": None,
}
data["amount"] = amount
data["timestamp"] = datetime.now().timestamp()
if description_hash:
self.tags_set = {"h"}
self.description_hash = description_hash.hex()
data["tags_set"] = ["h"]
data["description_hash"] = description_hash.hex()
else:
self.tags_set = {"d"}
self.memo = memo
self.description = memo
letters = string.ascii_lowercase
data["tags_set"] = ["d"]
data["memo"] = memo
data["description"] = memo
randomHash = hashlib.sha256(
str(random.getrandbits(256)).encode("utf-8")
).hexdigest()
self.paymenthash = randomHash
payment_request = encode(self)
data["paymenthash"] = randomHash
payment_request = encode(data)
print(payment_request)
checking_id = randomHash