Skip to content

Commit

Permalink
Merge pull request #370 from fetchai/develop
Browse files Browse the repository at this point in the history
Release v0.1.12
  • Loading branch information
DavidMinarsch authored Nov 3, 2019
2 parents df6babf + b1e4403 commit 907fbad
Show file tree
Hide file tree
Showing 70 changed files with 2,734 additions and 1,025 deletions.
9 changes: 8 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Release History

- Provides examples and fixes.


0.1.2 (2019-09-16)
-------------------

Expand Down Expand Up @@ -92,3 +91,11 @@ Release History
- Adds ledger integrations for fetch.ai and ethereum
- Adds carpark examples and ledger examples
- Multiple additional minor fixes and changes

0.1.12 (2019-11-01)
-------------------

- Adds TCP connection (server and client)
- Fixes some examples and docs
- Refactors crypto modules and adds additional tests
- Multiple additional minor fixes and changes
2 changes: 1 addition & 1 deletion aea/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
__title__ = 'aea'
__description__ = 'Autonomous Economic Agent framework'
__url__ = 'https://github.com/fetchai/agents-aea.git'
__version__ = '0.1.11'
__version__ = '0.1.12'
__author__ = 'Fetch.AI Limited'
__license__ = 'Apache 2.0'
__copyright__ = '2019 Fetch.AI Limited'
99 changes: 95 additions & 4 deletions aea/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,103 @@
AEAConfigException, _load_env_file
from aea.cli.install import install
from aea.connections.base import Connection
from aea.crypto.helpers import _verify_or_create_private_keys, _verify_ledger_apis_access
from aea.crypto.ledger_apis import LedgerApis
from aea.crypto.wallet import Wallet, DEFAULT
from aea.configurations.loader import ConfigLoader
from aea.configurations.base import AgentConfig, DEFAULT_AEA_CONFIG_FILE, PrivateKeyPathConfig, LedgerAPIConfig
from aea.crypto.ethereum import ETHEREUM
from aea.crypto.fetchai import FETCHAI
from aea.crypto.helpers import _create_default_private_key, _create_fetchai_private_key, _create_ethereum_private_key, DEFAULT_PRIVATE_KEY_FILE, FETCHAI_PRIVATE_KEY_FILE, ETHEREUM_PRIVATE_KEY_FILE, _try_validate_private_key_pem_path, _try_validate_fet_private_key_path, _try_validate_ethereum_private_key_path
from aea.crypto.ledger_apis import LedgerApis, _try_to_instantiate_fetchai_ledger_api, _try_to_instantiate_ethereum_ledger_api, SUPPORTED_LEDGER_APIS
from aea.crypto.wallet import Wallet, DEFAULT, SUPPORTED_CRYPTOS
from aea.mail.base import MailBox


def _verify_or_create_private_keys(ctx: Context) -> None:
"""
Verify or create private keys.
:param ctx: Context
"""
path = Path(DEFAULT_AEA_CONFIG_FILE)
agent_loader = ConfigLoader("aea-config_schema.json", AgentConfig)
fp = open(str(path), mode="r", encoding="utf-8")
aea_conf = agent_loader.load(fp)

for identifier, value in aea_conf.private_key_paths.read_all():
if identifier not in SUPPORTED_CRYPTOS:
ValueError("Unsupported identifier in private key paths.")

default_private_key_config = aea_conf.private_key_paths.read(DEFAULT)
if default_private_key_config is None:
_create_default_private_key()
default_private_key_config = PrivateKeyPathConfig(DEFAULT, DEFAULT_PRIVATE_KEY_FILE)
aea_conf.private_key_paths.create(default_private_key_config.ledger, default_private_key_config)
else:
default_private_key_config = cast(PrivateKeyPathConfig, default_private_key_config)
try:
_try_validate_private_key_pem_path(default_private_key_config.path)
except FileNotFoundError:
logger.error("File {} for private key {} not found.".format(repr(default_private_key_config.path), default_private_key_config.ledger))
sys.exit(1)

