@magicblock-labs/ephemeral-validator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const child_process_1 = require("child_process");
9
+ const path_1 = __importDefault(require("path"));
10
+ const os_1 = require("os");
11
+ const package_json_1 = require("./package.json");
12
+ const PACKAGE_VERSION = `ephemeral-validator ${package_json_1.version}`;
13
+ function getBinaryVersion(location) {
14
+ const result = (0, child_process_1.spawnSync)(location, ["--version"]);
15
+ const error = (result.error && result.error.toString()) ||
16
+ (result.stderr.length > 0 && result.stderr.toString().trim()) ||
17
+ null;
18
+ return [error, result.stdout && result.stdout.toString().trim()];
19
+ }
20
+ function getExePath() {
21
+ let os = (0, os_1.platform)();
22
+ let extension = "";
23
+ if (["win32", "cygwin"].includes(os)) {
24
+ os = "windows";
25
+ extension = ".exe";
26
+ }
27
+ const binaryName = `@magicblock-labs/ephemeral-validator-${os}-${(0, os_1.arch)()}/bin/ephemeral-validator${extension}`;
28
+ try {
29
+ return require.resolve(binaryName);
30
+ }
31
+ catch (e) {
32
+ throw new Error(`Couldn't find application binary inside node_modules for ${os}-${(0, os_1.arch)()}, expected location: ${binaryName}`);
33
+ }
34
+ }
35
+ function runEphemeralValidator(location) {
36
+ const args = process.argv.slice(2);
37
+ const ephemeralValidator = (0, child_process_1.spawn)(location, args, { stdio: "inherit" });
38
+ ephemeralValidator.on("exit", (code, signal) => {
39
+ process.on("exit", () => {
40
+ if (signal) {
41
+ process.kill(process.pid, signal);
42
+ }
43
+ else if (code !== null) {
44
+ process.exit(code);
45
+ }
46
+ });
47
+ });
48
+ process.on("SIGINT", () => {
49
+ ephemeralValidator.kill("SIGINT");
50
+ ephemeralValidator.kill("SIGTERM");
51
+ });
52
+ }
53
+ function tryPackageEphemeralValidator() {
54
+ try {
55
+ const path = getExePath();
56
+ runEphemeralValidator(path);
57
+ return true;
58
+ }
59
+ catch (e) {
60
+ console.error("Failed to run bolt from package:", e instanceof Error ? e.message : e);
61
+ return false;
62
+ }
63
+ }
64
+ function trySystemEphemeralValidator() {
65
+ var _a;
66
+ const absolutePath = (_a = process.env.PATH) === null || _a === void 0 ? void 0 : _a.split(path_1.default.delimiter).filter((dir) => dir !== path_1.default.dirname(process.argv[1])).find((dir) => {
67
+ try {
68
+ fs_1.default.accessSync(`${dir}/ephemeral-validator`, fs_1.default.constants.X_OK);
69
+ return true;
70
+ }
71
+ catch (_a) {
72
+ return false;
73
+ }
74
+ });
75
+ if (!absolutePath) {
76
+ console.error(`Could not find globally installed ephemeral-validator, please install with cargo.`);
77
+ process.exit(1);
78
+ }
79
+ const absoluteBinaryPath = `${absolutePath}/ephemeral-validator`;
80
+ const [error, binaryVersion] = getBinaryVersion(absoluteBinaryPath);
81
+ if (error !== null) {
82
+ console.error(`Failed to get version of global binary: ${error}`);
83
+ return;
84
+ }
85
+ if (binaryVersion !== PACKAGE_VERSION) {
86
+ console.error(`Globally installed ephemeral-validator version is not correct. Expected "${PACKAGE_VERSION}", found "${binaryVersion}".`);
87
+ return;
88
+ }
89
+ runEphemeralValidator(absoluteBinaryPath);
90
+ }
91
+ tryPackageEphemeralValidator() || trySystemEphemeralValidator();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@magicblock-labs/ephemeral-validator",
3
+ "version": "0.1.0",
4
+ "description": "MagicBlock Ephemeral Validator",
5
+ "homepage": "https://github.com/magicblock-labs/ephemeral-validator#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/magicblock-labs/ephemeral-validator/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/magicblock-labs/ephemeral-validator.git"
12
+ },
13
+ "license": "Business Source License 1.1",
14
+ "bin": {
15
+ "ephemeral-validator": "ephemeralValidator.js"
16
+ },
17
+ "scripts": {
18
+ "typecheck": "tsc --noEmit",
19
+ "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check ",
20
+ "lint:fix": "node_modules/.bin/prettier */*.js \"*/**/*{.js,.ts}\" -w",
21
+ "build": "tsc",
22
+ "dev": "yarn build && node lib/index.js"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^20.8.8",
26
+ "prettier": "^3.3.3",
27
+ "typescript": "^4.9.4"
28
+ },
29
+ "optionalDependencies": {
30
+ "@magicblock-labs/ephemeral-validator-darwin-arm64": "^0.1.0",
31
+ "@magicblock-labs/ephemeral-validator-darwin-x64": "0.1.0",
32
+ "@magicblock-labs/ephemeral-validator-linux-arm64": "0.1.0",
33
+ "@magicblock-labs/ephemeral-validator-linux-x64": "0.1.0",
34
+ "@magicblock-labs/ephemeral-validator-windows-x64": "0.1.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ }
39
+ }