Ejemplo n.º 1
0
def button_pushed():
    """Actions button pushes by number
    """
    if config.PUSHES == 1:
        if config.FIAT == 0:
            display.update_nocoin_screen()
            time.sleep(3)
            display.update_startup_screen()
        else:
            display.update_qr_request(config.SATS)
            config.INVOICE = qr.scan()
            while config.INVOICE is False:
                display.update_qr_failed()
                time.sleep(1)
                display.update_qr_request(config.SATS)
                config.INVOICE = qr.scan()
            update_payout_screen()

    if config.PUSHES == 2:
        if config.FIAT == 0:
            display.update_nocoin_screen()
            time.sleep(3)
            display.update_startup_screen()
        else:
            lntxbot.process_using_lnurl(config.SATS)

    if config.PUSHES == 3:
        display.update_lntxbot_scan()
        lntxcreds = lntxbot.scan_creds()
        utils.update_config("LNTXBOTCRED", lntxcreds)
        importlib.reload(config)
        balance = lntxbot.get_lnurl_balance()
        display.update_lntxbot_balance(balance)
        GPIO.cleanup()
        os.execv("/home/pi/LightningATM/app.py", [""])

    if config.PUSHES == 4:
        logger.info("Button pushed three times (add coin)")
        print("Button pushed three times (add coin)")
        config.PULSES = 2

    if config.PUSHES == 5:
        logger.warning("Button pushed three times (restart)")
        print("Button pushed three times (restart)")
        GPIO.cleanup()
        os.execv("/home/pi/LightningATM/app.py", [""])

    if config.PUSHES == 6:
        display.update_shutdown_screen()
        GPIO.cleanup()
        logger.info("ATM shutdown (5 times button)")
        os.system("sudo shutdown -h now")
    config.PUSHES = 0
Ejemplo n.º 2
0
def mark_qr(image, save = "qr.png"):
  data = qr.scan(image)
  if data:
    v1, v2, v3, v4 = three.Vector2(data.location[0]), three.Vector2(data.location[1]), three.Vector2(data.location[2]), three.Vector2(data.location[3])
    bb = three.Box2()
    bb.setFromVectors([v1, v2, v3, v4])
    cv2.rectangle(img, (bb.min.x, bb.min.y), (bb.max.x, bb.max.y), (0, 0, 255))
    cv2.putText(img, "Data:"+str(data.data), (bb.center.x, bb.center.y), cv2.FONT_HERSHEY_COMPLEX, 2, (0, 0, 255))
    cv2.imwrite(save, img)
  else:
    print "QR not found"
  return image
def update_payout_screen(papirus, size):

    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)

    # set font sizes
    font = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMono.ttf', 20)
    font1 = ImageFont.truetype(
        '/usr/share/fonts/truetype/freefont/FreeMono.ttf', 15)

    # set btc and sat price
    # btcprice = price.getbtcprice(CURRENCY)
    # satprice = round((1 / btcprice) * 10e5, 2)

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

    papirus.display(image)
    papirus.update()

    INVOICE = qr.scan()

    print(INVOICE)

    decodreq = lightning.decoderequest(INVOICE)

    print(decodreq, round(SATS))

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

        # time.sleep(5)
        result = lightning.lastpayment(INVOICE)

        draw.text((15, 70), str(result), fill=BLACK, font=font1)

        papirus.display(image)
        papirus.partial_update()
    else:
        print('Please show correct invoice')
Ejemplo n.º 4
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()

    print(INVOICE)

    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()
    else:
        print('Please show correct invoice')
Ejemplo n.º 5
0
def scan_creds():
    """Scan lntxbot credentials
    """
    attempts = 0

    while attempts < 4:
        qrcode = qr.scan()
        if qrcode:
            credentials = qrcode
            if not credentials:
                attempts += 1
            else:
                return credentials
        attempts += 1

    logger.error("4 failed scanning attempts.")
    print("4 failed attempts ... try again.")
    raise utils.ScanError
