def process_using_lnurl(amt): """Processes receiving an amount using the lnurl scheme """ # get the new lnurl display.update_lnurl_generation() logger.info("LNURL requested") print("LNURL requested") lnurl = request_lnurl(amt) print(lnurl["lnurl"]) # Check EPD_SIZE is defined utils.check_epd_size() # create a qr code image and print it to terminal qr_img = generate_lnurl_qr(lnurl["lnurl"]) qr_img = qr_img.resize((96, 96), resample=0) # draw the qr code on the e-ink screen draw_lnurl_qr(qr_img) # get the balance? back from the bot start_balance = get_lnurl_balance() print(start_balance) # loop while we wait for a balance update or until timeout reached success = wait_for_balance_update(start_balance, timeout=90) if success: display.update_thankyou_screen() logger.info("LNURL withdrawal succeeded") return else: # TODO: I think we should handle a failure here logger.error("LNURL withdrawal failed (within 90 seconds)")
def process_using_lnurl(amt): """Processes receiving an amount using the lnurl scheme """ # get the new lnurl display.update_lnurl_generation() logger.info("LNURL requested") print("LNURL requested") lnurl = request_lnurl(amt) print(lnurl["lnurl"]) # Check EPD_SIZE is defined utils.check_epd_size() # create a qr code image and print it to terminal qr_img = generate_lnurl_qr(lnurl["lnurl"]) print(type(qr_img)) print(qr_img.size) qr_img = qr_img.resize((96, 96), resample=0) print(qr_img.size) # draw the qr code on the e-ink screen draw_lnurl_qr(qr_img) # get the balance? back from the bot start_balance = get_lnurl_balance() print(start_balance) # loop while we wait for a balance update or until timeout reached success = wait_for_balance_update(start_balance, timeout=90) if success: display.update_thankyou_screen() logger.info("Initiating restart...") os.execv("/home/pi/LightningATM/app.py", [""]) else: # TODO: I think we should handle a failure here pass
def generate_lnurl(amt): display.update_lnurl_generation() logging.info('LNURL requested') print('LNURL requested') data = { 'satoshis': str(round(amt)), } response = requests.post( 'https://lntxbot.alhur.es/generatelnurlwithdraw', headers = {'Authorization' : 'Basic %s' % LNTXBOTCRED}, data=json.dumps(data), ) response = json.loads(response.text) print(response['lnurl']) if os.path.exists('/etc/default/epd-fuse'): exec(open('/etc/default/epd-fuse').read()) image = Image.new('1', PAPIRUS.size, BLACK) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=2, border=1, ) qr.add_data(response['lnurl'].upper()) img = qr.make_image() print(type(img)) print(img.size) img = img.resize((96,96), resample=0) print(img.size) draw = ImageDraw.Draw(image) draw.bitmap((0, 0), img, fill=WHITE) draw.text((110, 25), 'Scan to', fill=WHITE, font=createfont('freemonobold',16)) draw.text((110, 45), 'receive', fill=WHITE, font=createfont('freemonobold',16)) PAPIRUS.display(image) PAPIRUS.update() response = requests.post( 'https://lntxbot.alhur.es/balance', headers = {'Authorization' : 'Basic %s' % LNTXBOTCRED}, ) response = json.loads(response.text) response = response['BTC'] balance = response['AvailableBalance'] print(balance) newbalance = balance while balance == newbalance: response = requests.post( 'https://lntxbot.alhur.es/balance', headers = {'Authorization' : 'Basic %s' % LNTXBOTCRED}, ) response = json.loads(response.text) response = response['BTC'] newbalance = response['AvailableBalance'] print('Balance: ' + str(balance) +' (no changes)') time.sleep(3) print('Balance: ' + str(balance) +' | New Balance:' + str(newbalance)) logging.info('LNURL withdrawl succeeded') print('LNURL withdrawl succeeded') display.update_thankyou_screen() logging.info('Initiating restart...') os.execv('/home/pi/LightningATM/app.py', [''])