Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/erc1155 #1466

Merged
merged 4 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ignore-patterns=serialization.py,message.py,__main__.py,.*_pb2.py,launch.py,transaction.py

[MESSAGES CONTROL]
disable=C0103,C0201,C0330,C0301,C0302,W1202,W1203,W0511,W0107,W0105,W0621,W0235,W0613,W0221,R0902,R0913,R0914,R1720,R1705,R0801,R0904,R0903,R0911,R0912,R1721,R0901,R1718,R1723,R1704,R0916,R1714,R1702,R0123,R0915,R1710,R1703,R1716,R1711,R1722,R0401
disable=C0103,C0201,C0330,C0301,C0302,W1202,W1203,W0511,W0107,W0105,W0621,W0235,W0613,W0221,R0902,R0913,R0914,R1720,R1705,R0801,R0904,R0903,R0911,R0912,R0901,R1704,R0916,R1702,R0915,R1710,R1703,R0401

ENABLED:
# W0703: broad-except
Expand All @@ -20,7 +20,14 @@ ENABLED:
# W0106: expression-not-assigned
# R0201: no-self-use
# R0205: useless-object-inheritance

# R1723: no-else-break
# R1721: unnecessary-comprehension
# R1718: consider-using-set-comprehension
# R1716: chained-comparison
# R1714: consider-using-in
# R0123: literal-comparison
# R1711: useless-return
# R1722: consider-using-sys-exit

## Resolve these:
# R0401: cyclic-import
Expand All @@ -30,25 +37,17 @@ ENABLED:
# R0914: too-many-locals
# R1720: no-else-raise
# R1705: no-else-return
# R1723: no-else-break
# R0904: too-many-public-methods
# R0903: too-few-public-methods
# R0911: too-many-return-statements
# R0912: too-many-branches
# R1721: unnecessary-comprehension
# R0901: too-many-ancestors
# R1718: consider-using-set-comprehension
# R1716: chained-comparison
# R1704: redefined-argument-from-local
# R0916: too-many-boolean-expressions
# R1714: consider-using-in
# R1702: too-many-nested-blocks
# R0123: literal-comparison
# R0915: too-many-statements
# R1710: inconsistent-return-statements
# R1703: simplifiable-if-statement
# R1711: useless-return
# R1722: consider-using-sys-exit

## Keep the following:
# C0103: invalid-name
Expand Down
3 changes: 1 addition & 2 deletions aea/cli/generate_wealth.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ def _wait_funds_release(agent_config, wallet, type_):
while time.time() < end_time:
if start_balance != try_get_balance(agent_config, wallet, type_):
break # pragma: no cover
else:
time.sleep(1)
time.sleep(1)
12 changes: 9 additions & 3 deletions aea/configurations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ def delete(self, item_id: str) -> None:

def read_all(self) -> List[Tuple[str, T]]:
"""Read all the items."""
return [(k, v) for k, v in self._items_by_id.items()]
return [ # pylint: disable=unnecessary-comprehension
(k, v) for k, v in self._items_by_id.items()
]


class PublicId(JSONSerializable):
Expand Down Expand Up @@ -1329,7 +1331,9 @@ def package_dependencies(self) -> Set[ComponentId]:
@property
def private_key_paths_dict(self) -> Dict[str, str]:
"""Get dictionary version of private key paths."""
return {key: path for key, path in self.private_key_paths.read_all()}
return { # pylint: disable=unnecessary-comprehension
key: path for key, path in self.private_key_paths.read_all()
}

@property
def ledger_apis_dict(self) -> Dict[str, Dict[str, Union[str, int]]]:
Expand All @@ -1342,7 +1346,9 @@ def ledger_apis_dict(self) -> Dict[str, Dict[str, Union[str, int]]]:
@property
def connection_private_key_paths_dict(self) -> Dict[str, str]:
"""Get dictionary version of connection private key paths."""
return {key: path for key, path in self.connection_private_key_paths.read_all()}
return { # pylint: disable=unnecessary-comprehension
key: path for key, path in self.connection_private_key_paths.read_all()
}

