UNPKG

@acurast/cli

Version:

A cli to interact with the Acurast Cloud.

52 lines 2.55 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { AcurastService } from './env/acurastService.js'; import { getWallet } from '../util/getWallet.js'; /** * Updates the script of a mutable deployment * @param deploymentId - The deployment ID in format [MultiOrigin, address, number] * @param script - The IPFS hash of the new script (must start with "ipfs://") * @returns Promise<string> - The transaction hash */ export const editScript = (deploymentId, script) => __awaiter(void 0, void 0, void 0, function* () { // Validate that script is an IPFS hash if (!script.startsWith('ipfs://')) { throw new Error('Script must be an IPFS hash starting with "ipfs://"'); } const acurast = new AcurastService(); const wallet = yield getWallet(); try { yield acurast.connect(); if (!acurast.api) { throw new Error('API not connected'); } // Convert the deploymentId to the format expected by the extrinsic // The extrinsic expects (AcurastCommonMultiOrigin, u128) where: // - AcurastCommonMultiOrigin is { acurast: AccountId32 } // - u128 is the deployment number const jobId = [ { acurast: deploymentId[1] }, // AcurastCommonMultiOrigin deploymentId[2], // u128 deployment number ]; // Convert IPFS hash to Bytes format // Remove 'ipfs://' prefix and convert to bytes const ipfsHash = script.replace('ipfs://', ''); const scriptBytes = `0x${Buffer.from(ipfsHash, 'utf8').toString('hex')}`; // Call the extrinsic const tx = yield acurast.api.tx.acurastMarketplace.editScript(jobId, scriptBytes); const signedTx = yield tx.signAsync(wallet); const hash = yield signedTx.send(); return hash.toString(); } finally { yield acurast.disconnect(); } }); //# sourceMappingURL=editScript.js.map