summaryrefslogtreecommitdiffstats
path: root/bitvend.py
blob: 339114e1327280dbc6b2b3d8d0dff2f9d384db79 (plain)
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
import logging
import threading
import flask
from flask_qrcode import QRcode

from bitvend.mdb import BitvendCashlessMDBDevice
from bitvend.utils import to_local_currency, from_local_currency, format_btc, \
    sat_to_btc
from bitvend.processor import PaymentProcessor
from bitvend.models import db, Transaction

logging.basicConfig(level=logging.INFO)

from prometheus_client import start_http_server
start_http_server(8000)

app = flask.Flask(__name__)
app.config.from_object('bitvend.default_settings')

db.init_app(app)

QRcode(app)

dev = BitvendCashlessMDBDevice()
dev.init_app(app)

proc = PaymentProcessor(dev)
proc.init_app(app)

@app.route('/')
def index():
    return flask.render_template(
        'index.html', items=app.config['ITEMS'])

@app.route('/log')
def log():
    return flask.render_template(
        'log.html', transactions=Transaction.query.all())
@app.route('/begin/<int:amount>')
def begin_session(amount):
    dev.begin_session(amount)
    return 'ok'

@app.route('/cancel')
def cancel_session():
    dev.cancel_session()
    return 'ok'

@app.context_processor
def ctx_utils():
    return {
        'from_local_currency': from_local_currency,
        'to_local_currency': to_local_currency,
        'format_btc': format_btc,
        'sat_to_btc': sat_to_btc,
    }

if __name__ == "__main__":
    with app.app_context():
        db.create_all()

    threading.Thread(target=app.run, kwargs={
        'host': '0.0.0.0'
        }, daemon=True).start()
    proc.start()
    dev.run()