Ejemplo n.º 6
0
def main():
    global FIAT
    global SATS
    global PULSES
    global PUSHES
    global INVOICE

    ## Initiating logging instance
    logging.basicConfig(filename='/home/pi/LightningATM/resources/debug.log',
                            format='%(asctime)s %(name)s %(levelname)s %(message)s',
                            datefmt='%Y/%m/%d %I:%M:%S %p',
                            level=logging.INFO)

    logging.info('Application started')

    ## Display startup startup_screen
    display.update_startup_screen()

    ## Defining GPIO BCM Mode
    GPIO.setmode(GPIO.BCM)

    ## Setup GPIO Pins for coin acceptor and button
    GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(6,GPIO.IN, pull_up_down=GPIO.PUD_UP)

    ## Setup coin interrupt channel (bouncetime for switch bounce)
    GPIO.add_event_detect(5, GPIO.RISING,callback=buttonevent, bouncetime=200)
    GPIO.add_event_detect(6,GPIO.FALLING,callback=coinevent)

    while True:
        time.sleep(0.5)
        ## Detect when coins are being inserted
        if((time.time() - LASTIMPULSE > 0.5) and (PULSES > 0)):
            if (PULSES == 2):
                FIAT += 0.02
                SATS = FIAT * 100 * SATPRICE
                logging.info('2 cents added')
                update_amount_screen(PAPIRUS)
            if (PULSES == 3):
                FIAT += 0.05
                SATS = FIAT * 100 * SATPRICE
                logging.info('5 cents added')
                update_amount_screen(PAPIRUS)
            if (PULSES == 4):
                FIAT += 0.1
                SATS = FIAT * 100 * SATPRICE
                logging.info('10 cents added')
                update_amount_screen(PAPIRUS)
            if (PULSES == 5):
                FIAT += 0.2
                SATS = FIAT * 100 * SATPRICE
                logging.info('20 cents added')
                update_amount_screen(PAPIRUS)
            if (PULSES == 6):
                FIAT += 0.5
                SATS = FIAT * 100 * SATPRICE
                logging.info('50 cents added')
                update_amount_screen(PAPIRUS)
            if (PULSES == 7):
                FIAT += 1
                SATS = FIAT * 100 * SATPRICE
                logging.info('100 cents added')
                update_amount_screen(PAPIRUS)
            PULSES = 0

        ## Detect if the buttons has been pushed
        if((time.time() - LASTPUSHES > 0.5) and (PUSHES > 0)):
            if (PUSHES == 1):
                if FIAT == 0:
                    display.update_nocoin_screen()
                    time.sleep(3)
                    display.update_startup_screen()
                else:
                    display.update_qr_request()
                    INVOICE = qr.scan()
                    while INVOICE == False:
                        display.update_qr_failed()
                        time.sleep(1)
                        display.update_qr_request()
                        INVOICE = qr.scan()
                    update_payout_screen(PAPIRUS)

            if (PUSHES == 2):
                logging.info('Button pushed twice (add coin)')
                print('Button pushed twice (add coin)')
                PULSES = 2

            if (PUSHES == 3):
                logging.warning('Button pushed three times (restart)')
                print('Button pushed three times (restart)')
                os.execv('/home/pi/LightningATM/app.py', [''])
                GPIO.cleanup()

            if (PUSHES == 4):
                display.update_shutdown_screen()
                GPIO.cleanup()
                logging.info('ATM shutdown (4 times button)')
                os.system('sudo shutdown -h now')
            PUSHES = 0
Ejemplo n.º 7
0
def button_pushed():
    """Actions button pushes by number
    """
    if config.PUSHES == 1:
        """If no coins inserted, update the screen.
        If coins inserted, scan a qr code for the exchange amount
        """
        if config.FIAT == 0:
            display.update_nocoin_screen()
            time.sleep(3)
            display.update_startup_screen()
        else:
            display.update_qr_request()
            qrcode = qr.scan()
            config.INVOICE = lndrest.evaluate_scan(qrcode)
            while config.INVOICE is False:
                display.update_qr_failed()
                time.sleep(1)
                display.update_qr_request()
                qrcode = qr.scan()
                config.INVOICE = lndrest.evaluate_scan(qrcode)
            display.update_payout_screen()
            lndrest.handle_invoice()
            softreset()

    if config.PUSHES == 2:
        """If no coins inserted, update the screen.
        If coins are inserted, return a lnurl for the exchange amount
        """
        if config.FIAT == 0:
            display.update_nocoin_screen()
            time.sleep(3)
            display.update_startup_screen()
        else:
            lntxbot.process_using_lnurl(config.SATS)
            # Softreset and startup screen
            softreset()

    if config.PUSHES == 3:
        """Store new lntxbot credential via a QR code scan
        """
        display.update_lntxbot_scan()

        # scan the credentials
        lntxcreds = lntxbot.scan_creds()

        # save them to the current config and reload config file
        config.update_config("lntxbot", "creds", lntxcreds)
        if config.check_dangermode():
            importlib.reload(config)

        # return the current balance to the user on the screen
        balance = lntxbot.get_lnurl_balance()
        display.update_lntxbot_balance(balance)
        softreset()

    if config.PUSHES == 4:
        """Simulates adding a coin
        """
        logger.info("Button pushed four times (add coin)")
        print("Button pushed four times (add coin)")
        config.PULSES = 2

    if config.PUSHES == 5:
        """Restarts the application
        """
        logger.warning("Button pushed five times (restart)")
        print("Button pushed five times (restart)")
        utils.softreset()

    if config.PUSHES == 6:
        """Shutdown the host machine
        """
        display.update_shutdown_screen()
        GPIO.cleanup()
        logger.warning("ATM shutdown (6 times button)")
        os.system("sudo shutdown -h now")
    config.PUSHES = 0
