Some small refactors

This commit is contained in:
Sergi Delgado Segura
2019-06-20 14:58:20 +01:00
parent 531f2104c9
commit db263cf9b9
4 changed files with 15 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
from pisa import *
from pisa.watcher import Watcher
from pisa.inspector import Inspector
from pisa.appointment import Appointment
from flask import Flask, request, Response
import json
@@ -19,9 +20,9 @@ def add_appointment():
# Check content type once if properly defined
request_data = json.loads(request.get_json())
appointment = inspector.inspect(request_data, debug)
appointment = inspector.inspect(request_data)
if appointment:
if type(appointment) == Appointment:
appointment_added = watcher.add_appointment(appointment, debug, logging)
rcode = HTTP_OK
@@ -32,7 +33,11 @@ def add_appointment():
response = "appointment rejected"
# FIXME: change the response code maybe?
elif type(appointment) == tuple:
rcode = HTTP_BAD_REQUEST
response = "appointment rejected. Error {}: {}".format(appointment[0], appointment[1])
else:
rcode = HTTP_BAD_REQUEST
response = "appointment rejected. Request does not match the standard"
@@ -50,7 +55,7 @@ def start_api(d, l):
debug = d
logging = l
watcher = Watcher()
inspector = Inspector()
inspector = Inspector(debug, logging)
# Setting Flask log t ERROR only so it does not mess with out logging
logging.getLogger('werkzeug').setLevel(logging.ERROR)

View File

@@ -12,4 +12,9 @@ class Appointment:
self.cipher = cipher
self.hash_function = hash_function
# ToDO: We may want to add some additional things to the appointment, like
# minimum fee
# refund to be payed to the user in case of failing

View File

@@ -3,8 +3,7 @@ from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.backends import default_backend
SALT = 'lightningwatcher'
from conf import SALT
class EncryptedBlob:

View File

@@ -1,13 +1,12 @@
from binascii import hexlify, unhexlify
from queue import Queue
from threading import Thread
from conf import EXPIRY_DELTA
from pisa.responder import Responder
from pisa.zmq_subscriber import ZMQHandler
from utils.authproxy import AuthServiceProxy, JSONRPCException
from conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT, MAX_APPOINTMENTS
EXPIRY_DELTA = 6
class Watcher:
def __init__(self, max_appointments=MAX_APPOINTMENTS):