mirror of
https://github.com/aljazceru/python-teos.git
synced 2026-02-23 07:24:30 +01:00
Move config options used by inspector to the constructor
This commit is contained in:
@@ -17,8 +17,9 @@ logger = Logger("API")
|
||||
|
||||
|
||||
class API:
|
||||
def __init__(self, watcher):
|
||||
def __init__(self, watcher, config):
|
||||
self.watcher = watcher
|
||||
self.config = config
|
||||
|
||||
def add_appointment(self):
|
||||
"""
|
||||
@@ -41,7 +42,7 @@ class API:
|
||||
|
||||
# Check content type once if properly defined
|
||||
request_data = json.loads(request.get_json())
|
||||
inspector = Inspector()
|
||||
inspector = Inspector(self.config)
|
||||
appointment = inspector.inspect(
|
||||
request_data.get("appointment"), request_data.get("signature"), request_data.get("public_key")
|
||||
)
|
||||
|
||||
@@ -5,7 +5,6 @@ from common.constants import LOCATOR_LEN_HEX
|
||||
from common.cryptographer import Cryptographer
|
||||
|
||||
from pisa import errors
|
||||
import pisa.conf as conf
|
||||
from common.logger import Logger
|
||||
from common.appointment import Appointment
|
||||
from pisa.block_processor import BlockProcessor
|
||||
@@ -23,6 +22,9 @@ class Inspector:
|
||||
The :class:`Inspector` class is in charge of verifying that the appointment data provided by the user is correct.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def inspect(self, appointment_data, signature, public_key):
|
||||
"""
|
||||
Inspects whether the data provided by the user is correct.
|
||||
@@ -221,8 +223,7 @@ class Inspector:
|
||||
|
||||
return rcode, message
|
||||
|
||||
@staticmethod
|
||||
def check_to_self_delay(to_self_delay):
|
||||
def check_to_self_delay(self, to_self_delay):
|
||||
"""
|
||||
Checks if the provided ``to_self_delay`` is correct.
|
||||
|
||||
@@ -255,10 +256,10 @@ class Inspector:
|
||||
rcode = errors.APPOINTMENT_WRONG_FIELD_TYPE
|
||||
message = "wrong to_self_delay data type ({})".format(t)
|
||||
|
||||
elif to_self_delay < conf.MIN_TO_SELF_DELAY:
|
||||
elif to_self_delay < self.config.get("MIN_TO_SELF_DELAY"):
|
||||
rcode = errors.APPOINTMENT_FIELD_TOO_SMALL
|
||||
message = "to_self_delay too small. The to_self_delay should be at least {} (current: {})".format(
|
||||
conf.MIN_TO_SELF_DELAY, to_self_delay
|
||||
self.config.get("MIN_TO_SELF_DELAY"), to_self_delay
|
||||
)
|
||||
|
||||
if message is not None:
|
||||
|
||||
@@ -7,16 +7,7 @@ from common.logger import Logger
|
||||
from pisa.api import API
|
||||
from pisa.watcher import Watcher
|
||||
from pisa.builder import Builder
|
||||
from pisa.conf import (
|
||||
BTC_NETWORK,
|
||||
FEED_PROTOCOL,
|
||||
FEED_ADDR,
|
||||
FEED_PORT,
|
||||
MAX_APPOINTMENTS,
|
||||
EXPIRY_DELTA,
|
||||
MIN_TO_SELF_DELAY,
|
||||
PISA_SECRET_KEY,
|
||||
)
|
||||
import pisa.conf as conf
|
||||
from pisa.responder import Responder
|
||||
from pisa.db_manager import DBManager
|
||||
from pisa.block_processor import BlockProcessor
|
||||
@@ -108,7 +99,7 @@ if __name__ == "__main__":
|
||||
watcher.block_queue = Builder.build_block_queue(missed_blocks_watcher)
|
||||
|
||||
# Fire the API
|
||||
API(watcher).start()
|
||||
API(watcher, config=pisa_config).start()
|
||||
|
||||
except Exception as e:
|
||||
logger.error("An error occurred: {}. Shutting down".format(e))
|
||||
|
||||
Reference in New Issue
Block a user