@instadapp/interop-x 0.0.0-dev.b64d8b7 → 0.0.0-dev.b7bbd82
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +2 -2
- package/dist/src/config/index.js +10 -1
- package/dist/src/index.js +14 -1
- package/dist/src/tasks/AutoUpdateTask.js +28 -8
- package/dist/src/tasks/BaseTask.js +4 -0
- package/package.json +2 -2
- package/src/config/index.ts +9 -1
- package/src/index.ts +20 -4
- package/src/tasks/AutoUpdateTask.ts +29 -10
- package/src/tasks/BaseTask.ts +5 -0
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instadapp/interop-x",
|
3
|
-
"version": "0.0.0-dev.
|
3
|
+
"version": "0.0.0-dev.b7bbd82",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -28,7 +28,6 @@
|
|
28
28
|
"await-spawn": "^4.0.2",
|
29
29
|
"axios": "^0.27.1",
|
30
30
|
"axios-retry": "^3.2.4",
|
31
|
-
"bignumber.js": "^9.0.2",
|
32
31
|
"chalk": "4.1.2",
|
33
32
|
"dotenv": "^16.0.0",
|
34
33
|
"ethereumjs-util": "^7.1.4",
|
@@ -36,6 +35,7 @@
|
|
36
35
|
"ethers-multisend": "^2.1.1",
|
37
36
|
"expand-home-dir": "^0.0.3",
|
38
37
|
"fastify": "^3.28.0",
|
38
|
+
"fs-extra": "^10.1.0",
|
39
39
|
"libp2p": "^0.36.2",
|
40
40
|
"libp2p-bootstrap": "^0.14.0",
|
41
41
|
"libp2p-kad-dht": "^0.28.6",
|
package/dist/src/config/index.js
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
const ethers_1 = require("ethers");
|
4
7
|
const types_1 = require("@/types");
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
5
10
|
class Config {
|
6
11
|
constructor() {
|
7
12
|
this.events = new types_1.EventBus();
|
8
|
-
this.maxPeers =
|
13
|
+
this.maxPeers = 20;
|
9
14
|
this.privateKey = process.env.PRIVATE_KEY;
|
10
15
|
this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
|
11
16
|
this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
12
17
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
13
18
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
19
|
+
this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
14
20
|
}
|
15
21
|
get publicAddress() {
|
16
22
|
return this.wallet.address;
|
@@ -18,5 +24,8 @@ class Config {
|
|
18
24
|
isLeadNode() {
|
19
25
|
return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
|
20
26
|
}
|
27
|
+
isMaintenanceMode() {
|
28
|
+
return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
|
29
|
+
}
|
21
30
|
}
|
22
31
|
exports.default = new Config();
|
package/dist/src/index.js
CHANGED
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const module_alias_1 = __importDefault(require("module-alias"));
|
7
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
7
9
|
module_alias_1.default.addAliases({
|
8
10
|
"@/": __dirname + "/",
|
9
11
|
"@/logger": __dirname + "/logger",
|
@@ -37,7 +39,18 @@ if (process.argv.at(-1) === 'help') {
|
|
37
39
|
printUsage();
|
38
40
|
process.exit(0);
|
39
41
|
}
|
40
|
-
const
|
42
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
43
|
+
if (process.argv.at(-1) === 'down') {
|
44
|
+
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
45
|
+
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
46
|
+
process.exit(0);
|
47
|
+
}
|
48
|
+
if (process.argv.at(-1) === 'up') {
|
49
|
+
fs_extra_1.default.removeSync(basePath + '/maintenance');
|
50
|
+
console.log(chalk_1.default.green('Maintenance mode disabled'));
|
51
|
+
process.exit(0);
|
52
|
+
}
|
53
|
+
const GIT_SHORT_HASH = 'b7bbd82';
|
41
54
|
if (process.argv.at(-1) === 'version') {
|
42
55
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
43
56
|
process.exit(0);
|
@@ -5,32 +5,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const BaseTask_1 = require("./BaseTask");
|
7
7
|
const logger_1 = __importDefault(require("@/logger"));
|
8
|
-
const utils_1 = require("@/utils");
|
9
8
|
const await_spawn_1 = __importDefault(require("await-spawn"));
|
10
9
|
const config_1 = __importDefault(require("@/config"));
|
11
10
|
const waait_1 = __importDefault(require("waait"));
|
12
|
-
const
|
13
|
-
const currentVersion =
|
11
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
12
|
+
const currentVersion = package_json_1.default.version;
|
13
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
14
14
|
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
15
15
|
constructor() {
|
16
16
|
super({
|
17
17
|
logger: new logger_1.default("AutoUpdateTask"),
|
18
18
|
});
|
19
|
-
this.pollIntervalMs = 60 *
|
19
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
20
20
|
}
|
21
21
|
prePollHandler() {
|
22
22
|
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
23
23
|
}
|
24
|
+
async getInstalledVersion() {
|
25
|
+
try {
|
26
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['-g', 'ls', '--depth=0', '--json']);
|
27
|
+
return JSON.parse(stdout.toString()).dependencies[package_json_1.default.name].version;
|
28
|
+
}
|
29
|
+
catch (error) {
|
30
|
+
this.logger.error(error);
|
31
|
+
return currentVersion;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
async getLatestVersion() {
|
35
|
+
try {
|
36
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
|
37
|
+
return stdout.toString().trim();
|
38
|
+
}
|
39
|
+
catch (error) {
|
40
|
+
this.logger.error(error);
|
41
|
+
return currentVersion;
|
42
|
+
}
|
43
|
+
}
|
24
44
|
async pollHandler() {
|
25
|
-
const
|
26
|
-
const version = data['dist-tags'].latest;
|
45
|
+
const version = await this.getLatestVersion();
|
27
46
|
if (version === currentVersion) {
|
28
47
|
return;
|
29
48
|
}
|
30
49
|
this.logger.warn(`New version ${version} available.`);
|
31
|
-
|
50
|
+
this.logger.info('Updating...');
|
51
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
32
52
|
await (0, waait_1.default)(5000);
|
33
|
-
if (
|
53
|
+
if (version !== await this.getInstalledVersion()) {
|
34
54
|
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
35
55
|
return;
|
36
56
|
}
|
@@ -35,6 +35,10 @@ class BaseTask extends events_1.default {
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
prePollHandler() {
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
40
|
+
return false;
|
41
|
+
}
|
38
42
|
if (this.exceptLeadNode) {
|
39
43
|
return !config_1.default.isLeadNode();
|
40
44
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instadapp/interop-x",
|
3
|
-
"version": "0.0.0-dev.
|
3
|
+
"version": "0.0.0-dev.b7bbd82",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -28,7 +28,6 @@
|
|
28
28
|
"await-spawn": "^4.0.2",
|
29
29
|
"axios": "^0.27.1",
|
30
30
|
"axios-retry": "^3.2.4",
|
31
|
-
"bignumber.js": "^9.0.2",
|
32
31
|
"chalk": "4.1.2",
|
33
32
|
"dotenv": "^16.0.0",
|
34
33
|
"ethereumjs-util": "^7.1.4",
|
@@ -36,6 +35,7 @@
|
|
36
35
|
"ethers-multisend": "^2.1.1",
|
37
36
|
"expand-home-dir": "^0.0.3",
|
38
37
|
"fastify": "^3.28.0",
|
38
|
+
"fs-extra": "^10.1.0",
|
39
39
|
"libp2p": "^0.36.2",
|
40
40
|
"libp2p-bootstrap": "^0.14.0",
|
41
41
|
"libp2p-kad-dht": "^0.28.6",
|
package/src/config/index.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { ethers, Wallet } from "ethers"
|
2
2
|
import { EventBus, EventBusType } from "@/types"
|
3
|
+
import fs from 'fs-extra'
|
4
|
+
import expandHomeDir from "expand-home-dir";
|
3
5
|
|
4
6
|
class Config {
|
5
7
|
public readonly events: EventBusType
|
@@ -9,15 +11,17 @@ class Config {
|
|
9
11
|
public readonly wallet: Wallet
|
10
12
|
public readonly staging: boolean
|
11
13
|
public readonly autoUpdate: boolean
|
14
|
+
public readonly baseConfigPath: string
|
12
15
|
|
13
16
|
constructor() {
|
14
17
|
this.events = new EventBus() as EventBusType
|
15
|
-
this.maxPeers =
|
18
|
+
this.maxPeers = 20
|
16
19
|
this.privateKey = process.env.PRIVATE_KEY as string;
|
17
20
|
this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
|
18
21
|
this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
19
22
|
this.wallet = new Wallet(this.privateKey);
|
20
23
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
|
24
|
+
this.baseConfigPath = expandHomeDir(`~/.interop-x`);
|
21
25
|
}
|
22
26
|
|
23
27
|
get publicAddress(){
|
@@ -27,6 +31,10 @@ class Config {
|
|
27
31
|
isLeadNode() {
|
28
32
|
return ethers.utils.getAddress(this.leadNodeAddress) === ethers.utils.getAddress(this.wallet.address)
|
29
33
|
}
|
34
|
+
|
35
|
+
isMaintenanceMode(){
|
36
|
+
return fs.existsSync(this.baseConfigPath + '/maintenance')
|
37
|
+
}
|
30
38
|
}
|
31
39
|
|
32
40
|
export default new Config()
|
package/src/index.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import moduleAlias from 'module-alias';
|
2
|
-
|
2
|
+
import expandHomeDir from "expand-home-dir";
|
3
|
+
import fs from 'fs-extra'
|
3
4
|
moduleAlias.addAliases({
|
4
5
|
"@/": __dirname + "/",
|
5
6
|
"@/logger": __dirname + "/logger",
|
@@ -38,6 +39,21 @@ if (process.argv.at(-1) === 'help') {
|
|
38
39
|
process.exit(0)
|
39
40
|
}
|
40
41
|
|
42
|
+
const basePath = expandHomeDir(`~/.interop-x`);
|
43
|
+
|
44
|
+
if (process.argv.at(-1) === 'down') {
|
45
|
+
fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
|
46
|
+
console.log(chalk.red('Maintenance mode enabled'))
|
47
|
+
process.exit(0)
|
48
|
+
}
|
49
|
+
|
50
|
+
if (process.argv.at(-1) === 'up') {
|
51
|
+
fs.removeSync(basePath + '/maintenance')
|
52
|
+
console.log(chalk.green('Maintenance mode disabled'))
|
53
|
+
process.exit(0)
|
54
|
+
}
|
55
|
+
|
56
|
+
|
41
57
|
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
42
58
|
|
43
59
|
if (process.argv.at(-1) === 'version') {
|
@@ -45,7 +61,7 @@ if (process.argv.at(-1) === 'version') {
|
|
45
61
|
process.exit(0)
|
46
62
|
}
|
47
63
|
|
48
|
-
if(!
|
64
|
+
if (!process.env.PRIVATE_KEY) {
|
49
65
|
console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
|
50
66
|
printUsage()
|
51
67
|
process.exit(1)
|
@@ -80,10 +96,10 @@ async function main() {
|
|
80
96
|
if (!peerPool.isLeadNode(payload.peerId)) {
|
81
97
|
const peer = peerPool.getPeer(payload.peerId)
|
82
98
|
|
83
|
-
if(!
|
99
|
+
if (!peer) {
|
84
100
|
return;
|
85
101
|
}
|
86
|
-
|
102
|
+
|
87
103
|
logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
|
88
104
|
return;
|
89
105
|
}
|
@@ -4,13 +4,13 @@ import { http } from "@/utils";
|
|
4
4
|
import spawn from 'await-spawn';
|
5
5
|
import config from "@/config";
|
6
6
|
import wait from "waait";
|
7
|
+
import packageJson from "../../package.json";
|
7
8
|
|
8
|
-
const
|
9
|
-
|
10
|
-
const currentVersion = getCurrentVersion()
|
9
|
+
const currentVersion = packageJson.version;
|
10
|
+
const tag = config.staging ? 'dev' : 'latest';
|
11
11
|
|
12
12
|
class AutoUpdateTask extends BaseTask {
|
13
|
-
pollIntervalMs: number = 60 *
|
13
|
+
pollIntervalMs: number = 60 * 10 * 1000
|
14
14
|
|
15
15
|
constructor() {
|
16
16
|
super({
|
@@ -22,11 +22,30 @@ class AutoUpdateTask extends BaseTask {
|
|
22
22
|
return config.autoUpdate && !config.isLeadNode();
|
23
23
|
}
|
24
24
|
|
25
|
-
async
|
25
|
+
async getInstalledVersion() {
|
26
|
+
try {
|
27
|
+
const stdout = await spawn('npm', ['-g', 'ls', '--depth=0', '--json'])
|
28
|
+
return JSON.parse(stdout.toString()).dependencies[packageJson.name].version
|
29
|
+
} catch (error) {
|
30
|
+
this.logger.error(error)
|
31
|
+
|
32
|
+
return currentVersion
|
33
|
+
}
|
34
|
+
}
|
26
35
|
|
27
|
-
|
36
|
+
async getLatestVersion() {
|
37
|
+
try {
|
38
|
+
const stdout = await spawn('npm', ['view', `${packageJson.name}@${tag}`, 'version'])
|
39
|
+
return stdout.toString().trim()
|
40
|
+
} catch (error) {
|
41
|
+
this.logger.error(error)
|
42
|
+
|
43
|
+
return currentVersion
|
44
|
+
}
|
45
|
+
}
|
28
46
|
|
29
|
-
|
47
|
+
async pollHandler() {
|
48
|
+
const version = await this.getLatestVersion()
|
30
49
|
|
31
50
|
if (version === currentVersion) {
|
32
51
|
return;
|
@@ -34,13 +53,13 @@ class AutoUpdateTask extends BaseTask {
|
|
34
53
|
|
35
54
|
this.logger.warn(`New version ${version} available.`)
|
36
55
|
|
56
|
+
this.logger.info('Updating...')
|
37
57
|
|
38
|
-
await spawn('npm', ['-g', 'install',
|
39
|
-
|
58
|
+
await spawn('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
40
59
|
|
41
60
|
await wait(5000)
|
42
61
|
|
43
|
-
if (
|
62
|
+
if (version !== await this.getInstalledVersion()) {
|
44
63
|
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
|
45
64
|
return;
|
46
65
|
}
|
package/src/tasks/BaseTask.ts
CHANGED
@@ -46,6 +46,11 @@ export class BaseTask extends EventEmitter implements IBaseTask {
|
|
46
46
|
}
|
47
47
|
|
48
48
|
prePollHandler(): boolean {
|
49
|
+
if(config.isMaintenanceMode()){
|
50
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.')
|
51
|
+
return false
|
52
|
+
}
|
53
|
+
|
49
54
|
if (this.exceptLeadNode) {
|
50
55
|
return !config.isLeadNode();
|
51
56
|
}
|