Ejemplo n.º 1
0
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)")
Ejemplo n.º 2
0
def handle_invoice(draw, image):
    """Decode a BOLT11 invoice. Ensure that amount is correct or 0, then attempt to
    make the payment.
    """
    decode_req = lightning.decode_request(config.INVOICE)
    if decode_req == str(round(config.SATS)) or str(0):
        lightning.payout(config.SATS, config.INVOICE)
        result = lightning.last_payment(config.INVOICE)

        draw.text(
            (15, 70),
            str(result),
            fill=config.BLACK,
            font=utils.create_font("freemono", 15),
        )

        config.PAPIRUS.display(image)
        config.PAPIRUS.partial_update()
        time.sleep(1)

        if result is True:
            display.update_thankyou_screen()
        else:
            display.update_payment_failed()
            time.sleep(120)

        logger.info("Initiating restart...")
        os.execv("/home/pi/LightningATM/app.py", [""])
    else:
        print("Please show correct invoice")
Ejemplo n.º 3
0
def update_payout_screen(papirus):

    # global INVOICE

    ## initially set all white background
    image = Image.new('1', PAPIRUS.size, WHITE)

    ## Set width and heigt of screen
    width, height = image.size

    ## prepare for drawing
    draw = ImageDraw.Draw(image)

    draw.rectangle((2, 2, width - 2, height - 2), fill=WHITE, outline=BLACK)
    draw.text((15, 30),
              str(round(SATS)) + ' sats',
              fill=BLACK,
              font=createfont('freemono', 20))
    draw.text((15, 50),
              'on the way!',
              fill=BLACK,
              font=createfont('freemono', 15))

    PAPIRUS.display(image)
    PAPIRUS.update()

    # INVOICE = qr.scan()

    decodreq = lightning.decoderequest(INVOICE)

    print(decodreq, round(SATS))

    if (decodreq == str(round(SATS))) or (decodreq == True):
        lightning.payout(SATS, INVOICE)

        result = lightning.lastpayment(INVOICE)

        draw.text((15, 70),
                  str(result),
                  fill=BLACK,
                  font=createfont('freemono', 15))

        PAPIRUS.display(image)
        PAPIRUS.partial_update()
        time.sleep(1)

        if result == 'Success':
            display.update_thankyou_screen()
        else:
            display.update_payment_failed()
            time.sleep(120)

        logging.info('Initiating restart...')
        os.execv('/home/pi/LightningATM/app.py', [''])
    else:
        print('Please show correct invoice')
Ejemplo n.º 4
0
def handle_invoice():
    """Decode a BOLT11 invoice. Ensure that amount is correct or 0, then attempt to
    make the payment.
    """
    decode_req = decode_request(config.INVOICE)
    if decode_req in (math.floor(config.SATS), 0):
        payout(config.SATS, config.INVOICE)
        result = last_payment(config.INVOICE)

        if result is True:
            display.update_thankyou_screen()
        else:
            display.update_payment_failed()
            time.sleep(120)

        logger.info("Initiating softreset...")
    else:
        print("Please show correct invoice")
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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', [''])