Exemplo n.º 1
0
def _start_app(config, account):
    # create app
    app = HPCApp(config)

    # development mode
    if False:
        gevent.get_hub().SYSTEM_ERROR = BaseException

    # dump config
    pyethapp_app.dump_config(config)
    # init accounts first, as we need (and set by copy) the coinbase early FIXME
    if AccountsService in services:
        AccountsService.register_with_app(app)
    # add account
    app.services.accounts.add_account(account, store=False)

    assert app.services.accounts.coinbase in config['hdc']['validators']
    # register services
    for service in services:
        assert issubclass(service, BaseService)
        if service.name not in app.config['deactivated_services'] + [AccountsService.name]:
            assert service.name not in app.services
            service.register_with_app(app)
            assert hasattr(app.services, service.name)

    # start app
    log.info('starting')
    app.start()
    if config['post_app_start_callback'] is not None:
        config['post_app_start_callback'](app)
    return app
Exemplo n.º 2
0
def start_app(config, account):
    # create app
    app = HPCApp(config)

    # development mode
    if False:
        gevent.get_hub().SYSTEM_ERROR = BaseException

    # dump config
    pyethapp_app.dump_config(config)
    # init accounts first, as we need (and set by copy) the coinbase early FIXME
    if AccountsService in services:
        AccountsService.register_with_app(app)
    # add account
    app.services.accounts.add_account(account, store=False)

    assert app.services.accounts.coinbase in config['hdc']['validators']
    # register services
    for service in services:
        assert issubclass(service, BaseService)
        if service.name not in app.config['deactivated_services'] + [
                AccountsService.name
        ]:
            assert service.name not in app.services
            service.register_with_app(app)
            assert hasattr(app.services, service.name)

    # start app
    log.info('starting')
    app.start()
    if config['post_app_start_callback'] is not None:
        config['post_app_start_callback'](app)
    return app
Exemplo n.º 3
0
 def _init_pyethapp(self, keystore_dir=None):
     if keystore_dir is None:
         keystore_dir = self.get_keystore_path()
     # must be imported after `patch_find_library_android()`
     from devp2p.app import BaseApp
     from pyethapp.accounts import AccountsService
     self.pyethapp = BaseApp(config=dict(accounts=dict(
         keystore_dir=keystore_dir)))
     AccountsService.register_with_app(self.pyethapp)
Exemplo n.º 4
0
 def __init__(self, keystore_dir):
     # must be imported after `patch_find_library_android()`
     from devp2p.app import BaseApp
     from pyethapp.accounts import AccountsService
     self.keystore_dir = keystore_dir
     self.app = BaseApp(
         config=dict(accounts=dict(keystore_dir=self.keystore_dir)))
     AccountsService.register_with_app(self.app)
     self.patch_ethereum_tools_keys()
def app(request):
    app = BaseApp(config=dict(accounts=dict(keystore_dir=tempfile.mkdtemp())))
    AccountsService.register_with_app(app)

    def fin():
        # cleanup temporary keystore directory
        assert app.config['accounts']['keystore_dir'].startswith(tempfile.gettempdir())
        shutil.rmtree(app.config['accounts']['keystore_dir'])
        log.debug('cleaned temporary keystore dir', dir=app.config['accounts']['keystore_dir'])
    request.addfinalizer(fin)

    return app
Exemplo n.º 6
0
def app(request):
    app = BaseApp(config=dict(accounts=dict(keystore_dir=tempfile.mkdtemp())))
    AccountsService.register_with_app(app)

    def fin():
        # cleanup temporary keystore directory
        assert app.config['accounts']['keystore_dir'].startswith(tempfile.gettempdir())
        shutil.rmtree(app.config['accounts']['keystore_dir'])
        log.debug('cleaned temporary keystore dir', dir=app.config['accounts']['keystore_dir'])
    request.addfinalizer(fin)

    return app
Exemplo n.º 7
0
def start_app(config, accounts):

    # create app
    app = HPCApp(config)

    # development mode
    if False:
        gevent.get_hub().SYSTEM_ERROR = BaseException

    if config['test_privkeys']:
        # init accounts first, as we need (and set by copy) the coinbase early FIXME
        genesis_config = dict(alloc=dict())
        for privkey in config['test_privkeys']:
            assert len(privkey) == 32
            address = privtoaddr(privkey)
            account = Account.new(password='', key=privkey)
            accounts.append(account)
            # add to genesis alloc
            genesis_config['alloc'][address] = {'wei': config['test_privkeys_endowment']}

        if config['test_privkeys'] and config['eth'].get('genesis_hash'):
            del config['eth']['genesis_hash']

        konfig.update_config_from_genesis_json(config, genesis_config)

    # dump config
    pyethapp_app.dump_config(config)

    if AccountsService in services:
        AccountsService.register_with_app(app)

    # add account
    for account in accounts:
        app.services.accounts.add_account(account, store=False)

    if config['hdc']['validators']:
        assert app.services.accounts.coinbase in config['hdc']['validators']

    # register services
    for service in services:
        assert issubclass(service, BaseService)
        if service.name not in app.config['deactivated_services'] + [AccountsService.name]:
            assert service.name not in app.services
            service.register_with_app(app)
            assert hasattr(app.services, service.name)

    # start app
    log.info('starting')
    app.start()
    for cb in config['post_app_start_callbacks']:
        cb(app)
    return app