@property
def default_connection(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion aea/crypto/registries/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def __init__(self):
@property
def supported_ids(self) -> Set[str]:
"""Get the supported item ids."""
return set([str(id_) for id_ in self.specs.keys()])
return {str(id_) for id_ in self.specs.keys()}

def register(
self,
Expand Down
2 changes: 1 addition & 1 deletion aea/helpers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def wrapper(*args, **kwargs):
try:
return fn(*args, **kwargs)
except Exception as e: # pylint: disable=broad-except # pragma: no cover # generic code
logger.exception(e)
logger.debug(e)
if error_message:
log = get_logger_method(fn, logger_method)
log(error_message.format(e))
Expand Down
19 changes: 6 additions & 13 deletions aea/skills/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,10 @@ def parse_module(
name_to_class = dict(behaviours_classes)
_print_warning_message_for_non_declared_skill_components(
set(name_to_class.keys()),
set(
[
behaviour_config.class_name
for behaviour_config in behaviour_configs.values()
]
),
{
behaviour_config.class_name
for behaviour_config in behaviour_configs.values()
},
"behaviours",
path,
)
Expand Down Expand Up @@ -463,12 +461,7 @@ def parse_module(
name_to_class = dict(handler_classes)
_print_warning_message_for_non_declared_skill_components(
set(name_to_class.keys()),
set(
[
handler_config.class_name
for handler_config in handler_configs.values()
]
),
{handler_config.class_name for handler_config in handler_configs.values()},
"handlers",
path,
)
Expand Down Expand Up @@ -561,7 +554,7 @@ def parse_module(
name_to_class = dict(models)
_print_warning_message_for_non_declared_skill_components(
set(name_to_class.keys()),
set([model_config.class_name for model_config in model_configs.values()]),
{model_config.class_name for model_config in model_configs.values()},
"models",
path,
)
Expand Down
6 changes: 4 additions & 2 deletions benchmark/framework/aea_test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,16 @@ def __enter__(self) -> None:
"""Contenxt manager enter."""
self.start_loop()

def __exit__(self, exc_type=None, exc=None, traceback=None) -> None:
def __exit__( # pylint: disable=useless-return
self, exc_type=None, exc=None, traceback=None
) -> None:
"""
Context manager exit, stop agent.

:return: None
"""
self.stop_loop()
return None # pylint: disable=useless-return
return None

def start_loop(self) -> None:
"""
Expand Down
157 changes: 157 additions & 0 deletions docs/simple-oef-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
You can use the <a href="../simple-oef">SOEF</a> in the agent framework by using the SOEF connection as a package in your agent project.

## Add the SOEF package
Check out the <a href="../cli-commands">CLI guide</a> on details how to add a connection. You will want to add the `fetchai/soef:0.3.0` connection package.

## Register your agent and its services

### Register agent location
To register your agent's location, you have to send a message in the `fetchai/oef_search:0.3.0` protocol to the SOEF connection.

First, define a data model for location data:
``` python
from aea.helpers.search.models import Attribute, DataModel, Location

AGENT_LOCATION_MODEL = DataModel(
"location_agent",
[Attribute("location", Location, True, "The location where the agent is.")],
"A data model to describe location of an agent.",
)
```
It is important to use this exact data model, as the SOEF connection can only process specific data models.

Second, create a location object:
``` python
from aea.helpers.search.models import Location

agent_location = Location(52.2057092, 2.1183431)
```

Third, construct a service description instance with location and data model:
``` python
from aea.helpers.search.models import Description

service_instance = {"location": agent_location}
service_description = Description(
service_instance, data_model=AGENT_LOCATION_MODEL
)
```

Finally, construct a message and send it:
``` python
from packages.fetchai.protocols.oef_search.message import OefSearchMessage

message = OefSearchMessage(
performative=OefSearchMessage.Performative.REGISTER_SERVICE,
service_description=service_description,
)
```

In case everything is registered ok, you will not receive any message back.

If something goes wrong you will receive an error message with performative `OefSearchMessage.Performative.OEF_ERROR`.

### Register personality pieces

To register personality pieces, you have to use a specfic data model:
``` python
from aea.helpers.search.models import Attribute, DataModel, Location

AGENT_PERSONALITY_MODEL = DataModel(
"personality_agent",
[
Attribute("piece", str, True, "The personality piece key."),
Attribute("value", str, True, "The personality piece value."),
],
"A data model to describe the personality of an agent.",
)
```

An example follows:
``` python
service_instance = {"piece": "genus", "value": "service"}
service_description = Description(
service_instance, data_model=AGENT_PERSONALITY_MODEL
)
```

### Register services

To set some service key and value you have to use a specific data model:
``` python
SET_SERVICE_KEY_MODEL = DataModel(
"set_service_key",
[
Attribute("key", str, True, "Service key name."),
Attribute("value", str, True, "Service key value."),
],
"A data model to set service key.",
)
```

An example follows:
``` python
service_instance = {"key": "test", "value": "test"}
service_description = Description(
service_instance, data_model=SET_SERVICE_KEY_MODEL
)
```

### Remove service key

To remove service key have to use a specific data model:
``` python
REMOVE_SERVICE_KEY_MODEL = DataModel(
"remove_service_key",
[Attribute("key", str, True, "Service key name.")],
"A data model to remove service key.",
)
```

An example follows:
``` python
service_instance = {"key": "test"}
service_description = Description(
service_instance, data_model=REMOVE_SERVICE_KEY_MODEL
)
```

## Perform a search

To perform a search for services registered you have to define a search query consisting of constraints. The location constraints is required, personality pieces or services keys constraints are optional.

An example follows:
``` python
from aea.helpers.search.models import (
Constraint,
ConstraintType,
Location,
Query,
)

radius = 0.1
close_to_my_service = Constraint(
"location", ConstraintType("distance", (agent_location, radius))
)
personality_filters = [
Constraint("genus", ConstraintType("==", "vehicle")),
Constraint(
"classification", ConstraintType("==", "mobility.railway.train")
),
]

service_key_filters = [
Constraint("test", ConstraintType("==", "test")),
]

closeness_query = Query(
[close_to_my_service] + personality_filters + service_key_filters
)

message = OefSearchMessage(
performative=OefSearchMessage.Performative.SEARCH_SERVICES,
query=closeness_query,
)
```

In case of error you will received a message with `OefSearchMessage.Performative.OEF_ERROR`. In case of successful search you will receive a message with performative `OefSearchMessage.Performative.SEARCH_RESULT` and the list of matched agents addresses.
3 changes: 2 additions & 1 deletion docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ This page provides some tipps of how to upgrade between versions.

A number of breaking changes where introduced which make backwards compatibility of skills rare.

- Ledger apis <a href="../api/crypto/ledger_apis#ledger-apis-objects">`LedgerApis`</a> have been removed from the AEA constructor and skill context. `LedgerApis` are now exposed in the `LedgerConnection`. To communicate with the `LedgerApis` use the `fetchai/ledger_api` protocol.
- Ledger apis <a href="../api/crypto/ledger_apis#ledger-apis-objects">`LedgerApis`</a> have been removed from the AEA constructor and skill context. `LedgerApis` are now exposed in the `LedgerConnection` (`fetchai/ledger`). To communicate with the `LedgerApis` use the `fetchai/ledger_api` protocol. This allows for more flexibility (anyone can add another `LedgerAPI` to the registry and execute it with the connection) and removes dependencies from the core framework.
- Skills can now depend on other skills. As a result, skills have a new required config field, by default empty: `skills: []`.

## v0.4.0 to v0.4.1

Expand Down
16 changes: 14 additions & 2 deletions examples/protocol_specification_ex/contract_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ speech_acts:
contract_address: pt:str
callable: pt:str
kwargs: ct:Kwargs
get_raw_message:
ledger_id: pt:str
contract_id: pt:str
contract_address: pt:str
callable: pt:str
kwargs: ct:Kwargs
get_state:
ledger_id: pt:str
contract_id: pt:str
Expand All @@ -27,6 +33,8 @@ speech_acts:
state: ct:State
raw_transaction:
raw_transaction: ct:RawTransaction
raw_message:
raw_message: ct:RawMessage
error:
code: pt:optional[pt:int]
message: pt:optional[pt:str]
Expand All @@ -39,17 +47,21 @@ ct:State:
bytes state = 1;
ct:RawTransaction:
bytes raw_transaction = 1;
ct:RawMessage:
bytes raw_message = 1;
...
---
initiation: [get_deploy_transaction, get_raw_transaction, get_state]
initiation: [get_deploy_transaction, get_raw_transaction, get_raw_message, get_state]
reply:
get_deploy_transaction: [raw_transaction, error]
get_raw_transaction: [raw_transaction, error]
get_raw_message: [raw_message, error]
get_state: [state, error]
raw_transaction: []
raw_message: []
state: []
error: []
termination: [state, raw_transaction]
termination: [state, raw_transaction, raw_message]
roles: {agent, ledger}
end_states: [successful, failed]
...
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ nav:
- Search & Discovery:
- Defining Data Models: 'defining-data-models.md'
- The Query Language: 'query-language.md'
- SOEF Connection: 'simple-oef-usage.md'
- Developer Interfaces:
- CLI:
- Installation: 'cli-how-to.md'
Expand Down
2 changes: 1 addition & 1 deletion packages/fetchai/connections/ledger/connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fingerprint:
__init__.py: QmZvYZ5ECcWwqiNGh8qNTg735wu51HqaLxTSifUxkQ4KGj
base.py: QmZecsNSNpct1Zrs7HsJPQJN2buKJCirz6Z7nYH2FQbJFH
connection.py: QmRTut9Fo11GbXzhm5kdr9GbkEseTqSBEaxWVScps2pMYm
contract_dispatcher.py: QmSkvdYrG6SrneTkXaQfFeYGgZfSLHuozHpcrcV68x6tiH
contract_dispatcher.py: QmPtV5PxCP3YCtyA4EeGijqgpNwqPp3xvNZvtvk1nkhRJk
ledger_dispatcher.py: QmUk2J1FokJR6iLQYfyZbSSvR5y5g3ozYq7H6yQcv7YqmJ
fingerprint_ignore_patterns: []
protocols:
Expand Down
Loading