mech-client 0.14.1__py3-none-any.whl → 0.15.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mech_client/__init__.py +1 -1
- mech_client/cli.py +258 -11
- mech_client/configs/mechs.json +110 -110
- mech_client/interact.py +6 -1
- mech_client/marketplace_interact.py +160 -42
- mech_client/safe.py +73 -0
- mech_client/subgraph.py +0 -11
- {mech_client-0.14.1.dist-info → mech_client-0.15.1.dist-info}/METADATA +278 -224
- {mech_client-0.14.1.dist-info → mech_client-0.15.1.dist-info}/RECORD +22 -48
- scripts/deposit_native.py +48 -16
- scripts/deposit_token.py +107 -31
- scripts/nvm_subscribe.py +14 -6
- scripts/nvm_subscription/contracts/base_contract.py +9 -1
- scripts/nvm_subscription/contracts/nft_sales.py +1 -3
- scripts/nvm_subscription/contracts/subscription_provider.py +2 -4
- scripts/nvm_subscription/contracts/token.py +23 -5
- scripts/nvm_subscription/manager.py +109 -16
- scripts/utils.py +2 -2
- scripts/whitelist.py +5 -1
- mech_client/helpers/acn/README.md +0 -76
- mech_client/helpers/acn/__init__.py +0 -30
- mech_client/helpers/acn/acn.proto +0 -71
- mech_client/helpers/acn/acn_pb2.py +0 -42
- mech_client/helpers/acn/custom_types.py +0 -224
- mech_client/helpers/acn/dialogues.py +0 -126
- mech_client/helpers/acn/message.py +0 -274
- mech_client/helpers/acn/protocol.yaml +0 -24
- mech_client/helpers/acn/serialization.py +0 -149
- mech_client/helpers/acn/tests/__init__.py +0 -20
- mech_client/helpers/acn/tests/test_acn.py +0 -256
- mech_client/helpers/acn/tests/test_acn_dialogues.py +0 -53
- mech_client/helpers/acn/tests/test_acn_messages.py +0 -117
- mech_client/helpers/acn_data_share/README.md +0 -32
- mech_client/helpers/acn_data_share/__init__.py +0 -32
- mech_client/helpers/acn_data_share/acn_data_share.proto +0 -17
- mech_client/helpers/acn_data_share/acn_data_share_pb2.py +0 -29
- mech_client/helpers/acn_data_share/dialogues.py +0 -115
- mech_client/helpers/acn_data_share/message.py +0 -213
- mech_client/helpers/acn_data_share/protocol.yaml +0 -21
- mech_client/helpers/acn_data_share/serialization.py +0 -111
- mech_client/helpers/acn_data_share/tests/test_acn_data_share_dialogues.py +0 -49
- mech_client/helpers/acn_data_share/tests/test_acn_data_share_messages.py +0 -53
- mech_client/helpers/p2p_libp2p_client/README.md +0 -15
- mech_client/helpers/p2p_libp2p_client/__init__.py +0 -21
- mech_client/helpers/p2p_libp2p_client/connection.py +0 -703
- mech_client/helpers/p2p_libp2p_client/connection.yaml +0 -52
- {mech_client-0.14.1.dist-info → mech_client-0.15.1.dist-info}/LICENSE +0 -0
- {mech_client-0.14.1.dist-info → mech_client-0.15.1.dist-info}/WHEEL +0 -0
- {mech_client-0.14.1.dist-info → mech_client-0.15.1.dist-info}/entry_points.txt +0 -0
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# ------------------------------------------------------------------------------
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2022 Valory AG
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
#
|
|
18
|
-
# ------------------------------------------------------------------------------
|
|
19
|
-
|
|
20
|
-
"""This module contains class representations corresponding to every custom type in the protocol specification."""
|
|
21
|
-
# pylint: disable-all
|
|
22
|
-
from enum import Enum
|
|
23
|
-
from typing import Any, List
|
|
24
|
-
|
|
25
|
-
from aea.helpers.base import SimpleId, SimpleIdOrStr
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class AgentRecord:
|
|
29
|
-
"""
|
|
30
|
-
This class represents an instance of AgentRecord.
|
|
31
|
-
|
|
32
|
-
Eventually needs to be unified with `aea.helpers.acn.agent_record`.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
__slots__ = (
|
|
36
|
-
"_address",
|
|
37
|
-
"_public_key",
|
|
38
|
-
"_peer_public_key",
|
|
39
|
-
"_signature",
|
|
40
|
-
"_service_id",
|
|
41
|
-
"_ledger_id",
|
|
42
|
-
"_message_format",
|
|
43
|
-
"_message",
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
def __init__(
|
|
47
|
-
self,
|
|
48
|
-
address: str,
|
|
49
|
-
public_key: str,
|
|
50
|
-
peer_public_key: str,
|
|
51
|
-
signature: str,
|
|
52
|
-
service_id: SimpleIdOrStr,
|
|
53
|
-
ledger_id: SimpleIdOrStr,
|
|
54
|
-
) -> None:
|
|
55
|
-
"""Initialise an instance of AgentRecord."""
|
|
56
|
-
self._address = address
|
|
57
|
-
self._public_key = public_key
|
|
58
|
-
self._peer_public_key = peer_public_key
|
|
59
|
-
self._signature = signature
|
|
60
|
-
self._service_id = str(SimpleId(service_id))
|
|
61
|
-
self._ledger_id = str(SimpleId(ledger_id))
|
|
62
|
-
|
|
63
|
-
@property
|
|
64
|
-
def address(self) -> str:
|
|
65
|
-
"""Get agent address"""
|
|
66
|
-
return self._address
|
|
67
|
-
|
|
68
|
-
@property
|
|
69
|
-
def public_key(self) -> str:
|
|
70
|
-
"""Get agent public key"""
|
|
71
|
-
return self._public_key
|
|
72
|
-
|
|
73
|
-
@property
|
|
74
|
-
def peer_public_key(self) -> str:
|
|
75
|
-
"""Get agent representative's public key"""
|
|
76
|
-
return self._peer_public_key
|
|
77
|
-
|
|
78
|
-
@property
|
|
79
|
-
def signature(self) -> str:
|
|
80
|
-
"""Get record signature"""
|
|
81
|
-
return self._signature
|
|
82
|
-
|
|
83
|
-
@property
|
|
84
|
-
def service_id(self) -> SimpleIdOrStr:
|
|
85
|
-
"""Get the identifier."""
|
|
86
|
-
return self._service_id
|
|
87
|
-
|
|
88
|
-
@property
|
|
89
|
-
def ledger_id(self) -> SimpleIdOrStr:
|
|
90
|
-
"""Get ledger id."""
|
|
91
|
-
return self._ledger_id
|
|
92
|
-
|
|
93
|
-
@staticmethod
|
|
94
|
-
def encode(
|
|
95
|
-
agent_record_protobuf_object: Any, agent_record_object: "AgentRecord"
|
|
96
|
-
) -> None:
|
|
97
|
-
"""
|
|
98
|
-
Encode an instance of this class into the protocol buffer object.
|
|
99
|
-
|
|
100
|
-
The protocol buffer object in the agent_record_protobuf_object argument is matched with the instance of this class in the 'agent_record_object' argument.
|
|
101
|
-
|
|
102
|
-
:param agent_record_protobuf_object: the protocol buffer object whose type corresponds with this class.
|
|
103
|
-
:param agent_record_object: an instance of this class to be encoded in the protocol buffer object.
|
|
104
|
-
"""
|
|
105
|
-
agent_record_protobuf_object.address = agent_record_object.address
|
|
106
|
-
agent_record_protobuf_object.public_key = agent_record_object.public_key
|
|
107
|
-
agent_record_protobuf_object.peer_public_key = (
|
|
108
|
-
agent_record_object.peer_public_key
|
|
109
|
-
)
|
|
110
|
-
agent_record_protobuf_object.signature = agent_record_object.signature
|
|
111
|
-
agent_record_protobuf_object.service_id = agent_record_object.service_id
|
|
112
|
-
agent_record_protobuf_object.ledger_id = agent_record_object.ledger_id
|
|
113
|
-
|
|
114
|
-
@classmethod
|
|
115
|
-
def decode(cls, agent_record_protobuf_object: Any) -> "AgentRecord":
|
|
116
|
-
"""
|
|
117
|
-
Decode a protocol buffer object that corresponds with this class into an instance of this class.
|
|
118
|
-
|
|
119
|
-
A new instance of this class is created that matches the protocol buffer object in the 'agent_record_protobuf_object' argument.
|
|
120
|
-
|
|
121
|
-
:param agent_record_protobuf_object: the protocol buffer object whose type corresponds with this class.
|
|
122
|
-
:return: A new instance of this class that matches the protocol buffer object in the 'agent_record_protobuf_object' argument.
|
|
123
|
-
"""
|
|
124
|
-
record = cls(
|
|
125
|
-
address=agent_record_protobuf_object.address,
|
|
126
|
-
public_key=agent_record_protobuf_object.public_key,
|
|
127
|
-
peer_public_key=agent_record_protobuf_object.peer_public_key,
|
|
128
|
-
signature=agent_record_protobuf_object.signature,
|
|
129
|
-
service_id=agent_record_protobuf_object.service_id,
|
|
130
|
-
ledger_id=agent_record_protobuf_object.ledger_id,
|
|
131
|
-
)
|
|
132
|
-
return record
|
|
133
|
-
|
|
134
|
-
def __eq__(self, other: Any) -> bool:
|
|
135
|
-
"""Compare to objects of this class."""
|
|
136
|
-
return (
|
|
137
|
-
isinstance(other, AgentRecord)
|
|
138
|
-
and self.address == other.address
|
|
139
|
-
and self.public_key == other.public_key
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
class StatusBody:
|
|
144
|
-
"""This class represents an instance of StatusBody."""
|
|
145
|
-
|
|
146
|
-
__slots__ = (
|
|
147
|
-
"_status_code",
|
|
148
|
-
"_msgs",
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
class StatusCode(Enum):
|
|
152
|
-
"""Status code enum."""
|
|
153
|
-
|
|
154
|
-
SUCCESS = 0
|
|
155
|
-
ERROR_UNSUPPORTED_VERSION = 1
|
|
156
|
-
ERROR_UNEXPECTED_PAYLOAD = 2
|
|
157
|
-
ERROR_GENERIC = 3
|
|
158
|
-
ERROR_DECODE = 4
|
|
159
|
-
|
|
160
|
-
ERROR_WRONG_AGENT_ADDRESS = 10
|
|
161
|
-
ERROR_WRONG_PUBLIC_KEY = 11
|
|
162
|
-
ERROR_INVALID_PROOF = 12
|
|
163
|
-
ERROR_UNSUPPORTED_LEDGER = 13
|
|
164
|
-
|
|
165
|
-
ERROR_UNKNOWN_AGENT_ADDRESS = 20
|
|
166
|
-
ERROR_AGENT_NOT_READY = 21
|
|
167
|
-
|
|
168
|
-
def __int__(self) -> int:
|
|
169
|
-
"""Get string representation."""
|
|
170
|
-
return self.value
|
|
171
|
-
|
|
172
|
-
def __init__(self, status_code: StatusCode, msgs: List[str]) -> None:
|
|
173
|
-
"""Initialise an instance of StatusBody."""
|
|
174
|
-
self._status_code = status_code
|
|
175
|
-
self._msgs = msgs
|
|
176
|
-
|
|
177
|
-
@property
|
|
178
|
-
def status_code(self) -> "StatusCode":
|
|
179
|
-
"""Get the status code."""
|
|
180
|
-
return self._status_code
|
|
181
|
-
|
|
182
|
-
@property
|
|
183
|
-
def msgs(self) -> List[str]:
|
|
184
|
-
"""Get the list of messages."""
|
|
185
|
-
return self._msgs
|
|
186
|
-
|
|
187
|
-
@staticmethod
|
|
188
|
-
def encode(
|
|
189
|
-
status_body_protobuf_object: Any, status_body_object: "StatusBody"
|
|
190
|
-
) -> None:
|
|
191
|
-
"""
|
|
192
|
-
Encode an instance of this class into the protocol buffer object.
|
|
193
|
-
|
|
194
|
-
The protocol buffer object in the status_body_protobuf_object argument is matched with the instance of this class in the 'status_body_object' argument.
|
|
195
|
-
|
|
196
|
-
:param status_body_protobuf_object: the protocol buffer object whose type corresponds with this class.
|
|
197
|
-
:param status_body_object: an instance of this class to be encoded in the protocol buffer object.
|
|
198
|
-
"""
|
|
199
|
-
status_body_protobuf_object.code = int(status_body_object.status_code)
|
|
200
|
-
status_body_protobuf_object.msgs.extend(status_body_object.msgs)
|
|
201
|
-
|
|
202
|
-
@classmethod
|
|
203
|
-
def decode(cls, status_body_protobuf_object: Any) -> "StatusBody":
|
|
204
|
-
"""
|
|
205
|
-
Decode a protocol buffer object that corresponds with this class into an instance of this class.
|
|
206
|
-
|
|
207
|
-
A new instance of this class is created that matches the protocol buffer object in the 'status_body_protobuf_object' argument.
|
|
208
|
-
|
|
209
|
-
:param status_body_protobuf_object: the protocol buffer object whose type corresponds with this class.
|
|
210
|
-
:return: A new instance of this class that matches the protocol buffer object in the 'status_body_protobuf_object' argument.
|
|
211
|
-
"""
|
|
212
|
-
status_body = cls(
|
|
213
|
-
status_code=cls.StatusCode(status_body_protobuf_object.code),
|
|
214
|
-
msgs=status_body_protobuf_object.msgs,
|
|
215
|
-
)
|
|
216
|
-
return status_body
|
|
217
|
-
|
|
218
|
-
def __eq__(self, other: Any) -> bool:
|
|
219
|
-
"""Compare to objects of this class."""
|
|
220
|
-
return (
|
|
221
|
-
isinstance(other, StatusBody)
|
|
222
|
-
and self.status_code == other.status_code
|
|
223
|
-
and self.msgs == other.msgs
|
|
224
|
-
)
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# ------------------------------------------------------------------------------
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2024 valory
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
#
|
|
18
|
-
# ------------------------------------------------------------------------------
|
|
19
|
-
|
|
20
|
-
"""
|
|
21
|
-
This module contains the classes required for acn dialogue management.
|
|
22
|
-
|
|
23
|
-
- AcnDialogue: The dialogue class maintains state of a dialogue and manages it.
|
|
24
|
-
- AcnDialogues: The dialogues class keeps track of all dialogues.
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
from abc import ABC
|
|
28
|
-
from typing import Callable, Dict, FrozenSet, Type, cast
|
|
29
|
-
|
|
30
|
-
from aea.common import Address
|
|
31
|
-
from aea.protocols.base import Message
|
|
32
|
-
from aea.protocols.dialogue.base import Dialogue, DialogueLabel, Dialogues
|
|
33
|
-
|
|
34
|
-
from packages.valory.protocols.acn.message import AcnMessage
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class AcnDialogue(Dialogue):
|
|
38
|
-
"""The acn dialogue class maintains state of a dialogue and manages it."""
|
|
39
|
-
|
|
40
|
-
INITIAL_PERFORMATIVES: FrozenSet[Message.Performative] = frozenset(
|
|
41
|
-
{
|
|
42
|
-
AcnMessage.Performative.REGISTER,
|
|
43
|
-
AcnMessage.Performative.LOOKUP_REQUEST,
|
|
44
|
-
AcnMessage.Performative.AEA_ENVELOPE,
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
TERMINAL_PERFORMATIVES: FrozenSet[Message.Performative] = frozenset(
|
|
48
|
-
{AcnMessage.Performative.STATUS, AcnMessage.Performative.LOOKUP_RESPONSE}
|
|
49
|
-
)
|
|
50
|
-
VALID_REPLIES: Dict[Message.Performative, FrozenSet[Message.Performative]] = {
|
|
51
|
-
AcnMessage.Performative.AEA_ENVELOPE: frozenset(
|
|
52
|
-
{AcnMessage.Performative.STATUS}
|
|
53
|
-
),
|
|
54
|
-
AcnMessage.Performative.LOOKUP_REQUEST: frozenset(
|
|
55
|
-
{AcnMessage.Performative.LOOKUP_RESPONSE, AcnMessage.Performative.STATUS}
|
|
56
|
-
),
|
|
57
|
-
AcnMessage.Performative.LOOKUP_RESPONSE: frozenset(),
|
|
58
|
-
AcnMessage.Performative.REGISTER: frozenset({AcnMessage.Performative.STATUS}),
|
|
59
|
-
AcnMessage.Performative.STATUS: frozenset(),
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
class Role(Dialogue.Role):
|
|
63
|
-
"""This class defines the agent's role in a acn dialogue."""
|
|
64
|
-
|
|
65
|
-
NODE = "node"
|
|
66
|
-
|
|
67
|
-
class EndState(Dialogue.EndState):
|
|
68
|
-
"""This class defines the end states of a acn dialogue."""
|
|
69
|
-
|
|
70
|
-
SUCCESSFUL = 0
|
|
71
|
-
FAILED = 1
|
|
72
|
-
|
|
73
|
-
def __init__(
|
|
74
|
-
self,
|
|
75
|
-
dialogue_label: DialogueLabel,
|
|
76
|
-
self_address: Address,
|
|
77
|
-
role: Dialogue.Role,
|
|
78
|
-
message_class: Type[AcnMessage] = AcnMessage,
|
|
79
|
-
) -> None:
|
|
80
|
-
"""
|
|
81
|
-
Initialize a dialogue.
|
|
82
|
-
|
|
83
|
-
:param dialogue_label: the identifier of the dialogue
|
|
84
|
-
:param self_address: the address of the entity for whom this dialogue is maintained
|
|
85
|
-
:param role: the role of the agent this dialogue is maintained for
|
|
86
|
-
:param message_class: the message class used
|
|
87
|
-
"""
|
|
88
|
-
Dialogue.__init__(
|
|
89
|
-
self,
|
|
90
|
-
dialogue_label=dialogue_label,
|
|
91
|
-
message_class=message_class,
|
|
92
|
-
self_address=self_address,
|
|
93
|
-
role=role,
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
class AcnDialogues(Dialogues, ABC):
|
|
98
|
-
"""This class keeps track of all acn dialogues."""
|
|
99
|
-
|
|
100
|
-
END_STATES = frozenset(
|
|
101
|
-
{AcnDialogue.EndState.SUCCESSFUL, AcnDialogue.EndState.FAILED}
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
_keep_terminal_state_dialogues = False
|
|
105
|
-
|
|
106
|
-
def __init__(
|
|
107
|
-
self,
|
|
108
|
-
self_address: Address,
|
|
109
|
-
role_from_first_message: Callable[[Message, Address], Dialogue.Role],
|
|
110
|
-
dialogue_class: Type[AcnDialogue] = AcnDialogue,
|
|
111
|
-
) -> None:
|
|
112
|
-
"""
|
|
113
|
-
Initialize dialogues.
|
|
114
|
-
|
|
115
|
-
:param self_address: the address of the entity for whom dialogues are maintained
|
|
116
|
-
:param dialogue_class: the dialogue class used
|
|
117
|
-
:param role_from_first_message: the callable determining role from first message
|
|
118
|
-
"""
|
|
119
|
-
Dialogues.__init__(
|
|
120
|
-
self,
|
|
121
|
-
self_address=self_address,
|
|
122
|
-
end_states=cast(FrozenSet[Dialogue.EndState], self.END_STATES),
|
|
123
|
-
message_class=AcnMessage,
|
|
124
|
-
dialogue_class=dialogue_class,
|
|
125
|
-
role_from_first_message=role_from_first_message,
|
|
126
|
-
)
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# ------------------------------------------------------------------------------
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2024 valory
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
#
|
|
18
|
-
# ------------------------------------------------------------------------------
|
|
19
|
-
|
|
20
|
-
"""This module contains acn's message definition."""
|
|
21
|
-
|
|
22
|
-
# pylint: disable=too-many-statements,too-many-locals,no-member,too-few-public-methods,too-many-branches,not-an-iterable,unidiomatic-typecheck,unsubscriptable-object
|
|
23
|
-
import logging
|
|
24
|
-
from typing import Any, Set, Tuple, cast
|
|
25
|
-
|
|
26
|
-
from aea.configurations.base import PublicId
|
|
27
|
-
from aea.exceptions import AEAEnforceError, enforce
|
|
28
|
-
from aea.protocols.base import Message # type: ignore
|
|
29
|
-
|
|
30
|
-
from packages.valory.protocols.acn.custom_types import AgentRecord as CustomAgentRecord
|
|
31
|
-
from packages.valory.protocols.acn.custom_types import StatusBody as CustomStatusBody
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
_default_logger = logging.getLogger("aea.packages.valory.protocols.acn.message")
|
|
35
|
-
|
|
36
|
-
DEFAULT_BODY_SIZE = 4
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class AcnMessage(Message):
|
|
40
|
-
"""The protocol used for envelope delivery on the ACN."""
|
|
41
|
-
|
|
42
|
-
protocol_id = PublicId.from_str("valory/acn:1.1.0")
|
|
43
|
-
protocol_specification_id = PublicId.from_str("aea/acn:1.0.0")
|
|
44
|
-
|
|
45
|
-
AgentRecord = CustomAgentRecord
|
|
46
|
-
|
|
47
|
-
StatusBody = CustomStatusBody
|
|
48
|
-
|
|
49
|
-
class Performative(Message.Performative):
|
|
50
|
-
"""Performatives for the acn protocol."""
|
|
51
|
-
|
|
52
|
-
AEA_ENVELOPE = "aea_envelope"
|
|
53
|
-
LOOKUP_REQUEST = "lookup_request"
|
|
54
|
-
LOOKUP_RESPONSE = "lookup_response"
|
|
55
|
-
REGISTER = "register"
|
|
56
|
-
STATUS = "status"
|
|
57
|
-
|
|
58
|
-
def __str__(self) -> str:
|
|
59
|
-
"""Get the string representation."""
|
|
60
|
-
return str(self.value)
|
|
61
|
-
|
|
62
|
-
_performatives = {
|
|
63
|
-
"aea_envelope",
|
|
64
|
-
"lookup_request",
|
|
65
|
-
"lookup_response",
|
|
66
|
-
"register",
|
|
67
|
-
"status",
|
|
68
|
-
}
|
|
69
|
-
__slots__: Tuple[str, ...] = tuple()
|
|
70
|
-
|
|
71
|
-
class _SlotsCls:
|
|
72
|
-
__slots__ = (
|
|
73
|
-
"agent_address",
|
|
74
|
-
"body",
|
|
75
|
-
"dialogue_reference",
|
|
76
|
-
"envelope",
|
|
77
|
-
"message_id",
|
|
78
|
-
"performative",
|
|
79
|
-
"record",
|
|
80
|
-
"target",
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
def __init__(
|
|
84
|
-
self,
|
|
85
|
-
performative: Performative,
|
|
86
|
-
dialogue_reference: Tuple[str, str] = ("", ""),
|
|
87
|
-
message_id: int = 1,
|
|
88
|
-
target: int = 0,
|
|
89
|
-
**kwargs: Any,
|
|
90
|
-
):
|
|
91
|
-
"""
|
|
92
|
-
Initialise an instance of AcnMessage.
|
|
93
|
-
|
|
94
|
-
:param message_id: the message id.
|
|
95
|
-
:param dialogue_reference: the dialogue reference.
|
|
96
|
-
:param target: the message target.
|
|
97
|
-
:param performative: the message performative.
|
|
98
|
-
:param **kwargs: extra options.
|
|
99
|
-
"""
|
|
100
|
-
super().__init__(
|
|
101
|
-
dialogue_reference=dialogue_reference,
|
|
102
|
-
message_id=message_id,
|
|
103
|
-
target=target,
|
|
104
|
-
performative=AcnMessage.Performative(performative),
|
|
105
|
-
**kwargs,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def valid_performatives(self) -> Set[str]:
|
|
110
|
-
"""Get valid performatives."""
|
|
111
|
-
return self._performatives
|
|
112
|
-
|
|
113
|
-
@property
|
|
114
|
-
def dialogue_reference(self) -> Tuple[str, str]:
|
|
115
|
-
"""Get the dialogue_reference of the message."""
|
|
116
|
-
enforce(self.is_set("dialogue_reference"), "dialogue_reference is not set.")
|
|
117
|
-
return cast(Tuple[str, str], self.get("dialogue_reference"))
|
|
118
|
-
|
|
119
|
-
@property
|
|
120
|
-
def message_id(self) -> int:
|
|
121
|
-
"""Get the message_id of the message."""
|
|
122
|
-
enforce(self.is_set("message_id"), "message_id is not set.")
|
|
123
|
-
return cast(int, self.get("message_id"))
|
|
124
|
-
|
|
125
|
-
@property
|
|
126
|
-
def performative(self) -> Performative: # type: ignore # noqa: F821
|
|
127
|
-
"""Get the performative of the message."""
|
|
128
|
-
enforce(self.is_set("performative"), "performative is not set.")
|
|
129
|
-
return cast(AcnMessage.Performative, self.get("performative"))
|
|
130
|
-
|
|
131
|
-
@property
|
|
132
|
-
def target(self) -> int:
|
|
133
|
-
"""Get the target of the message."""
|
|
134
|
-
enforce(self.is_set("target"), "target is not set.")
|
|
135
|
-
return cast(int, self.get("target"))
|
|
136
|
-
|
|
137
|
-
@property
|
|
138
|
-
def agent_address(self) -> str:
|
|
139
|
-
"""Get the 'agent_address' content from the message."""
|
|
140
|
-
enforce(self.is_set("agent_address"), "'agent_address' content is not set.")
|
|
141
|
-
return cast(str, self.get("agent_address"))
|
|
142
|
-
|
|
143
|
-
@property
|
|
144
|
-
def body(self) -> CustomStatusBody:
|
|
145
|
-
"""Get the 'body' content from the message."""
|
|
146
|
-
enforce(self.is_set("body"), "'body' content is not set.")
|
|
147
|
-
return cast(CustomStatusBody, self.get("body"))
|
|
148
|
-
|
|
149
|
-
@property
|
|
150
|
-
def envelope(self) -> bytes:
|
|
151
|
-
"""Get the 'envelope' content from the message."""
|
|
152
|
-
enforce(self.is_set("envelope"), "'envelope' content is not set.")
|
|
153
|
-
return cast(bytes, self.get("envelope"))
|
|
154
|
-
|
|
155
|
-
@property
|
|
156
|
-
def record(self) -> CustomAgentRecord:
|
|
157
|
-
"""Get the 'record' content from the message."""
|
|
158
|
-
enforce(self.is_set("record"), "'record' content is not set.")
|
|
159
|
-
return cast(CustomAgentRecord, self.get("record"))
|
|
160
|
-
|
|
161
|
-
def _is_consistent(self) -> bool:
|
|
162
|
-
"""Check that the message follows the acn protocol."""
|
|
163
|
-
try:
|
|
164
|
-
enforce(
|
|
165
|
-
isinstance(self.dialogue_reference, tuple),
|
|
166
|
-
"Invalid type for 'dialogue_reference'. Expected 'tuple'. Found '{}'.".format(
|
|
167
|
-
type(self.dialogue_reference)
|
|
168
|
-
),
|
|
169
|
-
)
|
|
170
|
-
enforce(
|
|
171
|
-
isinstance(self.dialogue_reference[0], str),
|
|
172
|
-
"Invalid type for 'dialogue_reference[0]'. Expected 'str'. Found '{}'.".format(
|
|
173
|
-
type(self.dialogue_reference[0])
|
|
174
|
-
),
|
|
175
|
-
)
|
|
176
|
-
enforce(
|
|
177
|
-
isinstance(self.dialogue_reference[1], str),
|
|
178
|
-
"Invalid type for 'dialogue_reference[1]'. Expected 'str'. Found '{}'.".format(
|
|
179
|
-
type(self.dialogue_reference[1])
|
|
180
|
-
),
|
|
181
|
-
)
|
|
182
|
-
enforce(
|
|
183
|
-
type(self.message_id) is int,
|
|
184
|
-
"Invalid type for 'message_id'. Expected 'int'. Found '{}'.".format(
|
|
185
|
-
type(self.message_id)
|
|
186
|
-
),
|
|
187
|
-
)
|
|
188
|
-
enforce(
|
|
189
|
-
type(self.target) is int,
|
|
190
|
-
"Invalid type for 'target'. Expected 'int'. Found '{}'.".format(
|
|
191
|
-
type(self.target)
|
|
192
|
-
),
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
# Light Protocol Rule 2
|
|
196
|
-
# Check correct performative
|
|
197
|
-
enforce(
|
|
198
|
-
isinstance(self.performative, AcnMessage.Performative),
|
|
199
|
-
"Invalid 'performative'. Expected either of '{}'. Found '{}'.".format(
|
|
200
|
-
self.valid_performatives, self.performative
|
|
201
|
-
),
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
# Check correct contents
|
|
205
|
-
actual_nb_of_contents = len(self._body) - DEFAULT_BODY_SIZE
|
|
206
|
-
expected_nb_of_contents = 0
|
|
207
|
-
if self.performative == AcnMessage.Performative.REGISTER:
|
|
208
|
-
expected_nb_of_contents = 1
|
|
209
|
-
enforce(
|
|
210
|
-
isinstance(self.record, CustomAgentRecord),
|
|
211
|
-
"Invalid type for content 'record'. Expected 'AgentRecord'. Found '{}'.".format(
|
|
212
|
-
type(self.record)
|
|
213
|
-
),
|
|
214
|
-
)
|
|
215
|
-
elif self.performative == AcnMessage.Performative.LOOKUP_REQUEST:
|
|
216
|
-
expected_nb_of_contents = 1
|
|
217
|
-
enforce(
|
|
218
|
-
isinstance(self.agent_address, str),
|
|
219
|
-
"Invalid type for content 'agent_address'. Expected 'str'. Found '{}'.".format(
|
|
220
|
-
type(self.agent_address)
|
|
221
|
-
),
|
|
222
|
-
)
|
|
223
|
-
elif self.performative == AcnMessage.Performative.LOOKUP_RESPONSE:
|
|
224
|
-
expected_nb_of_contents = 1
|
|
225
|
-
enforce(
|
|
226
|
-
isinstance(self.record, CustomAgentRecord),
|
|
227
|
-
"Invalid type for content 'record'. Expected 'AgentRecord'. Found '{}'.".format(
|
|
228
|
-
type(self.record)
|
|
229
|
-
),
|
|
230
|
-
)
|
|
231
|
-
elif self.performative == AcnMessage.Performative.AEA_ENVELOPE:
|
|
232
|
-
expected_nb_of_contents = 2
|
|
233
|
-
enforce(
|
|
234
|
-
isinstance(self.envelope, bytes),
|
|
235
|
-
"Invalid type for content 'envelope'. Expected 'bytes'. Found '{}'.".format(
|
|
236
|
-
type(self.envelope)
|
|
237
|
-
),
|
|
238
|
-
)
|
|
239
|
-
enforce(
|
|
240
|
-
isinstance(self.record, CustomAgentRecord),
|
|
241
|
-
"Invalid type for content 'record'. Expected 'AgentRecord'. Found '{}'.".format(
|
|
242
|
-
type(self.record)
|
|
243
|
-
),
|
|
244
|
-
)
|
|
245
|
-
elif self.performative == AcnMessage.Performative.STATUS:
|
|
246
|
-
expected_nb_of_contents = 1
|
|
247
|
-
enforce(
|
|
248
|
-
isinstance(self.body, CustomStatusBody),
|
|
249
|
-
"Invalid type for content 'body'. Expected 'StatusBody'. Found '{}'.".format(
|
|
250
|
-
type(self.body)
|
|
251
|
-
),
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
# Check correct content count
|
|
255
|
-
enforce(
|
|
256
|
-
expected_nb_of_contents == actual_nb_of_contents,
|
|
257
|
-
"Incorrect number of contents. Expected {}. Found {}".format(
|
|
258
|
-
expected_nb_of_contents, actual_nb_of_contents
|
|
259
|
-
),
|
|
260
|
-
)
|
|
261
|
-
|
|
262
|
-
# Light Protocol Rule 3
|
|
263
|
-
if self.message_id == 1:
|
|
264
|
-
enforce(
|
|
265
|
-
self.target == 0,
|
|
266
|
-
"Invalid 'target'. Expected 0 (because 'message_id' is 1). Found {}.".format(
|
|
267
|
-
self.target
|
|
268
|
-
),
|
|
269
|
-
)
|
|
270
|
-
except (AEAEnforceError, ValueError, KeyError) as e:
|
|
271
|
-
_default_logger.error(str(e))
|
|
272
|
-
return False
|
|
273
|
-
|
|
274
|
-
return True
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
name: acn
|
|
2
|
-
author: valory
|
|
3
|
-
version: 1.1.0
|
|
4
|
-
protocol_specification_id: aea/acn:1.0.0
|
|
5
|
-
type: protocol
|
|
6
|
-
description: The protocol used for envelope delivery on the ACN.
|
|
7
|
-
license: Apache-2.0
|
|
8
|
-
aea_version: '>=1.0.0, <2.0.0'
|
|
9
|
-
fingerprint:
|
|
10
|
-
README.md: bafybeie7paijucvzemlfhwfmmhorypwuhzbeimgoitlkokdio5c3ne4pjq
|
|
11
|
-
__init__.py: bafybeicqlp4gkeeef5osp6zopjztlgat24nxrzq43cy7wbwxk5omf2sc2m
|
|
12
|
-
acn.proto: bafybeidkun7o75sxpyk2sixt7dsykgty62f6dnixnes2irbunyamilqsh4
|
|
13
|
-
acn_pb2.py: bafybeialafz3yomunwa3g5xgrdqwodzl7zg5dncvzuetv7xoew4zhw76ni
|
|
14
|
-
custom_types.py: bafybeigpueuq6mdeyjyayzv3menkmemutfgfiwlozlpl64t67cfnnom24q
|
|
15
|
-
dialogues.py: bafybeidjpyk7s3getyfegjdrgrt5blf2yutzqclohaktjehwcj3sqx2ole
|
|
16
|
-
message.py: bafybeiai7kond3rcbtwnr5xgpwzuauf5tusuep6ikopi4cqvp2wa5qfz3e
|
|
17
|
-
serialization.py: bafybeidu7fzixk6sm3iprhph4shbiq5qgvg56lg4yiryfaf3unuqk34bwi
|
|
18
|
-
tests/__init__.py: bafybeidteufp2npjd77ekcftk5e4gbaquq3gike5nxtk5xfmnusls56keu
|
|
19
|
-
tests/test_acn.py: bafybeignjgdtlfdnj25hc5necmg7zl3kvngsmzkjgcwfm5qg36liqa63ki
|
|
20
|
-
tests/test_acn_dialogues.py: bafybeia2kndutaokjpogo4wlb5pf4gkqacvcbngqromf4g4mzu6wyetz7q
|
|
21
|
-
tests/test_acn_messages.py: bafybeigriniqu3tfzeok7rjx3widzclyjqgjhkunkgt657lpng23mo7oxa
|
|
22
|
-
fingerprint_ignore_patterns: []
|
|
23
|
-
dependencies:
|
|
24
|
-
protobuf: {}
|