@instadapp/interop-x 0.0.0-dev.ab1e84b → 0.0.0-dev.adea608

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.ab1e84b",
3
+ "version": "0.0.0-dev.adea608",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -24,7 +24,6 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@achingbrain/libp2p-gossipsub": "^0.12.2",
27
- "await-spawn": "^4.0.2",
28
27
  "axios": "^0.27.1",
29
28
  "axios-retry": "^3.2.4",
30
29
  "bignumber.js": "^9.0.2",
@@ -47,8 +46,6 @@
47
46
  "libp2p-websockets": "^0.16.2",
48
47
  "luxon": "^2.3.2",
49
48
  "module-alias": "^2.2.2",
50
- "patch-package": "^6.4.7",
51
- "postinstall-postinstall": "^2.1.0",
52
49
  "sequelize": "6.18.0",
53
50
  "sqlite3": "^5.0.5",
54
51
  "waait": "^1.0.5"
@@ -63,6 +60,8 @@
63
60
  "@types/fs-extra": "^9.0.13",
64
61
  "@types/node": "^17.0.17",
65
62
  "nodemon": "^2.0.15",
63
+ "patch-package": "^6.4.7",
64
+ "postinstall-postinstall": "^2.1.0",
66
65
  "replace-in-file": "^6.3.2",
67
66
  "rimraf": "^3.0.2",
68
67
  "ts-node": "^10.5.0",
@@ -8,7 +8,6 @@ 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';
12
11
  this.wallet = new ethers_1.Wallet(this.privateKey);
13
12
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
14
13
  }
package/dist/src/index.js CHANGED
@@ -19,43 +19,28 @@ module_alias_1.default.addAliases({
19
19
  "@/typechain": __dirname + "/typechain"
20
20
  });
21
21
  (0, module_alias_1.default)();
22
+ const assert_1 = __importDefault(require("assert"));
22
23
  const dotenv_1 = __importDefault(require("dotenv"));
23
- const chalk_1 = __importDefault(require("chalk"));
24
24
  const ethers_1 = require("ethers");
25
25
  const package_json_1 = __importDefault(require("../package.json"));
26
26
  dotenv_1.default.config();
27
27
  const logger_1 = __importDefault(require("@/logger"));
28
28
  const logger = new logger_1.default('Process');
