mirror of
https://github.com/aljazceru/python-teos.git
synced 2026-02-09 16:44:31 +01:00
Adds API HOST and PORT as configurable parameters.
Uses API_BIND/API_PORT for the server and API_CONNECT/API_PORT for the user, for consistency.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import os
|
||||
|
||||
HOST = "localhost"
|
||||
PORT = 9814
|
||||
DATA_DIR = os.path.expanduser("~/.teos/")
|
||||
CONF_FILE_NAME = "teos.conf"
|
||||
LOG_PREFIX = "teos"
|
||||
|
||||
# Default conf fields
|
||||
DEFAULT_CONF = {
|
||||
"API_BIND": {"value": "localhost", "type": str},
|
||||
"API_PORT": {"value": 9814, "type": int},
|
||||
"BTC_RPC_USER": {"value": "user", "type": str},
|
||||
"BTC_RPC_PASSWORD": {"value": "passwd", "type": str},
|
||||
"BTC_RPC_CONNECT": {"value": "127.0.0.1", "type": str},
|
||||
|
||||
@@ -3,8 +3,8 @@ import logging
|
||||
from math import ceil
|
||||
from flask import Flask, request, abort, jsonify
|
||||
|
||||
from teos import LOG_PREFIX
|
||||
import teos.errors as errors
|
||||
from teos import HOST, PORT, LOG_PREFIX
|
||||
from teos.inspector import InspectionFailed
|
||||
from teos.gatekeeper import NotEnoughSlots, IdentificationFailure
|
||||
|
||||
@@ -79,7 +79,9 @@ class API:
|
||||
access.
|
||||
"""
|
||||
|
||||
def __init__(self, inspector, watcher, gatekeeper):
|
||||
def __init__(self, host, port, inspector, watcher, gatekeeper):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.inspector = inspector
|
||||
self.watcher = watcher
|
||||
self.gatekeeper = gatekeeper
|
||||
@@ -341,4 +343,4 @@ class API:
|
||||
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
||||
os.environ["WERKZEUG_RUN_MAIN"] = "true"
|
||||
|
||||
app.run(host=HOST, port=PORT)
|
||||
app.run(host=self.host, port=self.port)
|
||||
|
||||
@@ -3,6 +3,8 @@ def show_usage():
|
||||
"USAGE: "
|
||||
"\n\tpython teosd.py [global options]"
|
||||
"\n\nGLOBAL OPTIONS:"
|
||||
"\n\t--apibind \t\taddress that teos API will bind to. Defaults to 'localhost' (modifiable in conf file)."
|
||||
"\n\t--apiport \t\tport that teos API will bind to. Defaults to '9814' (modifiable in conf file)."
|
||||
"\n\t--btcnetwork \t\tNetwork bitcoind is connected to. Either mainnet, testnet or regtest. Defaults to "
|
||||
"'mainnet' (modifiable in conf file)."
|
||||
"\n\t--btcrpcuser \t\tbitcoind rpcuser. Defaults to 'user' (modifiable in conf file)."
|
||||
|
||||
@@ -11,6 +11,8 @@ feed_connect = 127.0.0.1
|
||||
feed_port = 28332
|
||||
|
||||
[teos]
|
||||
api_bind = localhost
|
||||
api_port = 9814
|
||||
subscription_slots = 100
|
||||
max_appointments = 1000000
|
||||
expiry_delta = 6
|
||||
|
||||
@@ -154,7 +154,8 @@ def main(command_line_conf):
|
||||
# FIXME: 92-block-data-during-bootstrap-db
|
||||
chain_monitor.monitor_chain()
|
||||
gatekeeper = Gatekeeper(UsersDBM(config.get("USERS_DB_PATH")), config.get("DEFAULT_SLOTS"))
|
||||
API(Inspector(block_processor, config.get("MIN_TO_SELF_DELAY")), watcher, gatekeeper).start()
|
||||
inspector = Inspector(block_processor, config.get("MIN_TO_SELF_DELAY"))
|
||||
API(config.get("API_BIND"), config.get("API_PORT"), inspector, watcher, gatekeeper).start()
|
||||
except Exception as e:
|
||||
logger.error("An error occurred: {}. Shutting down".format(e))
|
||||
exit(1)
|
||||
@@ -167,9 +168,23 @@ if __name__ == "__main__":
|
||||
opts, _ = getopt(
|
||||
argv[1:],
|
||||
"h",
|
||||
["btcnetwork=", "btcrpcuser=", "btcrpcpassword=", "btcrpcconnect=", "btcrpcport=", "datadir=", "help"],
|
||||
[
|
||||
"apiconnect=",
|
||||
"apiport=",
|
||||
"btcnetwork=",
|
||||
"btcrpcuser=",
|
||||
"btcrpcpassword=",
|
||||
"btcrpcconnect=",
|
||||
"btcrpcport=",
|
||||
"datadir=",
|
||||
"help",
|
||||
],
|
||||
)
|
||||
for opt, arg in opts:
|
||||
if opt in ["--apibind"]:
|
||||
command_line_conf["API_BIND"] = arg
|
||||
if opt in ["--apiport"]:
|
||||
command_line_conf["API_PORT"] = arg
|
||||
if opt in ["--btcnetwork"]:
|
||||
command_line_conf["BTC_NETWORK"] = arg
|
||||
if opt in ["--btcrpcuser"]:
|
||||
|
||||
Reference in New Issue
Block a user