UNPKG

@authereum/zos

Version:

Command-line interface for the ZeppelinOS smart contract platform

101 lines 5.83 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_pickby_1 = __importDefault(require("lodash.pickby")); const zos_lib_1 = require("zos-lib"); const link_1 = __importDefault(require("./link")); const add_1 = __importDefault(require("./add")); const push_1 = __importDefault(require("./push")); const create_1 = __importDefault(require("../scripts/create")); const Session_1 = __importDefault(require("../models/network/Session")); const Compiler_1 = require("../models/compiler/Compiler"); const naming_1 = require("../utils/naming"); const migrations_1 = require("../prompts/migrations"); const ConfigManager_1 = __importDefault(require("../models/config/ConfigManager")); const prompt_1 = require("../prompts/prompt"); const method_params_1 = __importDefault(require("../prompts/method-params")); const interfaces_1 = require("../scripts/interfaces"); const name = 'create'; const signature = `${name} [alias]`; const description = 'deploys a new upgradeable contract instance. Provide the <alias> you added your contract with, or <package>/<alias> to create a contract from a linked package.'; const register = program => program .command(signature, undefined, { noHelp: true }) .usage('[alias] --network <network> [options]') .description(description) .option('--init [function]', `call function after creating contract. If none is given, 'initialize' will be used`) .option('--args <arg1, arg2, ...>', 'provide initialization arguments for your contract if required') .option('--force', 'force creation even if contracts have local modifications') .option('--minimal', 'creates a cheaper but non-upgradeable instance instead, using a minimal proxy') .withNetworkOptions() .withSkipCompileOption() .withNonInteractiveOption() .action(commandActions); function commandActions(contractFullName, options) { return __awaiter(this, void 0, void 0, function* () { if (options.minimal) { zos_lib_1.Loggy.noSpin.warn(__filename, 'action', 'create-minimal-proxy', 'Minimal proxy support is still experimental.'); } const { skipCompile } = options; if (!skipCompile) yield Compiler_1.compile(); const { network: promptedNewtork, contractFullName: promptedContractFullName, } = yield promptForCreate(contractFullName, options); const { network, txParams } = yield ConfigManager_1.default.initNetworkConfiguration(Object.assign({}, options, { network: promptedNewtork })); yield link_1.default.runActionIfNeeded(promptedContractFullName, options); yield add_1.default.runActionIfNeeded(promptedContractFullName, options); yield push_1.default.runActionIfNeeded(promptedContractFullName, network, Object.assign({}, options, { network: promptedNewtork, force: true })); yield action(promptedContractFullName, Object.assign({}, options, { network, txParams })); if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0); }); } function action(contractFullName, options) { return __awaiter(this, void 0, void 0, function* () { const { force, network, txParams, init: rawInitMethod } = options; const { contract: contractAlias, package: packageName, } = naming_1.fromContractFullName(contractFullName); const additionalOpts = { askForMethodParams: rawInitMethod, askForMethodParamsMessage: 'Do you want to call a function on the instance after creating it?', }; const { methodName, methodArgs } = yield method_params_1.default(contractFullName, options, additionalOpts); const args = lodash_pickby_1.default({ packageName, contractAlias, methodName, methodArgs, force, }); if (options.minimal) args.kind = interfaces_1.ProxyType.Minimal; if (!(yield migrations_1.hasToMigrateProject(network))) process.exit(0); yield create_1.default(Object.assign({}, args, { network, txParams })); Session_1.default.setDefaultNetworkIfNeeded(network); }); } function promptForCreate(contractFullName, options) { return __awaiter(this, void 0, void 0, function* () { const { force, network: networkInOpts, interactive } = options; const { network: networkInSession, expired } = Session_1.default.getNetwork(); const defaultOpts = { network: networkInSession }; const args = { contractFullName }; const opts = { network: networkInOpts || (!expired ? networkInSession : undefined), }; return prompt_1.promptIfNeeded({ args, opts, defaults: defaultOpts, props: getCommandProps() }, interactive); }); } function getCommandProps() { return Object.assign({}, prompt_1.networksList('network', 'list'), prompt_1.contractsList('contractFullName', 'Pick a contract to instantiate', 'list', 'all')); } exports.default = { name, signature, description, register, action }; //# sourceMappingURL=create.js.map