Skip to content

Commit

Permalink
Welcome message with more info
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Mar 20, 2024
1 parent ee3ec30 commit 5221440
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
44 changes: 35 additions & 9 deletions counterparty-cli/counterpartycli/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import argparse
import logging
from urllib.parse import quote_plus as urlencode

from termcolor import cprint

Expand Down Expand Up @@ -58,19 +59,48 @@
[('--utxo-locks-max-age',), {'type': int, 'default': config.DEFAULT_UTXO_LOCKS_MAX_AGE, 'help': 'how long to keep a lock on a UTXO being tracked'}],
]

def welcome_message(action, server_configfile):
cprint(f'Running v{config.__version__} of {config.FULL_APP_NAME}.', 'magenta')

# print some info
cprint(f"Configuration file: {server_configfile}", 'light_grey')
cprint(f"Counterparty database: {config.DATABASE}", 'light_grey')
if config.LOG:
cprint(f'Writing log to file: `{config.LOG}`', 'light_grey')
else:
cprint('Warning: log disabled', 'yellow')
if config.API_LOG:
cprint(f'Writing API accesses log to file: `{config.API_LOG}`', 'light_grey')
else:
cprint('Warning: API log disabled', 'yellow')

if config.VERBOSE:
if config.TESTNET:
cprint('NETWORK: Testnet', 'light_grey')
elif config.REGTEST:
cprint('NETWORK: Regtest', 'light_grey')
else:
cprint('NETWORK: Mainnet', 'light_grey')

pass_str = f":{urlencode(config.BACKEND_PASSWORD)}@"
cprint(f'BACKEND_URL: {config.BACKEND_URL.replace(pass_str, ":*****@")}', 'light_grey')
cprint(f'INDEXD_URL: {config.INDEXD_URL}', 'light_grey')
pass_str = f":{urlencode(config.RPC_PASSWORD)}@"
cprint(f'RPC: {config.RPC.replace(pass_str, ":*****@")}', 'light_grey')

cprint(f"{'-' * 30} {action} {'-' * 30}\n", 'green')
exit()

class VersionError(Exception):
pass
def main():
cprint(f'Running v{config.__version__} of {config.FULL_APP_NAME}.', 'magenta')

if os.name == 'nt':
from counterpartylib.lib import util_windows
#patch up cmd.exe's "challenged" (i.e. broken/non-existent) UTF-8 logging
util_windows.fix_win32_unicode()

# Post installation tasks
generate_config_files()
server_configfile = generate_config_files()

# Parse command-line arguments.
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -163,14 +193,10 @@ def main():
log_file=config.LOG,
log_in_console=args.action == 'start'
)

logger.info(f'Running v{APP_VERSION} of {APP_NAME}.')

# print some info
if config.LOG:
cprint(f'Writing log to file: `{config.LOG}`', 'light_grey')
if args.action == 'start' and config.API_LOG:
cprint(f'Writing API accesses log to file: `{config.API_LOG}`', 'light_grey')
cprint(f"{'-' * 30} {args.action} {'-' * 30}\n", 'green')
welcome_message(args.action, server_configfile)

# Bootstrapping
if args.action == 'bootstrap':
Expand Down
1 change: 1 addition & 0 deletions counterparty-cli/counterpartycli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def generate_config_files():
if not os.path.exists(client_configfile):
client_known_config = server_to_client_config(server_known_config)
generate_config_file(client_configfile, CLIENT_CONFIG_ARGS, client_known_config)
return server_configfile

def zip_folder(folder_path, zip_path):
zip_file = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
Expand Down
26 changes: 22 additions & 4 deletions counterparty-lib/counterpartylib/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ def initialise_config(database_file=None, log_file=None, api_log_file=None, no_l

if config.TESTNET:
bitcoinlib.SelectParams('testnet')
logger.debug('NETWORK: testnet')
elif config.REGTEST:
bitcoinlib.SelectParams('regtest')
logger.debug('NETWORK: regtest')
else:
bitcoinlib.SelectParams('mainnet')
logger.debug('NETWORK: mainnet')

network = ''
if config.TESTNET:
Expand All @@ -160,11 +163,20 @@ def initialise_config(database_file=None, log_file=None, api_log_file=None, no_l
filename = f'{config.APP_NAME}{network}.db'
config.DATABASE = os.path.join(data_dir, filename)

logger.debug('DATABASE: %s', config.DATABASE)

# Log directory
log_dir = appdirs.user_log_dir(appauthor=config.XCP_NAME, appname=config.APP_NAME)
if not os.path.isdir(log_dir):
os.makedirs(log_dir, mode=0o755)

# Set up logging.
config.VERBOSE = verbose
config.QUIET = quiet

logger.debug('VERBOSE: %s', config.VERBOSE)
logger.debug('QUIET: %s', config.QUIET)

# Log
if no_log_files:
config.LOG = None
Expand All @@ -173,10 +185,8 @@ def initialise_config(database_file=None, log_file=None, api_log_file=None, no_l
config.LOG = os.path.join(log_dir, filename)
else: # user-specified location
config.LOG = log_file

# Set up logging.
config.VERBOSE = verbose
config.QUIET = quiet

logger.debug('LOG: %s', config.LOG)

if no_log_files: # no file logging
config.API_LOG = None
Expand All @@ -186,6 +196,8 @@ def initialise_config(database_file=None, log_file=None, api_log_file=None, no_l
else: # user-specified location
config.API_LOG = api_log_file

logger.debug('API_LOG: %s', config.API_LOG)

config.API_LIMIT_ROWS = api_limit_rows

##############
Expand Down Expand Up @@ -258,6 +270,8 @@ def initialise_config(database_file=None, log_file=None, api_log_file=None, no_l
config.BACKEND_URL = 'https://' + config.BACKEND_URL
else:
config.BACKEND_URL = 'http://' + config.BACKEND_URL

logger.debug('BACKEND_URL: %s', config.BACKEND_URL.replace(f':{config.BACKEND_PASSWORD}@', ':*****@'))

# Indexd RPC host
if indexd_connect:
Expand Down Expand Up @@ -286,6 +300,8 @@ def initialise_config(database_file=None, log_file=None, api_log_file=None, no_l
# Construct Indexd URL.
config.INDEXD_URL = 'http://' + config.INDEXD_CONNECT + ':' + str(config.INDEXD_PORT)

logger.debug('INDEXD_URL: %s', config.INDEXD_URL)

##############
# THINGS WE SERVE

Expand Down Expand Up @@ -572,6 +588,8 @@ def configure_rpc(rpc_password=None):
else:
config.RPC = 'http://' + config.RPC_HOST + ':' + str(config.RPC_PORT) + config.RPC_WEBROOT

logger.debug('RPC: %s', config.RPC.replace(f':{urlencode(config.RPC_PASSWORD)}@', ':*****@'))


def bootstrap():
data_dir = appdirs.user_data_dir(appauthor=config.XCP_NAME, appname=config.APP_NAME, roaming=True)
Expand Down

0 comments on commit 5221440

Please sign in to comment.