29
- const printUsage = () => {
29
+ if (process.argv.at(-1) === 'help') {
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');
34
- console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x');
35
- };
36
- if (process.argv.at(-1) === 'help') {
37
- printUsage();
38
33
  process.exit(0);
39
34
  }
40
- const GIT_SHORT_HASH = 'ab1e84b';
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
- }
45
- if (!process.env.PRIVATE_KEY) {
46
- console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
47
- printUsage();
48
- process.exit(1);
49
- }
35
+ (0, assert_1.default)(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
50
36
  try {
51
37
  new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
52
38
  }
53
39
  catch (e) {
54
- console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
55
- printUsage();
40
+ logger.error('Invalid private key');
56
41
  process.exit(1);
57
42
  }
58
- logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
43
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.adea608)`);
59
44
  const tasks_1 = require("@/tasks");
60
45
  const net_1 = require("@/net");
61
46
  const api_1 = require("@/api");
@@ -65,10 +50,8 @@ async function main() {
65
50
  const tasks = new tasks_1.Tasks();
66
51
  tasks.start();
67
52
  (0, api_1.startApiServer)();
68
- net_1.protocol.on('TransactionStatus', async (payload) => {
53
+ net_1.protocol.on('Transaction', async (payload) => {
69
54
  if (!net_1.peerPool.isLeadNode(payload.peerId)) {
70
- const peer = net_1.peerPool.getPeer(payload.peerId);
71
- logger.info(`ignored transaction status from ${payload.peerId} ${peer === null || peer === void 0 ? void 0 : peer.publicAddress} `);
72
55
  return;
73
56
  }
74
57
  const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
@@ -101,9 +101,6 @@ class PeerPool {
101
101
  get activePeerIds() {
102
102
  return this.activePeers.map((p) => p.id);
103
103
  }
104
- getPeer(id) {
105
- return this.pool.get(id);
106
- }
107
104
  isLeadNode(id) {
108
105
  const peer = this.pool.get(id);
109
106
  if (!peer) {
@@ -25,16 +25,16 @@ class Protocol extends stream_1.EventEmitter {
25
25
  }),
26
26
  },
27
27
  {
28
- name: 'TransactionStatus',
28
+ name: 'Transaction',
29
29
  code: 0x02,
30
30
  encode: (transaction) => [
31
31
  Buffer.from(transaction.transactionHash),
32
32
  Buffer.from(transaction.sourceStatus),
33
33
  Buffer.from(transaction.sourceTransactionHash),
34
- transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
34
+ transaction.sourceErrors.map((e) => Buffer.from(e)),
35
35
  Buffer.from(transaction.targetStatus),
36
36
  Buffer.from(transaction.targetTransactionHash),
37
- transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
37
+ transaction.targetErrors.map((e) => Buffer.from(e)),
38
38
  Buffer.from(transaction.status),
39
39
  ],
40
40
  decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
@@ -100,7 +100,7 @@ class Protocol extends stream_1.EventEmitter {
100
100
  this.libp2p.pubsub.publish(this.topic, encoded);
101
101
  }
102
102
  sendTransaction(transaction) {
103
- const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
103
+ const message = this.protocolMessages.find((m) => m.name === 'Transaction');
104
104
  const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
105
105
  this.libp2p.pubsub.publish(this.topic, encoded);
106
106
  }
@@ -8,11 +8,9 @@ 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"));
12
11
  class Tasks {
13
12
  constructor() {
14
13
  this.tasks = [
15
- new AutoUpdateTask_1.default(),
16
14
  new SyncDepositEvents_1.default({
17
15
  chainId: 43114
18
16
  }),
@@ -185,11 +185,6 @@ function getContract(address, contractInterface, signerOrProvider) {
185
185
  throw Error(`Invalid 'address' parameter '${address}'.`);
186
186
  }
187
187
  const contract = new ethers_1.ethers.Contract(address, contractInterface, signerOrProvider);
188
- // Make sure the contract properties is writable
189
- const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
190
- if (!desc || desc.writable !== true) {
191
- return contract;
192
- }
193
188
  return new Proxy(contract, {
194
189
  get(target, prop, receiver) {
195
190
  const value = Reflect.get(target, prop, receiver);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.ab1e84b",
3
+ "version": "0.0.0-dev.adea608",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -24,7 +24,6 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@achingbrain/libp2p-gossipsub": "^0.12.2",
27
- "await-spawn": "^4.0.2",
28
27
  "axios": "^0.27.1",
29
28
  "axios-retry": "^3.2.4",
30
29
  "bignumber.js": "^9.0.2",
@@ -47,8 +46,6 @@
47
46
  "libp2p-websockets": "^0.16.2",
48
47
  "luxon": "^2.3.2",
49
48
  "module-alias": "^2.2.2",
50
- "patch-package": "^6.4.7",
51
- "postinstall-postinstall": "^2.1.0",
52
49
  "sequelize": "6.18.0",
53
50
  "sqlite3": "^5.0.5",
54
51
  "waait": "^1.0.5"
@@ -63,6 +60,8 @@
63
60
  "@types/fs-extra": "^9.0.13",
64
61
  "@types/node": "^17.0.17",
65
62
  "nodemon": "^2.0.15",
63
+ "patch-package": "^6.4.7",
64
+ "postinstall-postinstall": "^2.1.0",
66
65
  "replace-in-file": "^6.3.2",
67
66
  "rimraf": "^3.0.2",
68
67
  "ts-node": "^10.5.0",
@@ -8,14 +8,12 @@ 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
12
11
 
13
12
  constructor() {
14
13
  this.events = new EventBus() as EventBusType
15
14
  this.maxPeers = 10
16
15
  this.privateKey = process.env.PRIVATE_KEY as string;
17
16
  this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
18
- this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
19
17
  this.wallet = new Wallet(this.privateKey);
20
18
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
21
19
  }
package/src/index.ts CHANGED
@@ -16,8 +16,8 @@ moduleAlias.addAliases({
16
16
  })
17
17
 
18
18
  moduleAlias();
19
+ import assert from "assert";
19
20
  import dotenv from "dotenv";
20
- import chalk from 'chalk';
21
21
  import { ethers } from "ethers";
22
22
  import packageJson from '../package.json'
23
23
  dotenv.config();
@@ -25,40 +25,24 @@ dotenv.config();
25
25
  import Logger from "@/logger";
26
26
  const logger = new Logger('Process')
27
27
 
28
- const printUsage = () => {
28
+
29
+ if (process.argv.at(-1) === 'help') {
29
30
  console.log('Usage:')
30
31
  console.log(' PRIVATE_KEY=abcd1234 interop-x')
31
32
  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')
34
- }
35
-
36
- if (process.argv.at(-1) === 'help') {
37
- printUsage()
38
33
  process.exit(0)
39
34
  }
40
35
 
41
- const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
36
+ assert(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
42
37
 
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
- }
47
-
48
- if(! process.env.PRIVATE_KEY) {
49
- console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
50
- printUsage()
51
- process.exit(1)
52
- }
53
38
  try {
54
39
  new ethers.Wallet(process.env.PRIVATE_KEY!)
55
40
  } catch (e) {
56
- console.error(chalk.bgRed.white('Invalid private key\n'))
57
- printUsage()
41
+ logger.error('Invalid private key')
58
42
  process.exit(1)
59
43
  }
60
44
 
61
- logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
45
+ logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.@GIT_SHORT_HASH@)`)
62
46
 
