Ejemplo n.º 1
0
def main():
    parser = init_arg_parse()
    args = parser.parse_args()

    try:
        config = Config(config_file=env_defaults[os.getenv('ENIGMA_ENV', 'COMPOSE')])
    except (ValueError, IOError):
        exit(-1)

    if not os.getenv('RUST_BACKTRACE'):
        if config['RUST_BACKTRACE'] != '0':
            os.environ["RUST_BACKTRACE"] = config['RUST_BACKTRACE']

    debug_trace_flags = map_log_level_to_exec_flags(config.get('LOG_LEVEL', 'INFO'))
    spid = config['SPID']
    port = config['PORT']
    attestation_retries = config['ATTESTATION_RETRIES']
    os.chdir(pathlib.Path(args.executable).parent)

    # wait for SGX service to start
    time.sleep(2)
    env = os.environ.copy()
    logger.debug(f'Environment: {env}')
    subprocess.call([f'{args.executable}', f'{debug_trace_flags}',
                     '-p', f'{port}',
                     '--spid', f'{spid}',
                     '-r', f'{attestation_retries}'], env=env)
Ejemplo n.º 2
0
 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 = ''
Ejemplo n.º 3
0
]

env_defaults = {
    'K8S': './p2p/config/k8s_config.json',
    'TESTNET': './p2p/config/testnet_config.json',
    'MAINNET': './p2p/config/mainnet_config.json',
    'COMPOSE': './p2p/config/compose_config.json'
}

env = os.getenv('ENIGMA_ENV', 'COMPOSE')

is_bootstrap = os.getenv('BOOTSTRAP', '')

try:
    config = Config(required=required,
                    config_file=env_defaults[os.getenv('ENIGMA_ENV',
                                                       'COMPOSE')])
except (ValueError, IOError):
    exit(-1)

# 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__))


def save_to_path(path, file, flags='wb+'):
    logger.info(f'Saving file to path: {path}')
    os.makedirs(os.path.dirname(path), exist_ok=True)
    with open(path, flags) as f:
        f.write(file)

Ejemplo n.º 4
0
# 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')])
eng_provider = Provider(config=config)

PORT = config['FAUCET_PORT']
NODE_URL = config["ETH_NODE_ADDRESS"]

ETH_ALLOWANCE_AMT = config.get('ALLOWANCE_AMOUNT', web3.Web3.toWei(1, 'ether'))
ENG_ALLOWANCE_AMT = config.get('ENG_ALLOWANCE_AMOUNT', 100000)

token_contract_abi = json.loads(eng_provider.enigma_token_abi)
token_contract_address = eng_provider.token_contract_address

enigma_abi = json.loads(eng_provider.enigma_abi)
enigma_contract_address = eng_provider.enigma_contract_address

provider = web3.HTTPProvider(NODE_URL)
Ejemplo n.º 5
0
from flask import Flask, request
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('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):
Ejemplo n.º 6
0
    '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)
    with open(path, 'wb+') as f:
        f.write(file)


if __name__ == '__main__':

    logger.info('STARTING P2P STARTUP')
    env = os.getenv('ENIGMA_ENV', 'COMPOSE')
    config = Config(required=required, config_file=env_defaults[env])
    provider = Provider(config=config)

    # *** Load parameters from config

    contracts_folder_path = config['CONTRACTS_FOLDER']
    enigma_abi_filename = config['ENIGMA_CONTRACT_FILE_NAME']
    eth_node_address = f'{config["ETH_NODE_ADDRESS"]}:{config["ETH_NODE_PORT"]}'

    # Load Enigma.json ABI
    enigma_contract_abi = provider.enigma_abi

    if config.get('SGX_MODE', 'SW') == 'SW':
        enigma_abi_filename = 'EnigmaSimulation.json'

    contract_abi_path = contracts_folder_path + enigma_abi_filename
Ejemplo n.º 7
0
    if level == "DEBUG":
        return '-vvv'
    if level == "INFO":
        return '-vv'
    if level == "WARNING":
        return '-v'
    else:
        return ''


if __name__ == '__main__':
    # parse arguments
    logger.info('STARTING KEY MANAGEMENT.....')
    logger.info(f'Enviroment: {env}')

    config = Config(required=required, config_file=env_defaults[env])
    provider = Provider(config=config)

    keypair = config['KEYPAIR_PATH']
    public = config['KEYPAIR_PUBLIC_PATH']
    config['URL'] = f'{config["ETH_NODE_ADDRESS"]}'
    # not sure we want to let people set the executable from outside, especially
    # since we're running as root atm O.o
    if 'EXECUTABLE_PATH' in os.environ:
        del os.environ['EXECUTABLE_PATH']

    executable = config['EXECUTABLE_PATH']
    os.chdir(pathlib.Path(executable).parent)

    if not os.path.exists(keypair) or not os.path.exists(public):
        generate_keypair(executable, keypair, public,