def test_restart_service(app, account, password):
    s = app.services.accounts
    account.path = os.path.join(app.config["accounts"]["keystore_dir"], "account1")
    s.add_account(account)
    app.services.pop("accounts")
    AccountsService.register_with_app(app)
    s = app.services.accounts
    assert len(s) == 1
    reloaded_account = s.accounts[0]
    assert reloaded_account.path == account.path
    assert reloaded_account.address == account.address
    assert reloaded_account.uuid == account.uuid
    assert reloaded_account.privkey is None
    assert reloaded_account.pubkey is None
    reloaded_account.unlock(password)
    assert reloaded_account.privkey == account.privkey
    assert reloaded_account.pubkey == account.pubkey
    account.path = None
def test_restart_service(app, account, password):
    s = app.services.accounts
    account.path = os.path.join(app.config['accounts']['keystore_dir'], 'account1')
    s.add_account(account)
    app.services.pop('accounts')
    AccountsService.register_with_app(app)
    s = app.services.accounts
    assert len(s) == 1
    reloaded_account = s.accounts[0]
    assert reloaded_account.path == account.path
    assert reloaded_account.address == account.address
    assert reloaded_account.uuid == account.uuid
    assert reloaded_account.privkey is None
    assert reloaded_account.pubkey is None
    reloaded_account.unlock(password)
    assert reloaded_account.privkey == account.privkey
    assert reloaded_account.pubkey == account.pubkey
    account.path = None
Exemplo n.º 10
0
def _start_app(account, config, validators):
    # create app
    app = HPCApp(config)
    # development mode
    if True:
        gevent.get_hub().SYSTEM_ERROR = BaseException

    # dump config
    pyethapp_app.dump_config(config)
    # init accounts first, as we need (and set by copy) the coinbase early FIXME
    if AccountsService in services:
        AccountsService.register_with_app(app)
    # add account
    app.services.accounts.add_account(account, store=False)

    assert app.services.accounts.coinbase in validators
    # register services
    for service in services:
        assert issubclass(service, BaseService)
        if service.name not in app.config['deactivated_services'] + [AccountsService.name]:
            assert service.name not in app.services
            service.register_with_app(app)
            assert hasattr(app.services, service.name)

    # start app
    log.info('starting')
    app.start()
    if config['post_app_start_callback'] is not None:
        config['post_app_start_callback'](app)

    # wait for interrupt
    evt = Event()
    gevent.signal(signal.SIGQUIT, evt.set)
    gevent.signal(signal.SIGTERM, evt.set)
    gevent.signal(signal.SIGINT, evt.set)
    evt.wait()
    # finally stop
    app.stop()
Exemplo n.º 11
0
    def __init__(self, privkey, validators, simenv=None):
        self.config = copy.deepcopy(hdc_service.ChainService.default_config)
        self.config['db'] = dict(path='_db')
        self.config['data_dir'] = tempfile.mkdtemp()
        self.config['hdc']['validators'] = validators

        initial_alloc = dict((a, dict(wei=2 ** 200)) for a in validators)
        self.config['eth']['block']['GENESIS_INITIAL_ALLOC'] = initial_alloc

        self.simenv = simenv
        self.services = self.Services()
        self.services.db = EphemDB()
        self.services.accounts = AccountsService(self)
        self.services.peermanager = PeerManagerMock(self)
        account = Account.new(password='', key=privkey)
        self.services.accounts.add_account(account, store=False)
        if simenv:
            self.services.chainservice = SimChainService(self, simenv=simenv)
        else:
            self.services.chainservice = hdc_service.ChainService(self)
        self.isactive = True
Exemplo n.º 12
0
 def __init__(self, privkey):
     self.services = self.Services()
     self.services.db = EphemDB()
     self.services.accounts = AccountsService(self)
     account = Account.new(password='', key=privkey)
     self.services.accounts.add_account(account, store=False)
Exemplo n.º 13
0
 def __init__(self, keystore_dir=None):
     if keystore_dir is None:
         keystore_dir = PyWalib.get_default_keystore_path()
     self.app = BaseApp(config=dict(accounts=dict(
         keystore_dir=keystore_dir)))
     AccountsService.register_with_app(self.app)