-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add localnet command #16
Changes from 14 commits
4ca6b76
eeb45ec
68a67ad
a4c8d71
1a09eae
cebc398
a8d342c
1acd846
3973ee2
d90245b
5940293
4d44048
55b145c
860f415
edddec3
40b8aa8
c58b62b
f2a9ecf
724a224
4dd22b2
fcd11b1
21ea0bb
fbd18ed
ec6a3e8
04eaa91
cb5a4ba
38c14a3
7ffb3ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#! /usr/bin/env node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the files in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed @ c58b62b |
||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
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) : adopt(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 chalk_1 = __importDefault(require("chalk")); | ||
// @ts-ignore | ||
// const figlet = require('figlet'); | ||
const figlet_1 = __importDefault(require("figlet")); | ||
// import method to create projects | ||
const create_1 = __importDefault(require("./create")); | ||
const deposit_1 = __importDefault(require("./deposit")); | ||
const withdraw_1 = __importDefault(require("./withdraw")); | ||
const localnet_1 = __importDefault(require("./localnet")); | ||
const help_1 = __importDefault(require("./help")); | ||
const confirm_withdraw_1 = __importDefault(require("./confirm-withdraw")); | ||
const zeek_1 = __importDefault(require("./zeek")); | ||
const availableOptions = [ | ||
"create", | ||
"deposit", | ||
"withdraw", | ||
"localnet", | ||
"confirm-withdraw", | ||
"help", | ||
]; | ||
// second argument should be the selected option | ||
const option = process.argv[2]; | ||
const main = () => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!availableOptions.includes(option)) { | ||
console.log(`Invalid operation. Available operations are: ${availableOptions}`); | ||
process.exit(-1); | ||
} | ||
// Starts CLI | ||
console.log(chalk_1.default.magentaBright(figlet_1.default.textSync(`zkSync ${option}`, { horizontalLayout: "full" }))); | ||
const zeekFlag = Boolean(process.argv.filter((arg) => arg === "--zeek")[0]); | ||
const l1RpcUrl = String(process.argv | ||
.filter((arg) => arg.startsWith("l1-rpc-url")) | ||
.map((arg) => arg.split("=")[1])[0]); | ||
const l2RpcUrl = String(process.argv | ||
.filter((arg) => arg.startsWith("l2-rpc-url")) | ||
.map((arg) => arg.split("=")[1])[0]); | ||
switch (option) { | ||
case "create": | ||
// arg 3 is the project name | ||
const projectName = process.argv[3] || "."; | ||
yield (0, create_1.default)(projectName, zeekFlag); | ||
break; | ||
case "deposit": | ||
yield (0, deposit_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); | ||
break; | ||
case "withdraw": | ||
yield (0, withdraw_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); | ||
break; | ||
case "confirm-withdraw": | ||
yield (0, confirm_withdraw_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); | ||
break; | ||
case 'localnet': | ||
const subcommandName = process.argv[3] || undefined; | ||
(0, localnet_1.default)(subcommandName); | ||
break; | ||
case "help": | ||
(0, help_1.default)(); | ||
break; | ||
} | ||
if (zeekFlag) { | ||
yield (0, zeek_1.default)(); | ||
} | ||
process.exit(0); | ||
}); | ||
main(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function (operationName: string | undefined): Promise<void>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
"use strict"; | ||
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 (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
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) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const child_process_1 = require("child_process"); | ||
const path = __importStar(require("path")); | ||
const fs = __importStar(require("fs")); | ||
const os = __importStar(require("os")); | ||
const REPO_URL = "https://github.com/matter-labs/local-setup.git"; | ||
const REPO_BRANCH = "main"; | ||
// --------------------------------------------------------------------------------------- | ||
// Utilities | ||
// --------------------------------------------------------------------------------------- | ||
function runCommand(command, options) { | ||
const defaultOptions = { cwd: repoDirectory(), encoding: 'utf-8' }; | ||
const unifiedOptions = Object.assign(Object.assign({}, defaultOptions), options); | ||
return (0, child_process_1.execSync)(command, unifiedOptions).toString(); | ||
} | ||
function repoDirectory() { | ||
const xdgStateHome = process.env.XDG_STATE_HOME || path.join(os.homedir(), ".local/state"); | ||
return path.join(xdgStateHome, "zksync-cli/local-setup"); | ||
} | ||
function isRepoCloned() { | ||
return fs.existsSync(repoDirectory()); | ||
} | ||
function cloneRepo() { | ||
const parentDirectory = path.join(repoDirectory(), ".."); | ||
runCommand(`mkdir -p '${parentDirectory}'`, { cwd: "/" }); | ||
const options = { cwd: parentDirectory }; | ||
runCommand(`git clone --branch '${REPO_BRANCH}' '${REPO_URL}'`, options); | ||
} | ||
function setUp() { | ||
cloneRepo(); | ||
} | ||
// --------------------------------------------------------------------------------------- | ||
// Localnet operations | ||
// --------------------------------------------------------------------------------------- | ||
function logs() { | ||
const options = { stdio: 'inherit' }; | ||
runCommand("docker compose logs --follow", options); | ||
return 0; | ||
} | ||
function up() { | ||
if (!isRepoCloned()) { | ||
setUp(); | ||
} | ||
runCommand("docker compose up --detach"); | ||
return 0; | ||
} | ||
function down() { | ||
runCommand("docker compose down --volumes"); | ||
return 0; | ||
} | ||
function start() { | ||
runCommand("docker compose start"); | ||
return 0; | ||
} | ||
function stop() { | ||
runCommand("docker compose stop"); | ||
return 0; | ||
} | ||
function wallets() { | ||
const rawJSON = fs.readFileSync(path.join(repoDirectory(), "rich-wallets.json")).toString(); | ||
const wallets = JSON.parse(rawJSON); | ||
console.log(wallets); | ||
return 0; | ||
} | ||
// --------------------------------------------------------------------------------------- | ||
// Command handling | ||
// --------------------------------------------------------------------------------------- | ||
function help() { | ||
console.log("USAGE: zksync-cli localnet <operation>"); | ||
console.log(""); | ||
console.log("Manage local L1 and L2 chains"); | ||
console.log(""); | ||
console.log("Available operations"); | ||
console.log(' up -- Bootstrap L1 and L2 localnets'); | ||
console.log(' down -- clear L1 and L2 localnets'); | ||
console.log(' start -- start L1 and L2 localnets'); | ||
console.log(' stop -- stop L1 and L2 localnets'); | ||
console.log(' logs -- Display logs'); | ||
console.log(' help -- Display this message and quit'); | ||
console.log(' wallets -- Display seeded wallet keys'); | ||
return 0; | ||
} | ||
function handleUndefinedOperation() { | ||
console.error("No operation provided"); | ||
help(); | ||
return 1; | ||
} | ||
function handleInvalidOperation(operationName) { | ||
const validOperationNames = Array.from(operationHandlers.keys()); | ||
console.error('Invalid operation: ', operationName); | ||
help(); | ||
return 1; | ||
} | ||
const operationHandlers = new Map([ | ||
['up', up], | ||
['down', down], | ||
['start', start], | ||
['stop', stop], | ||
['logs', logs], | ||
['help', help], | ||
['wallets', wallets], | ||
[undefined, handleUndefinedOperation], | ||
]); | ||
function default_1(operationName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const handler = operationHandlers.get(operationName) || (() => handleInvalidOperation(operationName)); | ||
process.exit(handler()); | ||
}); | ||
} | ||
exports.default = default_1; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