Ejemplo n.º 8
0
def button_pushed():
    """Actions button pushes by number
    """
    if config.PUSHES == 1:
        """If no coins inserted, update the screen.
        If coins inserted, scan a qr code for the exchange amount
        """
        if config.FIAT == 0:
            display.update_nocoin_screen()
            time.sleep(3)
            display.update_startup_screen()

        if not config.conf["atm"]["activewallet"]:
            logger.error("No wallet has been configured for the ATM.")
            # Softreset and startup screen
            softreset()

        if config.conf["atm"]["activewallet"] == "btcpay_lnd":
            display.update_qr_request()
            qrcode = qr.scan()
            config.INVOICE = lndrest.evaluate_scan(qrcode)
            while config.INVOICE is False:
                display.update_qr_failed()
                time.sleep(1)
                display.update_qr_request()
                qrcode = qr.scan()
                config.INVOICE = lndrest.evaluate_scan(qrcode)
            display.update_payout_screen()
            lndrest.handle_invoice()
            softreset()
        elif config.conf["atm"]["activewallet"] == "lntxbot":
            lntxbot.process_using_lnurl(config.SATS)
            # Softreset and startup screen
            softreset()
            # lntxbot.payout(config.SATS, config.INVOICE)
        else:
            pass

    if config.PUSHES == 3:
        """Scan and store new wallet credentials
        """
        # Delete current wallet flag and credentials
        config.update_config("atm", "activewallet", "")
        config.update_config("lntxbot", "creds", "")
        config.update_config("lnd", "macaroon", "")

        display.update_wallet_scan()
        qr.scan_credentials()
        importlib.reload(config)

        if config.conf["atm"]["activewallet"] == "btcpay_lnd":
            display.update_btcpay_lnd()
        elif config.conf["atm"]["activewallet"] == "lntxbot":
            balance = lntxbot.get_lnurl_balance()
            display.update_lntxbot_balance(balance)
        else:
            logger.error("Saving of wallet credentials failed.")

        # scan the credentials
        # lntxcreds = lntxbot.scan_creds()

        # save them to the current config and reload config file
        # config.update_config("lntxbot", "creds", lntxcreds)
        # if config.check_dangermode():
        #     importlib.reload(config)

        # return the current balance to the user on the screen

        softreset()

    if config.PUSHES == 4:
        """Simulates adding a coin
        """
        logger.info("Button pushed four times (add coin)")
        print("Button pushed four times (add coin)")
        config.PULSES = 2

    if config.PUSHES == 6:
        """Shutdown the host machine
        """
        display.update_shutdown_screen()
        GPIO.cleanup()
        logger.warning("ATM shutdown (6 times button)")
        os.system("sudo shutdown -h now")
    config.PUSHES = 0
Ejemplo n.º 9
0
def main():
    global FIAT
    global SATS
    global PULSES
    global PUSHES
    global INVOICE

    ## Display startup startup_screen
    display.update_startup_screen()

    ## Defining GPIO BCM Mode
    GPIO.setmode(GPIO.BCM)

    ## Setup GPIO Pins for coin acceptor and button
    GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    ## Setup coin interrupt channel (bouncetime for switch bounce)
    GPIO.add_event_detect(5, GPIO.RISING, callback=buttonevent, bouncetime=200)
    GPIO.add_event_detect(6, GPIO.FALLING, callback=coinevent)

    while True:
        time.sleep(0.5)
        ## Detect when coins are being inserted
        if ((time.time() - LASTIMPULSE > 0.5) and (PULSES > 0)):
            if (PULSES == 1):
                FIAT += 0.02
                SATS = FIAT * 100 * SATPRICE
                update_amount_screen(PAPIRUS)
            if (PULSES == 2):
                FIAT += 0.05
                SATS = FIAT * 100 * SATPRICE
                update_amount_screen(PAPIRUS)
            if (PULSES == 3):
                FIAT += 0.1
                SATS = FIAT * 100 * SATPRICE
                update_amount_screen(PAPIRUS)
            if (PULSES == 4):
                FIAT += 0.2
                SATS = FIAT * 100 * SATPRICE
                update_amount_screen(PAPIRUS)
            if (PULSES == 5):
                FIAT += 0.5
                SATS = FIAT * 100 * SATPRICE
                update_amount_screen(PAPIRUS)
            PULSES = 0

        ## Detect if the buttons has been pushed
        if ((time.time() - LASTPUSHES > 0.5) and (PUSHES > 0)):
            if (PUSHES == 1):
                display.update_qr_request()
                INVOICE = qr.scan()
                update_payout_screen(PAPIRUS)
            if (PUSHES == 2):
                FIAT += 0.05
                SATS = FIAT * 100 * SATPRICE
                update_amount_screen(PAPIRUS)
            if (PUSHES == 3):
                os.execv('/home/pi/LightningATM/app.py', [''])
                GPIO.cleanup()
            PUSHES = 0