UNPKG

@iexec/dataprotector

Version:

This product enables users to confidentially store data–such as mail address, documents, personal information ...

46 lines 2.1 kB
import { WorkflowError } from '../../utils/errors.js'; import { resolveENS } from '../../utils/resolveENS.js'; import { addressOrEnsSchema, throwIfMissing } from '../../utils/validators.js'; import { getSharingContract } from './smartContract/getSharingContract.js'; import { onlyCollectionNotSubscribed, onlyCollectionOperator, onlyProtectedDataNotRented, } from './smartContract/preflightChecks.js'; import { getProtectedDataDetails } from './smartContract/sharingContract.reads.js'; export const removeProtectedDataFromCollection = async ({ iexec = throwIfMissing(), sharingContractAddress = throwIfMissing(), protectedData = throwIfMissing(), }) => { let vProtectedData = addressOrEnsSchema() .required() .label('protectedData') .validateSync(protectedData); // ENS resolution if needed vProtectedData = await resolveENS(iexec, vProtectedData); let userAddress = await iexec.wallet.getAddress(); userAddress = userAddress.toLowerCase(); const sharingContract = await getSharingContract(iexec, sharingContractAddress); //---------- Smart Contract Call ---------- const protectedDataDetails = await getProtectedDataDetails({ sharingContract, protectedData: vProtectedData, userAddress, }); await onlyCollectionOperator({ sharingContract, collectionId: Number(protectedDataDetails.collection.collectionId), userAddress, }); //---------- Pre flight check ---------- onlyCollectionNotSubscribed(protectedDataDetails); onlyProtectedDataNotRented(protectedDataDetails); try { const { txOptions } = await iexec.config.resolveContractsClient(); const tx = await sharingContract.removeProtectedDataFromCollection(vProtectedData, txOptions); await tx.wait(); return { txHash: tx.hash, }; } catch (e) { throw new WorkflowError({ message: 'Failed to remove protected data from collection', errorCause: e, }); } }; //# sourceMappingURL=removeProtectedDataFromCollection.js.map