-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_ln_address.py
84 lines (65 loc) · 2.59 KB
/
test_ln_address.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
import os
import asyncio
from aiohttp.client import ClientSession
from ln_address import LNAddress
import logging
###################################
logging.basicConfig(filename='lnaddress.log', level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logging.getLogger("lnaddress").setLevel(level=logging.WARNING)
logger = logging.getLogger(__name__)
###################################
async def main():
email = '[email protected]'
amount = 150 # amount in sats
#email = '[email protected]' # non working ln address
#amount = None
# Get environment variables
invoice_key = os.getenv('INVOICE_KEY')
admin_key = os.getenv('ADMIN_KEY')
base_url = os.getenv('BASE_URL')
config = { 'invoice_key': invoice_key,
'admin_key': admin_key,
'base_url': base_url }
print(config)
try:
async with ClientSession() as session:
logging.info("in ClientSession")
lnaddy = LNAddress(config, session)
bolt11 = await lnaddy.get_bolt11(email, amount)
logging.info(bolt11)
payhash = await lnaddy.get_payhash(bolt11)
logging.info("response from get_payhash: " + str(payhash))
# check payment hash status -
output = await lnaddy.check_invoice(payhash)
if 'paid' in output:
pay_status = output['paid']
pay_preimage = output['preimage']
paid_status= 'paid status:'+ str(pay_status)
img_status = "image: " + str(pay_preimage)
logging.info(paid_status)
logging.info(img_status)
else:
logging.info(output)
# pay invoice
#result = await lnaddy.pay_invoice(bolt11)
#logging.info("pay invoice result:")
#logging.info(result)
# check payment hash status -
"""
payment_hash = result['payment_hash']
output = await lnaddy.check_invoice(payment_hash)
if 'paid' in output:
pay_status = output['paid']
pay_preimage = output['preimage']
paid_status= 'paid status:'+ str(pay_status)
img_status = "image: " + str(pay_preimage)
logging.info(paid_status)
logging.info(img_status)
else:
logging.info(output)
"""
except Exception as e:
logging.error(e)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())