UNPKG

@massalabs/massa-sc-utils

Version:
128 lines 4.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const massa_web3_1 = require("@massalabs/massa-web3"); const WebsiteDeployer_1 = require("../utils/WebsiteDeployer"); const prompt = require("prompt"); const path = require("path"); const fs = require("fs"); const chalk = require("chalk"); prompt.start(); const schema = { properties: { websiteZipFile: { description: "Website zipfile to deploy", message: "File must be a compressed zip", type: "string", required: true }, networkID: { description: "Network ID", message: "Must be one of MAINNET/TESTNET/LABNET or mainnet/testnet/labnet", pattern: "(MAINNET|TESTNET|LABNET|mainnet|testnet|labnet)", type: "string", default: "LABNET", required: true }, deployerSecretKey: { description: "Deployer Account Secret Key", message: "Secret key must be base58 encoded", type: "string", hidden: true, replace: "*", required: true }, fee: { description: "Fee", required: true, type: "number", default: 0 }, maxGas: { description: "Max Gas", required: true, type: "number", default: 200000 }, gasPrice: { description: "Gas Price", required: true, type: "number", default: 0 }, coins: { description: "Coins to send with deployment", required: true, type: "number", default: 0, }, } }; prompt.get(schema, (err, result) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (err) { console.error(`Prompt error: ${chalk.red(err)}`); process.exit(1); } // get input from prompt const networkID = result.networkID.toUpperCase(); let selectedNetwork = massa_web3_1.DefaultProviderUrls.TESTNET; switch (networkID) { case "TESTNET": { selectedNetwork = massa_web3_1.DefaultProviderUrls.TESTNET; break; } case "MAINNET": { selectedNetwork = massa_web3_1.DefaultProviderUrls.MAINNET; break; } case "LABNET": { selectedNetwork = massa_web3_1.DefaultProviderUrls.LABNET; break; } default: { throw new Error(`Unknown network selected: ${networkID}`); } } const deployerSecretKey = result.deployerSecretKey; const websiteZipFile = result.websiteZipFile; if (!fs.existsSync(websiteZipFile)) { throw new Error(`The website file under ${websiteZipFile} does not exist.`); } if (!path.extname(websiteZipFile).endsWith(".zip")) { throw new Error(`The website file under ${websiteZipFile} is not a zip archive.`); } const fee = result.fee; const maxGas = result.maxGas; const gasPrice = result.gasPrice; const coins = result.coins; // init deployer account and a web3 client let deployerAccount; try { deployerAccount = yield massa_web3_1.WalletClient.getAccountFromSecretKey(deployerSecretKey); } catch (ex) { throw new Error(`Wrong secret key. Deployer account could not be initialized: ${ex}`); } let web3Client = null; try { web3Client = yield massa_web3_1.ClientFactory.createDefaultClient(selectedNetwork, true, deployerAccount); } catch (ex) { throw new Error(`Error creating a web3 client: ${ex}`); } try { // upload website to sc address yield (0, WebsiteDeployer_1.deployWebsite)(websiteZipFile, { fee, maxGas, gasPrice, coins, }, web3Client, true, deployerAccount); } catch (ex) { const msg = chalk.red(`Error compiling and deploying website on path ${chalk.yellow(websiteZipFile)}`); console.error(msg); throw new Error(ex); } })); //# sourceMappingURL=deployWebsite.js.map