Skip to content

Commit

Permalink
Merge pull request #95 from airalab/dev
Browse files Browse the repository at this point in the history
v.1.6.7
  • Loading branch information
tubleronchik authored Dec 8, 2024
2 parents 4451989 + 8e674b5 commit d70af80
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
4 changes: 3 additions & 1 deletion connectivity/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
MOBILE_GPS = 3
PING_MODEL = 1
STATION_VERSION = "v0.8.0"
PASKAL2MMHG = 133.32
PASKAL2MMHG = 133.32
POLKA_REMOTE_WS = "wss://polkadot.rpc.robonomics.network/"
KSM_REMOTE_WS = "wss://kusama.rpc.robonomics.network"
27 changes: 19 additions & 8 deletions connectivity/src/feeders/datalog_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sort_payload,
create_tmp_file,
)
from connectivity.constants import PING_MODEL
from connectivity.constants import PING_MODEL, POLKA_REMOTE_WS, KSM_REMOTE_WS

from .ifeeder import IFeeder
from .pinning_services import PinningManager
Expand Down Expand Up @@ -125,25 +125,36 @@ def to_datalog(self, ipfs_hash: str) -> None:
:param ipfs_hash: Ipfs hash of the file.
"""

account = Account(seed=self.config["datalog"]["suri"])
rws = RWS(account)
ksm_account = Account(seed=self.config["datalog"]["suri"], remote_ws=KSM_REMOTE_WS)
polkadot_account = Account(seed=self.config["datalog"]["suri"], remote_ws=POLKA_REMOTE_WS)
rws = RWS(ksm_account)
try:
if rws.get_days_left():
rws_sub_owner = account.get_address()
rws_sub_owner = ksm_account.get_address()
if not rws.is_in_sub(sub_owner_addr=rws_sub_owner, addr=rws_sub_owner):
rws.set_devices([rws_sub_owner])
rws_datalog = Datalog(account, rws_sub_owner=rws_sub_owner)
rws_datalog = Datalog(ksm_account, rws_sub_owner=rws_sub_owner)
robonomics_receipt = rws_datalog.record(ipfs_hash)
else:
datalog = Datalog(account)
datalog = Datalog(ksm_account)
robonomics_receipt = datalog.record(ipfs_hash)
logger.info(
f"Datalog Feeder: Ipfs hash sent to Robonomics Parachain and included in block {robonomics_receipt}"
f"Datalog Feeder: Ipfs hash sent to Robonomics KSM Parachain and included in block {robonomics_receipt}"
)
DATALOG_STATUS_METRIC.state("success")
self.datalog_db.update_status("sent", ipfs_hash)
except Exception as e:
logger.warning(
f"Datalog Feeder: Something went wrong during extrinsic submission to Robonomics: {e}"
f"Datalog Feeder: Something went wrong during extrinsic submission to KSM Robonomics: {e}"
)
DATALOG_STATUS_METRIC.state("error")
try:
datalog = Datalog(polkadot_account)
robonomics_receipt = datalog.record(ipfs_hash)
logger.info(
f"Datalog Feeder: Ipfs hash sent to Robonomics Polkadot Parachain and included in block {robonomics_receipt}"
)
except Exception as e:
logger.warning(
f"Datalog Feeder: Something went wrong during extrinsic submission to Polkadot Robonomics: {e}"
)
2 changes: 2 additions & 0 deletions connectivity/src/feeders/pinning_services/gateways/crust.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def pin(self, args: PinArgs) -> None:
def _can_upload(self, file_size: int) -> bool:
"""Check whether there is enough tokens on balance"""
balance = self._get_balance()
if not balance:
return None
approximately_price = self._get_store_price(file_size)
return balance >= approximately_price

Expand Down
14 changes: 12 additions & 2 deletions connectivity/src/feeders/pinning_services/pinning_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing as tp
import logging.config

from .gateways import (
CrustGateway,
Expand All @@ -7,7 +8,10 @@
TemporalGateway,
PinArgs,
)
from connectivity.config.logging import LOGGING_CONFIG

logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger("sensors-connectivity")

class PinningManager:
def __init__(self, config: dict) -> None:
Expand Down Expand Up @@ -36,9 +40,15 @@ def _set_gateways(self) -> None:

def pin_to_gateways(self, file_path: str) -> tp.Optional[str]:
pinArgs_for_local_gateway = PinArgs(file_path)
file_hash, file_size = self.gateways["local"].pin(pinArgs_for_local_gateway)
try:
file_hash, file_size = self.gateways["local"].pin(pinArgs_for_local_gateway)
except Exception as e:
logger.error(f"PinningManager: couldn't pin file to local gateway: {e}")
pin_args = PinArgs(file_path=file_path, hash=file_hash, file_size=file_size)
for gateway_name, gateway in self.gateways.items():
if gateway_name != "local":
gateway.pin(pin_args)
try:
gateway.pin(pin_args)
except Exception as e:
logger.error(f"PinningManager: couldn't pin {file_hash} to {gateway_name}: {e}")
return file_hash
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 = "sensors_connectivity"
version = "1.6.6"
version = "1.6.7"
description = "Robonomics package to read data from sensors and publish to different output channels"
authors = [
"Vadim Manaenko <[email protected]>",
Expand Down

0 comments on commit d70af80

Please sign in to comment.