@simbachain/hardhat
Version:
Simba Chain plugin for hardhat
314 lines • 13.4 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("hardhat/config");
const chalk_1 = __importDefault(require("chalk"));
const login_1 = require("./login");
const exportcontract_1 = require("./exportcontract");
const deploycontract_1 = require("./deploycontract");
const logout_1 = require("./logout");
const help_1 = require("./help");
const simbainfo_1 = require("./simbainfo");
const dirs_1 = require("./dirs");
const web3_suites_1 = require("@simbachain/web3-suites");
const loglevel_1 = require("./loglevel");
const contract_1 = require("./contract");
const SIMBA_COMMANDS = {
login: "log in to Blocks using keycloak device login",
export: "export your contract(s) to Blocks",
deploy: "deploy your contract(s) to the blockchain using Blocks",
logout: "logout of Blocks",
loglevel: "set level for tslog logger",
help: "get help for simba tasks",
viewcontracts: "view contracts for your organisation",
pull: "pull sol files and simba.json source code from SIMBA Chain",
addlib: "add external library so you can deploy contracts that depend on that library",
simbainfo: "grab info from your simba.json",
setdir: "set directory. --dirpath can be either artifact, build, or contract",
getdirs: "see readout of current directory paths for your project",
resetdir: "reset directory path for 'build', 'artifact', or 'contract'",
deletecontract: "delete contract"
};
var Commands;
(function (Commands) {
Commands["LOGIN"] = "login";
Commands["EXPORT"] = "export";
Commands["DEPLOY"] = "deploy";
Commands["LOGOUT"] = "logout";
Commands["HELP"] = "help";
Commands["LOGLEVEL"] = "loglevel";
Commands["VIEWCONTRACTS"] = "viewcontracts";
Commands["PULL"] = "pull";
Commands["ADDLIB"] = "addlib";
Commands["SIMBAINFO"] = "simbainfo";
Commands["SETDIR"] = "setdir";
Commands["GETDIRS"] = "getdirs";
Commands["RESETDIR"] = "resetdir";
Commands["DELETECONTRACT"] = "deletecontract";
})(Commands || (Commands = {}));
;
/**
* this is the main entry point for the CLI
* cmd is the main command to call (eg deploy, export, etc.)
* @param cmd
* @param topic
* @param primary
* @param deleteNonExportedArtifacts
* @param logLevel
* @param designID
* @param libraryName
* @param libraryAddress
*/
const simba = async (hre, cmd, topic, primary, deleteNonExportedArtifacts, logLevel, designID, libraryName, libraryAddress, interactive, org, app, contractName, pullSourceCode, pullSolFiles, useSimbaPath, savemode, field, contract, dirName, dirPath) => {
const entryParams = {
cmd,
topic,
primary,
logLevel,
designID,
libraryName,
libraryAddress,
interactive,
org,
app,
contractName,
pullSourceCode,
pullSolFiles,
useSimbaPath,
savemode,
field,
contract,
dirName,
dirPath,
};
web3_suites_1.SimbaConfig.log.debug(`:: ENTER : ${JSON.stringify(entryParams)}`);
let _interactive = true;
if (interactive) {
interactive = interactive.toLowerCase();
switch (interactive) {
case "false": {
_interactive = false;
break;
}
case "true": {
_interactive = true;
break;
}
default: {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: unrecognized value for "interactive" flag. Please enter '--interactive true' or '--interactive false' for this flag`)}`);
return;
}
}
}
else {
_interactive = true;
}
let _pullSourceCode = true;
if (pullSourceCode) {
pullSourceCode = pullSourceCode.toLowerCase();
switch (pullSourceCode) {
case "false": {
_pullSourceCode = false;
break;
}
case "true": {
_pullSourceCode = true;
break;
}
default: {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: unrecognized value for "pullsourcecode" flag. Please enter '--pullsourcecode true' or '--pullsourcecode false' for this flag`)}`);
return;
}
}
}
else {
_pullSourceCode = true;
}
let _pullSolFiles = true;
if (pullSolFiles) {
pullSolFiles = pullSolFiles.toLowerCase();
switch (pullSolFiles) {
case "false": {
_pullSolFiles = false;
break;
}
case "true": {
_pullSolFiles = true;
break;
}
default: {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: unrecognized value for "pullsolfiles" flag. Please enter '--pullsolfiles true' or '--pullsolfiles false' for this flag`)}`);
return;
}
}
}
else {
_pullSolFiles = false;
}
let _useSimbaPath = true;
if (useSimbaPath) {
useSimbaPath = useSimbaPath.toLowerCase();
switch (useSimbaPath) {
case "false": {
_useSimbaPath = false;
break;
}
case "true": {
_useSimbaPath = true;
break;
}
default: {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: unrecognized value for "useSimbaPath" flag. Please enter '--useSimbaPath true' or '--useSimbaPath false' for this flag`)}`);
return;
}
}
}
else {
_useSimbaPath = true;
}
if (savemode) {
if (!(savemode === "new" || savemode === "update")) {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: Invalid value for savemode: must be 'new' or 'update'`)}`);
return;
}
}
else {
savemode = "new";
}
switch (cmd) {
case Commands.LOGIN: {
await (0, login_1.login)(_interactive, org, app);
break;
}
case Commands.EXPORT: {
await (0, exportcontract_1.exportContract)(hre, _interactive, primary, savemode);
break;
}
case Commands.DEPLOY: {
await (0, deploycontract_1.deployContract)(primary);
break;
}
case Commands.LOGOUT: {
await (0, logout_1.logout)();
break;
}
case Commands.HELP: {
await (0, help_1.help)(topic);
break;
}
case Commands.LOGLEVEL: {
await (0, loglevel_1.setLogLevel)(logLevel);
break;
}
case Commands.VIEWCONTRACTS: {
await (0, contract_1.viewContracts)();
break;
}
case Commands.PULL: {
// we want non-interactive pull by default
if (!interactive) {
_interactive = false;
}
await (0, contract_1.pull)(designID, contractName, _pullSourceCode, _pullSolFiles, _interactive, _useSimbaPath);
break;
}
case Commands.ADDLIB: {
await (0, contract_1.addLibrary)(libraryName, libraryAddress);
break;
}
case Commands.SIMBAINFO: {
(0, simbainfo_1.getSimbaInfo)(field, contract);
break;
}
case Commands.GETDIRS: {
(0, dirs_1.setOrGetDir)("get");
break;
}
case Commands.SETDIR: {
if (!dirName || !dirPath) {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: you must specify both dirname and dirpath`)}`);
return;
}
if (dirName !== "contracts" && dirName !== "contract" && dirName !== "build" && dirName !== "artifact" && dirName !== "artifacts") {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: dirname param must be one of "contract", "contracts", "build", "artifact", or "artifacts`)}`);
return;
}
if (dirName === "contracts" || dirName === "contract") {
dirName = web3_suites_1.AllDirs.CONTRACTDIRECTORY;
}
if (dirName === "build") {
dirName = web3_suites_1.AllDirs.BUILDDIRECTORY;
}
if (dirName === "artifact" || dirName === "artifacts") {
dirName = web3_suites_1.AllDirs.ARTIFACTDIRECTORY;
}
(0, dirs_1.setOrGetDir)("set", dirName, dirPath);
break;
}
case Commands.RESETDIR: {
if (!dirName) {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: dirname must be specified.`)}`);
return;
}
if (dirName !== "contracts" && dirName !== "contract" && dirName !== "build" && dirName !== "artifact" && dirName !== "artifacts" && dirName !== "all") {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: dirname param must be one of "contract", "contracts", "build", "artifact", "artifacts"
, or "all"`)}`);
return;
}
if (dirName === "contracts" || dirName === "contract") {
dirName = web3_suites_1.AllDirs.CONTRACTDIRECTORY;
}
if (dirName === "build") {
dirName = web3_suites_1.AllDirs.BUILDDIRECTORY;
}
if (dirName === "artifact" || dirName === "artifacts") {
dirName = web3_suites_1.AllDirs.ARTIFACTDIRECTORY;
}
if (dirName.toLowerCase() === "all") {
for (const value in web3_suites_1.AllDirs) {
(0, dirs_1.setOrGetDir)("set", web3_suites_1.AllDirs[value], "reset");
}
return;
}
(0, dirs_1.setOrGetDir)("set", dirName, "reset");
break;
}
case Commands.DELETECONTRACT: {
await (0, contract_1.deleteContract)(designID);
break;
}
default: {
web3_suites_1.SimbaConfig.log.error(`${chalk_1.default.redBright(`\nsimba: unrecognized command - Please enter a valid simba command:\n${chalk_1.default.cyanBright(`${JSON.stringify(SIMBA_COMMANDS)}`)}`)}`);
break;
}
}
web3_suites_1.SimbaConfig.log.debug(`:: EXIT :`);
};
(0, config_1.task)("simba", "base simba cli that takes args")
.addPositionalParam("cmd", "command to call through simba")
.addOptionalParam("topic", "pass optional help topic when cmd == 'help'")
.addOptionalParam("prm", "used to specify a primary contract for either export or deploy")
.addOptionalParam("lvl", "minimum log level to set your logger to")
.addOptionalParam("id", "id of the contract you want to pull from Blocks; also used as id of contract for deletecontract")
.addOptionalParam("libname", "name of the library you want to add")
.addOptionalParam("libaddr", "address of the library you want to add")
.addOptionalParam("interactive", "'true' or 'false' for interactive export, login, and pull")
.addOptionalParam("org", "SIMBA org that you want to log into non-interactively")
.addOptionalParam("app", "SIMBA app that you want to log into non-interactively")
.addOptionalParam("contractname", "contract name for pull command")
.addOptionalParam("pullsourcecode", "'true' or 'false' for whether or not source code should be pulled for simba.json. Defaults to 'true', and this should be the case, unless the user has a reason for not wanting to sync their simba.json")
.addOptionalParam("pullsolfiles", "'true' or 'false' for whether user wants to sync their .sol files in their /contracts/ directory")
.addOptionalParam("usesimbapath", "'true' if you want to pull contracts to contracts/SimbaImports/, defaults to 'true'")
.addOptionalParam("savemode", "'new' to create save a new contract design, 'update' to update an existing one. Defaults to 'new'")
.addOptionalParam("field", "field to print from simba.json")
.addOptionalParam("contract", "contract to pull info for from simba.json. can be a contractName (without .sol) or 'all'")
.addOptionalParam("dirname", "name of directory to set using setdir command")
.addOptionalParam("dirpath", "can be either path to directory for setdir, or 'reset' to reset to default setting for directory")
.setAction(async (taskArgs, hre) => {
const { cmd, topic, prm, dltnon, lvl, id, libname, libaddr, interactive, org, app, contractname, pullsourcecode, pullsolfiles, usesimbapath, savemode, field, contract, dirname, dirpath, } = taskArgs;
await simba(hre, cmd, topic, prm, dltnon, lvl, id, libname, libaddr, interactive, org, app, contractname, pullsourcecode, pullsolfiles, usesimbapath, savemode, field, contract, dirname, dirpath);
});
exports.default = simba;
//# sourceMappingURL=simba.js.map