@instadapp/interop-x 0.0.0-dev.5bcd66b → 0.0.0-dev.67e7c3a

Sign up to get free protection for your applications and to get access to all the features.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.5bcd66b",
3
+ "version": "0.0.0-dev.67e7c3a",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -8,6 +8,7 @@ class Config {
8
8
  this.maxPeers = 10;
9
9
  this.privateKey = process.env.PRIVATE_KEY;
10
10
  this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
11
+ this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
11
12
  this.wallet = new ethers_1.Wallet(this.privateKey);
12
13
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
13
14
  }
package/dist/src/index.js CHANGED
@@ -30,12 +30,18 @@ const printUsage = () => {
30
30
  console.log('Usage:');
31
31
  console.log(' PRIVATE_KEY=abcd1234 interop-x');
32
32
  console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x');
33
+ console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x');
33
34
  console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x');
34
35
  };
35
36
  if (process.argv.at(-1) === 'help') {
36
37
  printUsage();
37
38
  process.exit(0);
38
39
  }
40
+ const GIT_SHORT_HASH = '67e7c3a';
41
+ if (process.argv.at(-1) === 'version') {
42
+ console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
43
+ process.exit(0);
44
+ }
39
45
  if (!process.env.PRIVATE_KEY) {
40
46
  console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
41
47
  printUsage();
@@ -49,7 +55,7 @@ catch (e) {
49
55
  printUsage();
50
56
  process.exit(1);
51
57
  }
52
- logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.5bcd66b)`);
58
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
53
59
  const tasks_1 = require("@/tasks");
54
60
  const net_1 = require("@/net");
55
61
  const api_1 = require("@/api");
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseTask_1 = require("./BaseTask");
7
+ const logger_1 = __importDefault(require("@/logger"));
8
+ const package_json_1 = __importDefault(require("../../package.json"));
9
+ const utils_1 = require("@/utils");
10
+ const child_process_1 = require("child_process");
11
+ const config_1 = __importDefault(require("@/config"));
12
+ const currentVersion = package_json_1.default.version;
13
+ class AutoUpdateTask extends BaseTask_1.BaseTask {
14
+ constructor() {
15
+ super({
16
+ logger: new logger_1.default("AutoUpdateTask"),
17
+ });
18
+ this.pollIntervalMs = 60 * 1000;
19
+ }
20
+ prePollHandler() {
21
+ return config_1.default.autoUpdate && !config_1.default.isLeadNode();
22
+ }
23
+ async pollHandler() {
24
+ const { data } = await utils_1.http.get('https://registry.npmjs.org/@instadapp/interop-x');
25
+ const version = data['dist-tags'].latest;
26
+ if (version === currentVersion) {
27
+ return;
28
+ }
29
+ this.logger.warn(`New version ${version} available.`);
30
+ const update = (0, child_process_1.spawn)('npm', ['-g', 'install', '@instadapp/interop-x']);
31
+ update.on("close", () => {
32
+ this.logger.warn(`Installed version ${version}`);
33
+ this.logger.warn(`Restarting...`);
34
+ (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
35
+ cwd: process.cwd(),
36
+ env: Object.create(process.env),
37
+ detached: true,
38
+ stdio: "inherit"
39
+ });
40
+ process.exit();
41
+ });
42
+ }
43
+ }
44
+ exports.default = AutoUpdateTask;
@@ -8,9 +8,11 @@ const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/Proces
8
8
  const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
9
9
  const SyncWithdrawEvents_1 = __importDefault(require("./InteropBridge/SyncWithdrawEvents"));
10
10
  const ProcessWithdrawEvents_1 = __importDefault(require("./InteropBridge/ProcessWithdrawEvents"));
11
+ const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
11
12
  class Tasks {
12
13
  constructor() {
13
14
  this.tasks = [
15
+ new AutoUpdateTask_1.default(),
14
16
  new SyncDepositEvents_1.default({
15
17
  chainId: 43114
16
18
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.5bcd66b",
3
+ "version": "0.0.0-dev.67e7c3a",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -8,12 +8,14 @@ class Config {
8
8
  public readonly privateKey: string
9
9
  public readonly wallet: Wallet
10
10
  public readonly staging: boolean
11
+ public readonly autoUpdate: boolean
11
12
 
12
13
  constructor() {
13
14
  this.events = new EventBus() as EventBusType
14
15
  this.maxPeers = 10
15
16
  this.privateKey = process.env.PRIVATE_KEY as string;
16
17
  this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
18
+ this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
17
19
  this.wallet = new Wallet(this.privateKey);
18
20
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
19
21
  }
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ const printUsage = () => {
29
29
  console.log('Usage:')
30
30
  console.log(' PRIVATE_KEY=abcd1234 interop-x')
31
31
  console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x')
32
+ console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x')
32
33
  console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x')
33
34
  }
34
35
 
@@ -37,6 +38,12 @@ if (process.argv.at(-1) === 'help') {
37
38
  process.exit(0)
38
39
  }
39
40
 
41
+ const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
42
+
43
+ if (process.argv.at(-1) === 'version') {
44
+ console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
45
+ process.exit(0)
46
+ }
40
47
 
41
48
  if(! process.env.PRIVATE_KEY) {
42
49
  console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
@@ -51,7 +58,7 @@ try {
51
58
  process.exit(1)
52
59
  }
53
60
 
54
- logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.@GIT_SHORT_HASH@)`)
61
+ logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
55
62
 