63
47
  import { Tasks } from "@/tasks";
64
48
  import { startPeer, protocol, peerPool } from "@/net";
@@ -75,10 +59,8 @@ async function main() {
75
59
 
76
60
  startApiServer()
77
61
 
78
- protocol.on('TransactionStatus', async (payload) => {
62
+ protocol.on('Transaction', async (payload) => {
79
63
  if (!peerPool.isLeadNode(payload.peerId)) {
80
- const peer = peerPool.getPeer(payload.peerId)
81
- logger.info(`ignored transaction status from ${payload.peerId} ${peer?.publicAddress} `)
82
64
  return;
83
65
  }
84
66
 
@@ -124,10 +124,6 @@ export class PeerPool {
124
124
  }
125
125
 
126
126
 
127
- getPeer(id: string){
128
- return this.pool.get(id);
129
- }
130
-
131
127
  isLeadNode(id: string) {
132
128
  const peer = this.pool.get(id);
133
129
 
@@ -34,12 +34,12 @@ interface PeerInfoEvent extends BaseMessageEvent {
34
34
  data: Omit<IPeerInfo, 'id' | 'updated' | 'idle' | 'pooled'>
35
35
  }
36
36
 
37
- interface TransactionStatusEvent extends BaseMessageEvent {
37
+ interface TransactionEvent extends BaseMessageEvent {
38
38
  data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'>
39
39
  }
40
40
 
41
41
  declare interface Protocol {
42
- on(event: 'TransactionStatus', listener: (payload: TransactionStatusEvent) => void): this;
42
+ on(event: 'Transaction', listener: (payload: TransactionEvent) => void): this;
43
43
  on(event: 'PeerInfo', listener: (payload: PeerInfoEvent) => void): this;
44
44
  on(event: string, listener: (payload: BaseMessageEvent) => void): this;
45
45
  }
@@ -59,18 +59,18 @@ class Protocol extends EventEmitter {
59
59
  }),
60
60
  },
61
61
  {
62
- name: 'TransactionStatus',
62
+ name: 'Transaction',
63
63
  code: 0x02,
64
64
  encode: (transaction: Transaction) => [
65
65
  Buffer.from(transaction.transactionHash),
66
66
 
67
67
  Buffer.from(transaction.sourceStatus),
68
68
  Buffer.from(transaction.sourceTransactionHash),
69
- transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
69
+ transaction.sourceErrors.map((e) => Buffer.from(e)),
70
70
 
71
71
  Buffer.from(transaction.targetStatus),
72
72
  Buffer.from(transaction.targetTransactionHash),
73
- transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
73
+ transaction.targetErrors.map((e) => Buffer.from(e)),
74
74
 
75
75
  Buffer.from(transaction.status),
76
76
  ],
@@ -158,7 +158,7 @@ class Protocol extends EventEmitter {
158
158
  }
159
159
 
160
160
  public sendTransaction(transaction: Transaction) {
161
- const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus')!
161
+ const message = this.protocolMessages.find((m) => m.name === 'Transaction')!
162
162
 
163
163
  const encoded = rlp.encode([message.code, message.encode(transaction)]);
164
164
 
@@ -4,13 +4,10 @@ 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";
8
7
 
9
8
  export class Tasks {
10
9
 
11
10
  tasks: BaseTask[] = [
12
- new AutoUpdateTask(),
13
-
14
11
  new InteropXGatewaySyncDepositEvents({
15
12
  chainId: 43114
16
13
  }),
@@ -259,12 +259,6 @@ export function getContract<TContract extends ethers.Contract>(address: string,
259
259
  signerOrProvider
260
260
  ) as TContract
261
261
 
262
- // Make sure the contract properties is writable
263
- const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
264
-
265
- if (!desc || desc.writable !== true) {
266
- return contract
267
- }
268
262
 
269
263
  return new Proxy(contract, {
270
264
  get(target, prop, receiver) {
@@ -1,44 +0,0 @@
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 await_spawn_1 = __importDefault(require("await-spawn"));
11
- const config_1 = __importDefault(require("@/config"));
12
- const waait_1 = __importDefault(require("waait"));
13
- const currentVersion = package_json_1.default.version;
14
- class AutoUpdateTask extends BaseTask_1.BaseTask {
15
- constructor() {
16
- super({
17
- logger: new logger_1.default("AutoUpdateTask"),
18
- });
19
- this.pollIntervalMs = 60 * 1000;
20
- }
21
- prePollHandler() {
22
- return config_1.default.autoUpdate && !config_1.default.isLeadNode();
23
- }
24
- async pollHandler() {
25
- const { data } = await utils_1.http.get('https://registry.npmjs.org/@instadapp/interop-x');
26
- const version = data['dist-tags'].latest;
27
- if (version === currentVersion) {
28
- return;
29
- }
30
- this.logger.warn(`New version ${version} available.`);
31
- await (0, await_spawn_1.default)('npm', ['-g', 'install', '@instadapp/interop-x']);
32
- this.logger.warn(`Installed version ${version}`);
33
- this.logger.warn(`Restarting...`);
34
- await (0, waait_1.default)(1000);
35
- console.log(process.argv[0], process.argv.slice(1));
36
- (0, await_spawn_1.default)(process.argv[0], process.argv.slice(1), {
37
- cwd: process.cwd(),
38
- detached: true,
39
- stdio: "inherit"
40
- });
41
- process.exit();
42
- }
43
- }
44
- exports.default = AutoUpdateTask;
@@ -1,56 +0,0 @@
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 'await-spawn';
6
- import config from "@/config";
7
- import wait from "waait";
8
- const currentVersion = packageJson.version;
9
-
10
- class AutoUpdateTask extends BaseTask {
11
- pollIntervalMs: number = 60 * 1000
12
-
13
- constructor() {
14
- super({
15
- logger: new Logger("AutoUpdateTask"),
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
- await spawn('npm', ['-g', 'install', '@instadapp/interop-x']);
37
-
38
- this.logger.warn(`Installed version ${version}`)
39
- this.logger.warn(`Restarting...`)
40
-
41
- await wait(1000)
42
-
43
- console.log(process.argv[0], process.argv.slice(1));
44
-
45
-
46
- spawn(process.argv[0], process.argv.slice(1), {
47
- cwd: process.cwd(),
48
- detached: true,
49
- stdio: "inherit"
50
- });
51
-
52
- process.exit()
53
- }
54
- }
55
-
56
- export default AutoUpdateTask;