def _pin_to_pinata(file_path: str, config: dict) -> None:
    pinata_api = config["datalog"]["pinata_api"]
    pinata_secret = config["datalog"]["pinata_secret"]
    if pinata_secret:
        try:
            logger.info("DatalogFeeder: Pinning file to Pinata")
            pinata = PinataPy(pinata_api, pinata_secret)
            pinata.pin_file_to_ipfs(file_path)
            hash = pinata.pin_list()["rows"][0]["ipfs_pin_hash"]
            logger.info(f"DatalogFeeder: File sent to pinata. Hash is {hash}")
        except Exception as e:
            logger.warning(f"DatalogFeeder: Failed while pining file to Pinata. Error: {e}")
Пример #2
0
def _pin_to_pinata(file_path: str, config):
    pinata_api = config["datalog"]["pinata_api"]
    pinata_secret = config["datalog"]["pinata_secret"]
    if pinata_secret:
        try:
            rospy.loginfo("Pinning file to Pinata")
            pinata = PinataPy(pinata_api, pinata_secret)
            pinata.pin_file_to_ipfs(file_path)
            hash = pinata.pin_list()["rows"][0]["ipfs_pin_hash"]
            rospy.loginfo(f"File sent to pinata. Hash is {hash}")
        except Exception as e:
            rospy.loginfo(f"Failed while pining file to Pinata. Error: {e}")
Пример #3
0
def pin_to_pinata(filename: str, config: tp.Dict[str, tp.Dict[str, tp.Any]]) -> None:
    """
    :param filename: full name of a recorded video
    :type filename: str
    :param config: dictionary containing all the configurations
    :type config: dict

    pinning files in pinata to make them broadcasted around ipfs
    """
    pinata_api = config["pinata"]["pinata_api"]  # pinata credentials
    pinata_secret_api = config["pinata"]["pinata_secret_api"]
    if pinata_api and pinata_secret_api:
        pinata = PinataPy(pinata_api, pinata_secret_api)
        pinata.pin_file_to_ipfs(filename)  # here we actually send the entire file to pinata, not just its hash. It will
        # remain the same as if published locally, cause the content is the same.
        logging.info("File published to Pinata")
Пример #4
0
 def __init__(self):
     types = {
         'CameraInfo': CameraInfo,
         'Image': Image,
         'TFMessage': TFMessage,
         'InteractiveMarkerUpdate': InteractiveMarkerUpdate
     }
     rospy.init_node(f"rosbag_recorder", anonymous=False)
     config_path = rospy.get_param("~config")
     print(config_path)
     sdk = bosdyn.client.create_standard_sdk('understanding-spot')
     self.robot = sdk.create_robot('192.168.50.3')
     with open("/home/spot/config/config") as f:
         for line in f:
             line = line.split('/')
             user = line[0].strip()
             password = line[1].strip()
             pinata_pub = line[2].strip()
             pinata_secret = line[3].strip()
     self.pinata = PinataPy(pinata_pub, pinata_secret)
     self.robot.authenticate(user, password)
     self.state_client = self.robot.ensure_client('robot-state')
     inf = rosnode.get_node_info_description('/rviz')
     inf = inf.split()
     # self.topics_str = ''
     # types_name = []
     # topic = False
     # for p in inf:
     #     p = p.strip()
     #     if topic:
     #         if p[0] == '/':
     #             self.command_full.append(p)
     #             self.topics_str += f'{p} '
     #         # if p[0] == '[':
     #         #     types_name.append(p.split('/')[-1][:-1])
     #     if p == "Subscriptions:":
     #         topic = True
     #     if p == "Services:":
     #         topic = False
     # print(self.command_full)
     # print(types)
     self.recording = False
     i = 0
     self.bag = None
Пример #5
0
def upload(asset_folder):
    """
    Uploads media and metadata from a specific folder to IPFS and blockchain respectively.
    """
    click.echo(f"Starting upload...")
    click.echo(f"Checking contracts...")

    if not walletDeployed():
        return

    if not distributorDeployed():
        return

    numAssets = getNumberOfAssets(asset_folder)
    config = getDistributorConfig()
    pinata = PinataPy(pinata_api_key=config["pinata_api_key"],
                      pinata_secret_api_key=config["pinata_secret_api_key"])

    # Upload files to IPFS first
    click.echo(f"Checking IPFS uploads...")

    for i in range(0, numAssets):
        with open(os.path.join(asset_folder, str(i) + ".json")) as f:
            data = f.read()
        meta = json.loads(data)

        if meta["image"] == "":
            result = pinata.pin_file_to_ipfs(
                os.path.join(asset_folder,
                             str(i) + ".png"))
            if "IpfsHash" not in result:
                click.echo(
                    f"IPFS upload error! Please check config and run CLI again."
                )
                click.echo(f"Error message: {result}")
                quit()

            meta["image"] = "https://gateway.pinata.cloud/ipfs/" + result[
                "IpfsHash"]
            meta["properties"]["files"][0][
                "uri"] = "https://gateway.pinata.cloud/ipfs/" + result[
                    "IpfsHash"]
            meta["properties"]["files"][0]["type"] = "image/png"
            meta["properties"]["category"] = "image"

            jsonFile = os.path.join(asset_folder, str(i) + ".json")
            with open(jsonFile, "w") as fp:
                json.dump(meta, fp)

    # Upload metadatas to blockchain next, start where we left off (check current Distributor contents)
    msig = getWallet()
    distributor = getDistributor()
    info = distributor.getInfo(includeTokens=True, includeWhitelist=False)
    metadatas = info["tokens"]

    # Check that all uploaded metadatas are correct
    click.echo(f"Checking current on-chain metadatas...")

    for i in range(0, len(metadatas)):
        with open(os.path.join(asset_folder, str(i) + ".json")) as f:
            data = f.read()
        meta = json.loads(data)
        dumped = json.dumps(meta)
        if metadatas[i] != dumped:
            click.echo(
                f"Metadata mismatch! Index: {i}\n Metadata local: {dumped}\nMetadata remote: {metadatas[i]}"
            )
            click.echo(f"Updating...")
            distributor.setToken(msig=msig, index=i, metadata=dumped)

    # Upload the remaining
    click.echo(f"Uploading remaining metadatas...")
    metadatasBatch = []
    batchSize = 0
    for i in range(len(metadatas), numAssets):
        with open(os.path.join(asset_folder, str(i) + ".json")) as f:
            data = f.read()
        meta = json.loads(data)
        dumped = json.dumps(meta)
        #distributor.addTokens(msig=msig, metadatas=[dumped])

        # create a batch and cap at 12KB, when target capacity is reached upload it to blockchain
        metadatasBatch.append(dumped)
        batchSize += len(dumped)
        if batchSize > 12000:
            click.echo(
                f"Uploadting a batch of {len(metadatasBatch)} metadatas...")
            result = distributor.addTokens(msig=msig, metadatas=metadatasBatch)
            metadatasBatch = []
            batchSize = 0

    if batchSize > 0:
        click.echo(f"Uploadting a batch of {len(metadatasBatch)} metadatas...")
        distributor.addTokens(msig=msig, metadatas=metadatasBatch)
        metadatasBatch = []
        batchSize = 0

    click.echo(f"Upload complete!")
Пример #6
0
 def setUp(self):
     self.PINATA_API_KEY = os.environ.get("PINATA_API_KEY")
     self.PINATA_SECRET_API_KEY = os.environ.get("PINATA_SECRET_API_KEY")
     self.pinata = PinataPy(self.PINATA_API_KEY, self.PINATA_SECRET_API_KEY)