UNPKG

cc-zos

Version:

Command-line interface for the ZeppelinOS smart contract platform

48 lines (32 loc) 2.49 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _setAdmin = require('../scripts/set-admin'); var _setAdmin2 = _interopRequireDefault(_setAdmin); var _runWithTruffle = require('../utils/runWithTruffle'); var _runWithTruffle2 = _interopRequireDefault(_runWithTruffle); var _naming = require('../utils/naming'); var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const name = 'set-admin'; const signature = `${name} [alias-or-address] [new-admin-address]`; const description = 'change upgradeability admin of a contract instance. Provide the [alias] or [package]/[alias] of the contract to change the ownership of all its instances, or its [address] to change a single one. Note that if you transfer to an incorrect address, you may irreversibly lose control over upgrading your contract.'; const register = program => program.command(signature, { noHelp: true }).usage('[alias-or-address] [new-admin-address] --network <network> [options]').description(description).option('-y, --yes', 'accept transferring admin rights (required)').withNetworkOptions().action(action); async function action(contractFullNameOrAddress, newAdmin, options) { const { yes } = options; if (!yes) { throw Error("This is a potentially irreversible operation: if you specify an incorrect admin address, you may lose the ability to upgrade your contract forever.\nPlease double check all parameters, and run the same command with --yes."); } let proxyAddress, contractAlias, packageName; if (contractFullNameOrAddress && contractFullNameOrAddress.startsWith('0x')) { proxyAddress = contractFullNameOrAddress; } else if (contractFullNameOrAddress) { ({ contract: contractAlias, package: packageName } = (0, _naming.fromContractFullName)(contractFullNameOrAddress)); } const args = _lodash2.default.pickBy({ contractAlias, packageName, proxyAddress, newAdmin }); await (0, _runWithTruffle2.default)(async opts => await (0, _setAdmin2.default)(_extends({}, args, opts)), options); } exports.default = { name, signature, description, register, action };