@instadapp/interop-x 0.0.0-dev.a775e30 → 0.0.0-dev.a846f65
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.
- package/dist/package.json +1 -2
- package/dist/src/config/index.js +1 -10
- package/dist/src/index.js +5 -28
- package/dist/src/tasks/AutoUpdateTask.js +8 -11
- package/dist/src/tasks/BaseTask.js +0 -4
- package/package.json +1 -2
- package/src/config/index.ts +1 -9
- package/src/index.ts +9 -41
- package/src/tasks/AutoUpdateTask.ts +14 -15
- package/src/tasks/BaseTask.ts +0 -5
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.a846f65",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -35,7 +35,6 @@
|
|
35
35
|
"ethers-multisend": "^2.1.1",
|
36
36
|
"expand-home-dir": "^0.0.3",
|
37
37
|
"fastify": "^3.28.0",
|
38
|
-
"fs-extra": "^10.1.0",
|
39
38
|
"libp2p": "^0.36.2",
|
40
39
|
"libp2p-bootstrap": "^0.14.0",
|
41
40
|
"libp2p-kad-dht": "^0.28.6",
|
package/dist/src/config/index.js
CHANGED
@@ -1,22 +1,16 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
3
|
const ethers_1 = require("ethers");
|
7
4
|
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"));
|
10
5
|
class Config {
|
11
6
|
constructor() {
|
12
7
|
this.events = new types_1.EventBus();
|
13
|
-
this.maxPeers =
|
8
|
+
this.maxPeers = 10;
|
14
9
|
this.privateKey = process.env.PRIVATE_KEY;
|
15
10
|
this.staging = !!process.env.STAGING && process.env.STAGING === 'true';
|
16
11
|
this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
17
12
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
18
13
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
19
|
-
this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
20
14
|
}
|
21
15
|
get publicAddress() {
|
22
16
|
return this.wallet.address;
|
@@ -24,8 +18,5 @@ class Config {
|
|
24
18
|
isLeadNode() {
|
25
19
|
return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
|
26
20
|
}
|
27
|
-
isMaintenanceMode() {
|
28
|
-
return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
|
29
|
-
}
|
30
21
|
}
|
31
22
|
exports.default = new Config();
|
package/dist/src/index.js
CHANGED
@@ -4,8 +4,6 @@ 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"));
|
9
7
|
module_alias_1.default.addAliases({
|
10
8
|
"@/": __dirname + "/",
|
11
9
|
"@/logger": __dirname + "/logger",
|
@@ -28,39 +26,18 @@ const package_json_1 = __importDefault(require("../package.json"));
|
|
28
26
|
dotenv_1.default.config();
|
29
27
|
const logger_1 = __importDefault(require("@/logger"));
|
30
28
|
const logger = new logger_1.default('Process');
|
31
|
-
const GIT_SHORT_HASH = 'a775e30';
|
32
29
|
const printUsage = () => {
|
33
|
-
console.log();
|
34
|
-
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
35
|
-
console.log();
|
36
30
|
console.log('Usage:');
|
37
|
-
console.log(' interop-x
|
38
|
-
console.log(' interop-x
|
39
|
-
console.log();
|
40
|
-
console.log(' interop-x
|
41
|
-
console.log(' interop-x up Take the node out of maintenance mode');
|
42
|
-
console.log();
|
43
|
-
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
|
44
|
-
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
|
45
|
-
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
|
46
|
-
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port');
|
47
|
-
console.log();
|
31
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x');
|
32
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x');
|
33
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x');
|
34
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x');
|
48
35
|
};
|
49
36
|
if (process.argv.at(-1) === 'help') {
|
50
37
|
printUsage();
|
51
38
|
process.exit(0);
|
52
39
|
}
|
53
|
-
const
|
54
|
-
if (process.argv.at(-1) === 'down') {
|
55
|
-
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
56
|
-
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
57
|
-
process.exit(0);
|
58
|
-
}
|
59
|
-
if (process.argv.at(-1) === 'up') {
|
60
|
-
fs_extra_1.default.removeSync(basePath + '/maintenance');
|
61
|
-
console.log(chalk_1.default.green('Maintenance mode disabled'));
|
62
|
-
process.exit(0);
|
63
|
-
}
|
40
|
+
const GIT_SHORT_HASH = 'a846f65';
|
64
41
|
if (process.argv.at(-1) === 'version') {
|
65
42
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
66
43
|
process.exit(0);
|
@@ -6,18 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const BaseTask_1 = require("./BaseTask");
|
7
7
|
const logger_1 = __importDefault(require("@/logger"));
|
8
8
|
const await_spawn_1 = __importDefault(require("await-spawn"));
|
9
|
-
const child_process_1 = require("child_process");
|
10
9
|
const config_1 = __importDefault(require("@/config"));
|
11
10
|
const waait_1 = __importDefault(require("waait"));
|
12
11
|
const package_json_1 = __importDefault(require("../../package.json"));
|
13
12
|
const currentVersion = package_json_1.default.version;
|
14
|
-
const tag = config_1.default.staging ? 'dev' : 'latest';
|
15
13
|
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
16
14
|
constructor() {
|
17
15
|
super({
|
18
16
|
logger: new logger_1.default("AutoUpdateTask"),
|
19
17
|
});
|
20
|
-
this.pollIntervalMs = 60 *
|
18
|
+
this.pollIntervalMs = 60 * 5 * 1000;
|
21
19
|
}
|
22
20
|
prePollHandler() {
|
23
21
|
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
@@ -34,8 +32,8 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
34
32
|
}
|
35
33
|
async getLatestVersion() {
|
36
34
|
try {
|
37
|
-
const stdout = await (0, await_spawn_1.default)('npm', ['view',
|
38
|
-
return stdout.toString()
|
35
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', package_json_1.default.name, 'version']);
|
36
|
+
return stdout.toString();
|
39
37
|
}
|
40
38
|
catch (error) {
|
41
39
|
this.logger.error(error);
|
@@ -49,7 +47,9 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
49
47
|
}
|
50
48
|
this.logger.warn(`New version ${version} available.`);
|
51
49
|
this.logger.info('Updating...');
|
52
|
-
|
50
|
+
const spawner = (0, await_spawn_1.default)('npm', ['-g', 'install', '@instadapp/interop-x@latest']);
|
51
|
+
spawner.child.on('data', console.log);
|
52
|
+
await spawner;
|
53
53
|
await (0, waait_1.default)(5000);
|
54
54
|
if (version !== await this.getInstalledVersion()) {
|
55
55
|
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
@@ -57,13 +57,10 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
57
57
|
}
|
58
58
|
this.logger.warn(`Installed version ${version}`);
|
59
59
|
this.logger.warn(`Restarting...`);
|
60
|
-
|
61
|
-
const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
|
60
|
+
(0, await_spawn_1.default)(process.argv[0], process.argv.slice(1), {
|
62
61
|
cwd: process.cwd(),
|
63
|
-
stdio: "inherit"
|
64
|
-
// shell: process.env.SHELL,
|
62
|
+
stdio: "inherit"
|
65
63
|
});
|
66
|
-
subprocess.unref();
|
67
64
|
process.exit();
|
68
65
|
}
|
69
66
|
}
|
@@ -35,10 +35,6 @@ 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
|
-
}
|
42
38
|
if (this.exceptLeadNode) {
|
43
39
|
return !config_1.default.isLeadNode();
|
44
40
|
}
|
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.a846f65",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -35,7 +35,6 @@
|
|
35
35
|
"ethers-multisend": "^2.1.1",
|
36
36
|
"expand-home-dir": "^0.0.3",
|
37
37
|
"fastify": "^3.28.0",
|
38
|
-
"fs-extra": "^10.1.0",
|
39
38
|
"libp2p": "^0.36.2",
|
40
39
|
"libp2p-bootstrap": "^0.14.0",
|
41
40
|
"libp2p-kad-dht": "^0.28.6",
|
package/src/config/index.ts
CHANGED
@@ -1,7 +1,5 @@
|
|
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";
|
5
3
|
|
6
4
|
class Config {
|
7
5
|
public readonly events: EventBusType
|
@@ -11,17 +9,15 @@ class Config {
|
|
11
9
|
public readonly wallet: Wallet
|
12
10
|
public readonly staging: boolean
|
13
11
|
public readonly autoUpdate: boolean
|
14
|
-
public readonly baseConfigPath: string
|
15
12
|
|
16
13
|
constructor() {
|
17
14
|
this.events = new EventBus() as EventBusType
|
18
|
-
this.maxPeers =
|
15
|
+
this.maxPeers = 10
|
19
16
|
this.privateKey = process.env.PRIVATE_KEY as string;
|
20
17
|
this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
|
21
18
|
this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
22
19
|
this.wallet = new Wallet(this.privateKey);
|
23
20
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
|
24
|
-
this.baseConfigPath = expandHomeDir(`~/.interop-x`);
|
25
21
|
}
|
26
22
|
|
27
23
|
get publicAddress(){
|
@@ -31,10 +27,6 @@ class Config {
|
|
31
27
|
isLeadNode() {
|
32
28
|
return ethers.utils.getAddress(this.leadNodeAddress) === ethers.utils.getAddress(this.wallet.address)
|
33
29
|
}
|
34
|
-
|
35
|
-
isMaintenanceMode(){
|
36
|
-
return fs.existsSync(this.baseConfigPath + '/maintenance')
|
37
|
-
}
|
38
30
|
}
|
39
31
|
|
40
32
|
export default new Config()
|
package/src/index.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import moduleAlias from 'module-alias';
|
2
|
-
|
3
|
-
import fs from 'fs-extra'
|
2
|
+
|
4
3
|
moduleAlias.addAliases({
|
5
4
|
"@/": __dirname + "/",
|
6
5
|
"@/logger": __dirname + "/logger",
|
@@ -26,30 +25,12 @@ dotenv.config();
|
|
26
25
|
import Logger from "@/logger";
|
27
26
|
const logger = new Logger('Process')
|
28
27
|
|
29
|
-
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
30
|
-
|
31
28
|
const printUsage = () => {
|
32
|
-
console.log()
|
33
|
-
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
34
|
-
console.log()
|
35
|
-
|
36
29
|
console.log('Usage:')
|
37
|
-
console.log(' interop-x
|
38
|
-
console.log(' interop-x
|
39
|
-
|
40
|
-
console.log()
|
41
|
-
|
42
|
-
console.log(' interop-x down Put the node into maintenance mode')
|
43
|
-
console.log(' interop-x up Take the node out of maintenance mode')
|
44
|
-
|
45
|
-
console.log()
|
46
|
-
|
47
|
-
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key')
|
48
|
-
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode')
|
49
|
-
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode')
|
50
|
-
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port')
|
51
|
-
console.log()
|
52
|
-
|
30
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x')
|
31
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x')
|
32
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x')
|
33
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x')
|
53
34
|
}
|
54
35
|
|
55
36
|
if (process.argv.at(-1) === 'help') {
|
@@ -57,27 +38,14 @@ if (process.argv.at(-1) === 'help') {
|
|
57
38
|
process.exit(0)
|
58
39
|
}
|
59
40
|
|
60
|
-
const
|
61
|
-
|
62
|
-
if (process.argv.at(-1) === 'down') {
|
63
|
-
fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
|
64
|
-
console.log(chalk.red('Maintenance mode enabled'))
|
65
|
-
process.exit(0)
|
66
|
-
}
|
67
|
-
|
68
|
-
if (process.argv.at(-1) === 'up') {
|
69
|
-
fs.removeSync(basePath + '/maintenance')
|
70
|
-
console.log(chalk.green('Maintenance mode disabled'))
|
71
|
-
process.exit(0)
|
72
|
-
}
|
73
|
-
|
41
|
+
const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
|
74
42
|
|
75
43
|
if (process.argv.at(-1) === 'version') {
|
76
44
|
console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
|
77
45
|
process.exit(0)
|
78
46
|
}
|
79
47
|
|
80
|
-
if
|
48
|
+
if(! process.env.PRIVATE_KEY) {
|
81
49
|
console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
|
82
50
|
printUsage()
|
83
51
|
process.exit(1)
|
@@ -112,10 +80,10 @@ async function main() {
|
|
112
80
|
if (!peerPool.isLeadNode(payload.peerId)) {
|
113
81
|
const peer = peerPool.getPeer(payload.peerId)
|
114
82
|
|
115
|
-
if
|
83
|
+
if(! peer) {
|
116
84
|
return;
|
117
85
|
}
|
118
|
-
|
86
|
+
|
119
87
|
logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
|
120
88
|
return;
|
121
89
|
}
|
@@ -1,16 +1,15 @@
|
|
1
1
|
import { BaseTask } from "./BaseTask";
|
2
2
|
import Logger from '@/logger';
|
3
|
-
import
|
4
|
-
import
|
3
|
+
import { http } from "@/utils";
|
4
|
+
import spawn from 'await-spawn';
|
5
5
|
import config from "@/config";
|
6
6
|
import wait from "waait";
|
7
7
|
import packageJson from "../../package.json";
|
8
8
|
|
9
9
|
const currentVersion = packageJson.version;
|
10
|
-
const tag = config.staging ? 'dev' : 'latest';
|
11
10
|
|
12
11
|
class AutoUpdateTask extends BaseTask {
|
13
|
-
pollIntervalMs: number = 60 *
|
12
|
+
pollIntervalMs: number = 60 * 5 * 1000
|
14
13
|
|
15
14
|
constructor() {
|
16
15
|
super({
|
@@ -24,20 +23,22 @@ class AutoUpdateTask extends BaseTask {
|
|
24
23
|
|
25
24
|
async getInstalledVersion() {
|
26
25
|
try {
|
27
|
-
const stdout = await
|
26
|
+
const stdout = await spawn('npm', ['-g', 'ls', '--depth=0', '--json'])
|
28
27
|
return JSON.parse(stdout.toString()).dependencies[packageJson.name].version
|
29
28
|
} catch (error) {
|
30
29
|
this.logger.error(error)
|
30
|
+
|
31
31
|
return currentVersion
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
35
35
|
async getLatestVersion() {
|
36
36
|
try {
|
37
|
-
const stdout = await
|
38
|
-
return stdout.toString()
|
37
|
+
const stdout = await spawn('npm', ['view', packageJson.name, 'version'])
|
38
|
+
return stdout.toString()
|
39
39
|
} catch (error) {
|
40
40
|
this.logger.error(error)
|
41
|
+
|
41
42
|
return currentVersion
|
42
43
|
}
|
43
44
|
}
|
@@ -51,9 +52,12 @@ class AutoUpdateTask extends BaseTask {
|
|
51
52
|
|
52
53
|
this.logger.warn(`New version ${version} available.`)
|
53
54
|
|
55
|
+
|
54
56
|
this.logger.info('Updating...')
|
55
57
|
|
56
|
-
|
58
|
+
const spawner = spawn('npm', ['-g', 'install', '@instadapp/interop-x@latest']);
|
59
|
+
spawner.child.on('data', console.log)
|
60
|
+
await spawner
|
57
61
|
|
58
62
|
await wait(5000)
|
59
63
|
|
@@ -65,16 +69,11 @@ class AutoUpdateTask extends BaseTask {
|
|
65
69
|
this.logger.warn(`Installed version ${version}`)
|
66
70
|
this.logger.warn(`Restarting...`)
|
67
71
|
|
68
|
-
|
69
|
-
// TODO: its restarting in the bg, but it should be in the fg
|
70
|
-
const subprocess = spawn(process.argv[0], process.argv.slice(1), {
|
72
|
+
spawn(process.argv[0], process.argv.slice(1), {
|
71
73
|
cwd: process.cwd(),
|
72
|
-
stdio: "inherit"
|
73
|
-
// shell: process.env.SHELL,
|
74
|
+
stdio: "inherit"
|
74
75
|
});
|
75
76
|
|
76
|
-
subprocess.unref();
|
77
|
-
|
78
77
|
process.exit()
|
79
78
|
}
|
80
79
|
}
|
package/src/tasks/BaseTask.ts
CHANGED
@@ -46,11 +46,6 @@ 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
|
-
|
54
49
|
if (this.exceptLeadNode) {
|
55
50
|
return !config.isLeadNode();
|
56
51
|
}
|