fetchai_private_key_config = aea_conf.private_key_paths.read(FETCHAI)
if fetchai_private_key_config is None:
_create_fetchai_private_key()
fetchai_private_key_config = PrivateKeyPathConfig(FETCHAI, FETCHAI_PRIVATE_KEY_FILE)
aea_conf.private_key_paths.create(fetchai_private_key_config.ledger, fetchai_private_key_config)
else:
fetchai_private_key_config = cast(PrivateKeyPathConfig, fetchai_private_key_config)
try:
_try_validate_fet_private_key_path(fetchai_private_key_config.path)
except FileNotFoundError:
logger.error("File {} for private key {} not found.".format(repr(fetchai_private_key_config.path), fetchai_private_key_config.ledger))
sys.exit(1)

ethereum_private_key_config = aea_conf.private_key_paths.read(ETHEREUM)
if ethereum_private_key_config is None:
_create_ethereum_private_key()
ethereum_private_key_config = PrivateKeyPathConfig(ETHEREUM, ETHEREUM_PRIVATE_KEY_FILE)
aea_conf.private_key_paths.create(ethereum_private_key_config.ledger, ethereum_private_key_config)
else:
ethereum_private_key_config = cast(PrivateKeyPathConfig, ethereum_private_key_config)
try:
_try_validate_ethereum_private_key_path(ethereum_private_key_config.path)
except FileNotFoundError:
logger.error("File {} for private key {} not found.".format(repr(ethereum_private_key_config.path), ethereum_private_key_config.ledger))
sys.exit(1)

# update aea config
path = Path(DEFAULT_AEA_CONFIG_FILE)
fp = open(str(path), mode="w", encoding="utf-8")
agent_loader.dump(aea_conf, fp)
ctx.agent_config = aea_conf


def _verify_ledger_apis_access() -> None:
"""Verify access to ledger apis."""
path = Path(DEFAULT_AEA_CONFIG_FILE)
agent_loader = ConfigLoader("aea-config_schema.json", AgentConfig)
fp = open(str(path), mode="r", encoding="utf-8")
aea_conf = agent_loader.load(fp)

for identifier, value in aea_conf.ledger_apis.read_all():
if identifier not in SUPPORTED_LEDGER_APIS:
ValueError("Unsupported identifier in ledger apis.")

fetchai_ledger_api_config = aea_conf.ledger_apis.read(FETCHAI)
if fetchai_ledger_api_config is None:
logger.debug("No fetchai ledger api config specified.")
else:
fetchai_ledger_api_config = cast(LedgerAPIConfig, fetchai_ledger_api_config)
_try_to_instantiate_fetchai_ledger_api(fetchai_ledger_api_config.addr, fetchai_ledger_api_config.port)

ethereum_ledger_config = aea_conf.ledger_apis.read(ETHEREUM)
if ethereum_ledger_config is None:
logger.debug("No ethereum ledger api config specified.")
else:
ethereum_ledger_config = cast(LedgerAPIConfig, ethereum_ledger_config)
_try_to_instantiate_ethereum_ledger_api(ethereum_ledger_config.addr, ethereum_ledger_config.port)


def _setup_connection(connection_name: str, public_key: str, ctx: Context) -> Connection:
"""
Set up a connection.
Expand Down Expand Up @@ -96,7 +187,7 @@ def run(click_context, connection_name: str, env_file: str, install_deps: bool):
agent_name = cast(str, ctx.agent_config.agent_name)

_verify_or_create_private_keys(ctx)
_verify_ledger_apis_access(ctx)
_verify_ledger_apis_access()
private_key_paths = dict([(identifier, config.path) for identifier, config in ctx.agent_config.private_key_paths.read_all()])
ledger_api_configs = dict([(identifier, (config.addr, config.port)) for identifier, config in ctx.agent_config.ledger_apis.read_all()])

Expand Down
20 changes: 20 additions & 0 deletions aea/connections/tcp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2018-2019 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""Implementation of a TCP connection."""
Loading

0 comments on commit 907fbad

Please sign in to comment.