56
63
  import { Tasks } from "@/tasks";
57
64
  import { startPeer, protocol, peerPool } from "@/net";
@@ -0,0 +1,54 @@
1
+ import { BaseTask } from "./BaseTask";
2
+ import Logger from '@/logger';
3
+ import packageJson from '../../package.json'
4
+ import { http } from "@/utils";
5
+ import { spawn } from 'child_process';
6
+ import config from "@/config";
7
+ const currentVersion = packageJson.version;
8
+
9
+ class AutoUpdateTask extends BaseTask {
10
+ pollIntervalMs: number = 60 * 1000
11
+
12
+ constructor() {
13
+ super({
14
+ logger: new Logger("AutoUpdateTask"),
15
+ })
16
+ }
17
+
18
+
19
+ prePollHandler(): boolean {
20
+ return config.autoUpdate && !config.isLeadNode();
21
+ }
22
+
23
+ async pollHandler() {
24
+
25
+ const { data } = await http.get('https://registry.npmjs.org/@instadapp/interop-x')
26
+
27
+ const version = data['dist-tags'].latest
28
+
29
+ if (version === currentVersion) {
30
+ return;
31
+ }
32
+
33
+ this.logger.warn(`New version ${version} available.`)
34
+
35
+
36
+ const update = spawn('npm', ['-g', 'install', '@instadapp/interop-x']);
37
+
38
+ update.on("close", () => {
39
+ this.logger.warn(`Installed version ${version}`)
40
+ this.logger.warn(`Restarting...`)
41
+
42
+ spawn(process.argv[0], process.argv.slice(1), {
43
+ cwd: process.cwd(),
44
+ env: Object.create(process.env),
45
+ detached: true,
46
+ stdio: "inherit"
47
+ });
48
+
49
+ process.exit()
50
+ })
51
+ }
52
+ }
53
+
54
+ export default AutoUpdateTask;
@@ -4,10 +4,13 @@ import InteropXGatewaySyncDepositEvents from "./InteropXGateway/SyncDepositEvent
4
4
 
5
5
  import InteropBridgeSyncWithdrawEvents from "./InteropBridge/SyncWithdrawEvents";
6
6
  import InteropBridgeProcessWithdrawEvents from "./InteropBridge/ProcessWithdrawEvents";
7
+ import AutoUpdateTask from "./AutoUpdateTask";
7
8
 
8
9
  export class Tasks {
9
10
 
10
11
  tasks: BaseTask[] = [
12
+ new AutoUpdateTask(),
13
+
11
14
  new InteropXGatewaySyncDepositEvents({
12
15
  chainId: 43114
13
16
  }),