UNPKG

@effectai/sdk

Version:

Effect Network Javscript/Typescript SDK (for [https://effect.network](https://effect.network))

34 lines 1.31 kB
import { TaskIpfsError } from "../../errors"; import { getIpfsResource } from "../ipfs/getIpfsResource"; import { getBatchById } from "./batch/getBatch"; export const getTaskData = async ({ client, taskIndex, batchId, }) => { try { const batch = await getBatchById({ client, id: batchId }); const i = taskIndex - batch.start_task_idx; const ipfsData = await getIpfsResource({ client, hash: batch.content.field_1, }); // Check if the ipfsData is an array if (!Array.isArray(ipfsData)) { throw new TaskIpfsError(`Task data retrieved from IPFS is not an array. \n${String(ipfsData)}`); } // Check if there is a task at the index if (ipfsData.length <= i || i < 0) { throw new TaskIpfsError(`Task data retrieved from IPFS does not have a task at index ${taskIndex}. \n${JSON.stringify(ipfsData)}`); } return ipfsData[i]; } catch (error) { console.error("Error while fetching task data:", error); throw error; } }; export const getTaskDataByReservation = (client, reservation) => { return getTaskData({ client, taskIndex: reservation.task_idx, batchId: reservation.batch_idx, }); }; //# sourceMappingURL=getTask.js.map