scrypto-dev
Version:
CLI tool for Scrypto development on Radix DLT - deploy packages, generate types, manage accounts, and more
198 lines ⢠7.76 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.deploy = deploy;
const environment_1 = require("../utils/environment");
const transaction_1 = require("../utils/transaction");
const radix_engine_toolkit_1 = require("@radixdlt/radix-engine-toolkit");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
// import * as readline from 'readline'; // TODO: Re-enable when owner role configuration is implemented
// TODO: Re-enable when owner role configuration is implemented
// interface OwnerRoleConfig {
// type: "badge" | "none";
// updatable: "Fixed" | "Updatable";
// resourceAddress?: string;
// badgeType?: "fungible" | "nonfungible";
// nftId?: string;
// }
async function createDeployManifest(rpdPath, wasmBuffer, accountAddress) {
// Decode the RPD content
const rpdDecoded = await radix_engine_toolkit_1.RadixEngineToolkit.ManifestSbor.decodeToString(new Uint8Array(fs.readFileSync(rpdPath)), 2, radix_engine_toolkit_1.ManifestSborStringRepresentation.ManifestString);
// Get the hash of the WASM buffer
const wasmHash = (0, radix_engine_toolkit_1.hash)(new Uint8Array(wasmBuffer));
return `
CALL_METHOD
Address("${accountAddress}")
"lock_fee"
Decimal("500")
;
PUBLISH_PACKAGE
${rpdDecoded}
Blob("${radix_engine_toolkit_1.Convert.Uint8Array.toHexString(wasmHash)}")
Map<String, Tuple>()
;
CALL_METHOD
Address("${accountAddress}")
"deposit_batch"
Expression("ENTIRE_WORKTOP")
;
`;
}
// TODO: Re-enable when owner role configuration is implemented
// async function promptUser(question: string): Promise<string> {
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
//
// return new Promise((resolve) => {
// rl.question(question, (answer) => {
// rl.close();
// resolve(answer.trim());
// });
// });
// }
async function findWasmAndRpd() {
const targetDir = path.join(process.cwd(), "target/wasm32-unknown-unknown/release");
if (!fs.existsSync(targetDir)) {
console.error("ā Target directory not found. Make sure you're in a Scrypto project directory.");
console.error(" Expected: target/wasm32-unknown-unknown/release/");
return null;
}
const files = fs.readdirSync(targetDir);
// Find .wasm file (not the _with_schema one)
const wasmFile = files.find((file) => file.endsWith(".wasm") && !file.endsWith("_with_schema.wasm"));
// Find .rpd file
const rpdFile = files.find((file) => file.endsWith(".rpd"));
if (!wasmFile || !rpdFile) {
console.error("ā Required files not found in target/wasm32-unknown-unknown/release/");
console.error(` Looking for: *.wasm and *.rpd files`);
console.error(` Found: ${files.join(", ")}`);
return null;
}
return {
wasmPath: path.join(targetDir, wasmFile),
rpdPath: path.join(targetDir, rpdFile),
};
}
async function deploy() {
console.log("š Deploying package...");
const network = (0, environment_1.getCurrentNetwork)();
if (!network) {
console.log('ā No environment set. Use "scrypto-dev set-env <network>" to set one.');
return;
}
const activeAccount = (0, environment_1.getActiveAccount)();
if (!activeAccount) {
console.log('ā No active account set. Use "scrypto-dev set-address <account-id>" to set one.');
return;
}
console.log(`š” Network: ${network}`);
console.log(`š¤ Account: ${activeAccount.address}`);
// Find wasm and rpd files
const files = await findWasmAndRpd();
if (!files) {
return;
}
console.log(`š¦ Found WASM: ${path.basename(files.wasmPath)}`);
console.log(`š Found RPD: ${path.basename(files.rpdPath)}`);
// Read WASM buffer
const wasmBuffer = fs.readFileSync(files.wasmPath);
try {
// Create manifest
const manifest = await createDeployManifest(files.rpdPath, wasmBuffer, activeAccount.address);
console.log("\nš Submitting deployment transaction...");
console.log("š Manifest preview:");
console.log(manifest);
const result = await (0, transaction_1.buildAndSubmitTransaction)({
instructions: { kind: "String", value: manifest },
blobs: [new Uint8Array(wasmBuffer)],
});
(0, transaction_1.logTransactionResult)(result);
// Try to extract package address from transaction result
if (result.status.status === "CommittedSuccess") {
console.log("\nš¦ Package deployed successfully!");
}
}
catch (error) {
console.error("ā Deployment failed:", error);
console.error("Full error:", error);
}
}
// TODO: Re-implement owner role configuration once basic deployment works
// async function getOwnerRoleConfig(): Promise<OwnerRoleConfig> {
// console.log('\nš Owner Role Configuration');
//
// const roleType = await promptUser('Select owner role (badge/none): ');
//
// if (roleType.toLowerCase() === 'none') {
// return { type: 'none', updatable: 'Fixed' };
// }
//
// if (roleType.toLowerCase() !== 'badge') {
// console.log('Invalid selection. Defaulting to "none".');
// return { type: 'none', updatable: 'Fixed' };
// }
//
// const updatable = await promptUser('Owner role updatable (Fixed/Updatable): ');
// const isUpdatable = updatable.toLowerCase() === 'updatable' ? 'Updatable' : 'Fixed';
//
// const badgeType = await promptUser('Badge type (fungible/nonfungible): ');
//
// if (badgeType.toLowerCase() === 'fungible') {
// const resourceAddress = await promptUser('Resource address: ');
// return {
// type: 'badge',
// updatable: isUpdatable,
// resourceAddress,
// badgeType: 'fungible'
// };
// } else if (badgeType.toLowerCase() === 'nonfungible') {
// const resourceAddress = await promptUser('Resource address: ');
// const nftId = await promptUser('NFT ID (e.g., #0# or <admin_badge>): ');
// return {
// type: 'badge',
// updatable: isUpdatable,
// resourceAddress,
// badgeType: 'nonfungible',
// nftId
// };
// }
//
// console.log('Invalid badge type. Defaulting to "none".');
// return { type: 'none', updatable: 'Fixed' };
// }
//# sourceMappingURL=deploy.js.map