import time import signal import threading import atexit import subprocess from typing import List from enigma_docker_common.logger import get_logger logger = get_logger('worker.p2p-node') class P2PNode(threading.Thread): exec_file = 'cli_app.js' runner = 'node' kill_now = False def __init__(self, ether_node: str, public_address: str, contract_address: str, key_mgmt_node: str, abi_path: str, proxy: int = 3346, core_addr: str = 'localhost:5552', peer_name: str = 'peer1', random_db: bool = True, auto_init: bool = True, bootstrap: bool = False, bootstrap_address: str = 'B1',
import os import json import pathlib from p2p_node import P2PNode from bootstrap_loader import BootstrapLoader from enigma_docker_common.config import Config from enigma_docker_common.provider import Provider from enigma_docker_common.logger import get_logger from enigma_docker_common.crypto import open_eth_keystore from enigma_docker_common.blockchain import get_initial_coins from enigma_docker_common.enigma import EnigmaTokenContract logger = get_logger('worker.p2p-startup') # required configuration parameters -- these can all be overridden as environment variables required = [ # required by provider AND locally 'CONTRACT_DISCOVERY_ADDRESS', 'KEY_MANAGEMENT_DISCOVERY', # defaults in local config file 'ETH_NODE_ADDRESS', 'ENIGMA_CONTRACT_FILE_NAME', 'CORE_ADDRESS', 'CORE_PORT', 'CONTRACTS_FOLDER', 'KEY_MANAGEMENT_ADDRESS', 'FAUCET_URL', 'MINIMUM_ETHER_BALANCE', 'BALANCE_WAIT_TIME', 'MIN_CONFIRMATIONS'
import web3 import threading from flask import Flask, request from flask_cors import CORS from flask_restplus import Api, Resource, abort from enigma_docker_common.config import Config from enigma_docker_common.logger import get_logger from enigma_docker_common.provider import Provider logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR) logging.getLogger("werkzeug").setLevel(logging.ERROR) # use this logger if you need to add logs. No need to customize the logger further logger = get_logger('enigma-contract.faucet') required = [ "ETH_NODE_ADDRESS", "CONTRACT_DISCOVERY_ADDRESS", "FAUCET_PORT", "BLOCK_TIME" ] env_defaults = { 'K8S': './config/k8s_config.json', 'TESTNET': './config/testnet_config.json', 'MAINNET': './config/mainnet_config.json', 'COMPOSE': './config/compose_config.json' } config = Config(required=required, config_file=env_defaults[os.getenv('ENIGMA_ENV', 'COMPOSE')])
import functools import json from enigma_docker_common import storage from enigma_docker_common import config from enigma_docker_common.logger import get_logger logger = get_logger('bootstrap-loader') class BootstrapLoader: bootstrap_file_name = "bootstrap_addresses.json" def __init__(self, cfg: config.Config, bootstrap_id: str = ''): self.env = cfg.get('ENIGMA_ENV', 'COMPOSE') self.bootstrap_id = bootstrap_id if self.env == 'COMPOSE': self.storage = storage.LocalStorage( directory=cfg["LOCAL_LIBP2P_KEY_PATH"]) self.storage_public = storage.LocalStorage( directory=cfg["LOCAL_LIBP2P_KEY_PATH"]) else: self.storage = storage.AzureContainerFileService( directory='bootstrap') self.storage_public = storage.AzureContainerFileService( directory='bootstrap-public') self._address: str = '' self._key: str = '' self._public: str = '' self.keyfile: str = ''
def run(): logger = get_logger('test') logger.info(f'Log level: INFO') logger.debug('and this shouldn\'t work') logger.setLevel("DEBUG") logger.debug('this should work')
from flask_restplus import Api, Resource from flask_restplus import abort from enigma_docker_common.config import Config from enigma_docker_common.logger import get_logger env_defaults = { 'K8S': './config/k8s_config.json', 'TESTNET': './config/testnet_config.json', 'MAINNET': './config/mainnet_config.json', 'COMPOSE': './config/compose_config.json' } config = Config(config_file=env_defaults[os.getenv('ENIGMA_ENV', 'COMPOSE')]) logger = get_logger('enigma-contract.server') logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR) logging.getLogger("werkzeug").setLevel(logging.ERROR) application = Flask(__name__) CORS(application) api = Api(app=application, version='1.0') contract_ns = api.namespace('contract', description='Contract operations') @contract_ns.route("/address") class GetAddress(Resource): """ returns a list of tracked addresses for a chain/network. If parameters are empty, will return all addresses """
import os import json from enigma_docker_common.config import Config from enigma_docker_common.provider import Provider from enigma_docker_common.logger import get_logger logger = get_logger('client-startup') # required configuration parameters -- these can all be overridden as environment variables required = [ # required by provider AND locally 'CONTRACT_DISCOVERY_PORT', 'CONTRACT_DISCOVERY_ADDRESS', # defaults in local config file 'ETH_NODE_ADDRESS', 'ENIGMA_CONTRACT_FILE_NAME', 'CONTRACTS_FOLDER', 'FAUCET_URL', 'MINIMUM_ETHER_BALANCE', 'ETH_NODE_PORT', 'WORKER_URL', 'PROXY_PORT' ] # local path to where we save the private key/public key if we generate it locally KEY_PAIR_PATH = os.path.dirname(os.path.dirname(__file__)) env_defaults = { 'K8S': './config/k8s_config.json', 'TESTNET': './config/testnet_config.json', 'MAINNET': './config/mainnet_config.json',
import os import time import pathlib import subprocess import argparse SGX_ENV_PATH = '/opt/sgxsdk/environment' from enigma_docker_common.config import Config from enigma_docker_common.logger import get_logger logger = get_logger('worker.core-startup') required = ['RUST_BACKTRACE', 'SPID', 'PORT', 'ATTESTATION_RETRIES'] env_defaults = {'K8S': './core/config/k8s_config.json', 'TESTNET': './core/config/testnet_config.json', 'MAINNET': './core/config/mainnet_config.json', 'COMPOSE': './core/config/compose_config.json'} def init_arg_parse() -> argparse.ArgumentParser: p = argparse.ArgumentParser() p.add_argument("-e", "--executable", help="Path to Key Management executable", type=str, default='/root/core/bin/enigma-core-app') return p def map_log_level_to_exec_flags(loglevel: str) -> str: level = loglevel.upper() if level == "DEBUG":
# Environment options: COMPOSE, K8S, TESTNET, MAINNET import os import json import subprocess import pathlib import threading from km_address_server import run from enigma_docker_common.config import Config from enigma_docker_common.provider import Provider from enigma_docker_common.logger import get_logger from enigma_docker_common.crypto import open_eth_keystore from enigma_docker_common.blockchain import get_initial_coins logger = get_logger('key_management.startup') required = [ # global environment setting 'ENIGMA_ENV', # required by provider AND locally 'CONTRACT_DISCOVERY_ADDRESS', 'KEY_MANAGEMENT_DISCOVERY', # defaults in local config file 'ETH_NODE_ADDRESS', 'CONTRACTS_FOLDER', 'DEFAULT_CONFIG_PATH', 'FAUCET_URL', 'KEYPAIR_FILE_NAME', 'TEMP_CONFIG_PATH', "MINIMUM_ETHER_BALANCE", "MINIMUM_ENG_BALANCE",
from flask_cors import CORS from flask_restplus import Api, Resource from flask_restplus import abort from enigma_docker_common.config import Config from enigma_docker_common.logger import get_logger env_defaults = {'K8S': './config/k8s_config.json', 'TESTNET': './config/testnet_config.json', 'MAINNET': './config/mainnet_config.json', 'COMPOSE': './config/compose_config.json'} config = Config(config_file=env_defaults[os.getenv('ENIGMA_ENV', 'COMPOSE')]) logger = get_logger('km.server') logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR) logging.getLogger("werkzeug").setLevel(logging.ERROR) application = Flask(__name__) CORS(application) api = Api(app=application, version='1.0') ns = api.namespace('km', description='Contract operations') @ns.route("/address") class GetAddress(Resource): """ returns a list of tracked addresses for a chain/network. If parameters are empty, will return all addresses """
# Environment options: LOCAL, K8S, TESTNET, MAINNET import logging import sys import os from web3.auto import w3 as auto_w3 from enigma_docker_common.config import Config from enigma_docker_common.provider import Provider from enigma_docker_common.logger import get_logger logger = get_logger(__file__) # required configuration parameters -- these can all be overridden as environment variables required = [ # required by provider AND locally 'PRINCIPAL_ADDRESS_PATH', 'CONTRACT_DISCOVERY_ADDRESS', 'KEY_MANAGEMENT_DISCOVERY' ] env_defaults = { 'K8S': './config/k8s_config.json', 'TESTNET': './config/testnet_config.json', 'MAINNET': './config/mainnet_config.json', 'COMPOSE': './config/compose_config.json' } def save_to_path(path, file): logger.info(f'Saving file to path: {path}') os.makedirs(os.path.dirname(path), exist_ok=True)