Skip to content

Commit

Permalink
Merge pull request #79 from Multi-Agent-io/development
Browse files Browse the repository at this point in the history
1.3.6 DT not hash encoded IPFS CIDs, subscriptions docstring update
  • Loading branch information
PaTara43 authored Oct 18, 2022
2 parents 98cc720 + 161a5d6 commit 5154e05
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "robonomics-interface"
version = "1.3.5"
version = "1.3.6"
description = "Robonomics wrapper over https://github.com/polkascan/py-substrate-interface created to facilitate programming with Robonomics"
authors = ["Pavel Tarasov <[email protected]>"]
license = "Apache-2.0"
Expand Down
24 changes: 22 additions & 2 deletions robonomicsinterface/classes/digital_twin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ class DigitalTwin(BaseClass):
Class for interacting with `Digital Twins <https://wiki.robonomics.network/docs/en/digital-twins/>`_..
"""

@staticmethod
def _process_topic(topic: str) -> str:
"""
Hash topic to a certain length if it doesn't meet topic format requirements.
:param topic: Topic name to process.
:return: Processed topic name
"""

try:
int(topic, 16)
if len(topic) == 66:
return topic
else:
return dt_encode_topic(topic)
except ValueError:
return dt_encode_topic(topic)

def get_info(self, dt_id: int, block_hash: tp.Optional[str] = None) -> tp.Optional[DigitalTwinTyping]:
"""
Fetch information about existing digital twin.
Expand Down Expand Up @@ -72,7 +92,7 @@ def get_source(self, dt_id: int, topic: str, block_hash: tp.Optional[str] = None
dt_map: tp.Optional[DigitalTwinTyping] = self.get_info(dt_id, block_hash=block_hash)
if not dt_map:
raise DigitalTwinMapException("No Digital Twin was created or Digital Twin map is empty.")
topic_hashed: str = dt_encode_topic(topic)
topic_hashed: str = self._process_topic(topic)
for source in dt_map:
if source[0] == topic_hashed:
return source[1]
Expand Down Expand Up @@ -119,7 +139,7 @@ def set_source(self, dt_id: int, topic: str, source: str, nonce: tp.Optional[int
"""

topic_hashed = dt_encode_topic(topic)
topic_hashed = self._process_topic(topic)
return (
topic_hashed,
self._service_functions.extrinsic(
Expand Down
4 changes: 2 additions & 2 deletions robonomicsinterface/classes/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def __init__(
:param account: Account dataclass with ``seed``, ``remote_ws`` address and node ``type_registry``.
:param subscribed_event: Event in substrate chain to be awaited. Choose from [``NewRecord``, ``NewLaunch``,
``Transfer``, ``TopicChanged``, ``NewDevices``]. This parameter should be a ``SubEvent`` class attribute.
This also requires importing this class.
``Transfer``, ``TopicChanged``, ``NewDevices``, ``NewLiability``, ``NewReport``]. This parameter should be a
``SubEvent`` class attribute. This also requires importing this class.
:param subscription_handler: Callback function that processes the updates of the storage.
THIS FUNCTION IS MEANT TO ACCEPT ONLY ONE ARGUMENT (THE NEW EVENT DESCRIPTION TUPLE) by default.
It will receive event ID as a second parameter if ``pass_event_id`` is True.
Expand Down

0 comments on commit 5154e05

Please sign in to comment.