2021-11-17 16:53:32 +00:00
|
|
|
import hashlib
|
|
|
|
import secrets
|
2022-06-26 22:11:46 +00:00
|
|
|
import random
|
|
|
|
import string
|
2021-11-17 16:53:32 +00:00
|
|
|
from lnbits.core.crud import create_payment
|
|
|
|
|
2022-06-01 12:53:05 +00:00
|
|
|
|
2021-11-17 16:53:32 +00:00
|
|
|
async def credit_wallet(wallet_id: str, amount: int):
|
|
|
|
preimage = secrets.token_hex(32)
|
|
|
|
m = hashlib.sha256()
|
|
|
|
m.update(f"{preimage}".encode())
|
|
|
|
payment_hash = m.hexdigest()
|
|
|
|
await create_payment(
|
|
|
|
wallet_id=wallet_id,
|
|
|
|
payment_request="",
|
|
|
|
payment_hash=payment_hash,
|
|
|
|
checking_id=payment_hash,
|
|
|
|
preimage=preimage,
|
2022-06-26 22:11:46 +00:00
|
|
|
memo=f"funding_test_{get_random_string(5)}",
|
2022-06-01 12:53:05 +00:00
|
|
|
amount=amount, # msat
|
|
|
|
pending=False, # not pending, so it will increase the wallet's balance
|
2021-11-17 16:53:32 +00:00
|
|
|
)
|
2022-06-26 22:11:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_random_string(N=10):
|
|
|
|
return "".join(
|
|
|
|
random.SystemRandom().choice(string.ascii_uppercase + string.digits)
|
|
|
|
for _ in range(10)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def get_random_invoice_data():
|
|
|
|
return {"out": False, "amount": 10, "memo": f"test_memo_{get_random_string(10)}"}
|