@instadapp/interop-x 0.0.0-dev.c109c51 → 0.0.0-dev.c2272fd
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 +3 -4
- package/dist/src/config/index.js +0 -1
- package/dist/src/index.js +5 -40
- package/dist/src/net/pool/index.js +0 -11
- package/dist/src/net/protocol/index.js +1 -30
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -2
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -3
- package/dist/src/tasks/index.js +0 -2
- package/dist/src/utils/index.js +0 -5
- package/package.json +3 -4
- package/src/config/index.ts +0 -2
- package/src/index.ts +7 -50
- package/src/net/pool/index.ts +3 -19
- package/src/net/protocol/index.ts +1 -45
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -2
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -4
- package/src/tasks/index.ts +0 -3
- package/src/utils/index.ts +0 -6
- package/dist/src/tasks/AutoUpdateTask.js +0 -41
- package/src/tasks/AutoUpdateTask.ts +0 -50
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.c2272fd",
|
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",
|
package/dist/src/config/index.js
CHANGED
@@ -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,71 +19,36 @@ 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
|
-
|
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
|
-
|
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
|
-
|
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
|
43
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.c2272fd)`);
|
59
44
|
const tasks_1 = require("@/tasks");
|
60
45
|
const net_1 = require("@/net");
|
61
46
|
const api_1 = require("@/api");
|
62
|
-
const db_1 = require("./db");
|
63
47
|
async function main() {
|
64
48
|
(0, net_1.startPeer)({});
|
65
49
|
const tasks = new tasks_1.Tasks();
|
66
50
|
tasks.start();
|
67
51
|
(0, api_1.startApiServer)();
|
68
|
-
net_1.protocol.on('TransactionStatus', async (payload) => {
|
69
|
-
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
|
-
return;
|
73
|
-
}
|
74
|
-
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
75
|
-
if (!transaction) {
|
76
|
-
return;
|
77
|
-
}
|
78
|
-
transaction.sourceStatus = payload.data.sourceStatus;
|
79
|
-
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
80
|
-
transaction.sourceErrors = payload.data.sourceErrors;
|
81
|
-
transaction.targetStatus = payload.data.targetStatus;
|
82
|
-
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
83
|
-
transaction.targetErrors = payload.data.targetErrors;
|
84
|
-
transaction.status = payload.data.status;
|
85
|
-
await transaction.save();
|
86
|
-
});
|
87
52
|
}
|
88
53
|
main()
|
89
54
|
.then(() => {
|
@@ -7,7 +7,6 @@ exports.peerPool = exports.PeerPool = void 0;
|
|
7
7
|
const types_1 = require("@/types");
|
8
8
|
const config_1 = __importDefault(require("@/config"));
|
9
9
|
const logger_1 = __importDefault(require("@/logger"));
|
10
|
-
const utils_1 = require("ethers/lib/utils");
|
11
10
|
const logger = new logger_1.default('PeerPool');
|
12
11
|
class PeerPool {
|
13
12
|
constructor() {
|
@@ -101,16 +100,6 @@ class PeerPool {
|
|
101
100
|
get activePeerIds() {
|
102
101
|
return this.activePeers.map((p) => p.id);
|
103
102
|
}
|
104
|
-
getPeer(id) {
|
105
|
-
return this.pool.get(id);
|
106
|
-
}
|
107
|
-
isLeadNode(id) {
|
108
|
-
const peer = this.pool.get(id);
|
109
|
-
if (!peer) {
|
110
|
-
return false;
|
111
|
-
}
|
112
|
-
return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
|
113
|
-
}
|
114
103
|
cleanup() {
|
115
104
|
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
116
105
|
// this.peers.forEach((peerInfo) => {
|
@@ -16,7 +16,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
16
16
|
this.protocolMessages = [
|
17
17
|
{
|
18
18
|
name: 'PeerInfo',
|
19
|
-
code:
|
19
|
+
code: 0x09,
|
20
20
|
encode: (info) => [
|
21
21
|
Buffer.from(info.publicAddress),
|
22
22
|
],
|
@@ -24,30 +24,6 @@ class Protocol extends stream_1.EventEmitter {
|
|
24
24
|
publicAddress: publicAddress.toString(),
|
25
25
|
}),
|
26
26
|
},
|
27
|
-
{
|
28
|
-
name: 'TransactionStatus',
|
29
|
-
code: 0x02,
|
30
|
-
encode: (transaction) => [
|
31
|
-
Buffer.from(transaction.transactionHash),
|
32
|
-
Buffer.from(transaction.sourceStatus),
|
33
|
-
Buffer.from(transaction.sourceTransactionHash),
|
34
|
-
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
35
|
-
Buffer.from(transaction.targetStatus),
|
36
|
-
Buffer.from(transaction.targetTransactionHash),
|
37
|
-
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
38
|
-
Buffer.from(transaction.status),
|
39
|
-
],
|
40
|
-
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
|
41
|
-
transactionHash: transactionHash.toString(),
|
42
|
-
sourceStatus: sourceStatus.toString(),
|
43
|
-
sourceTransactionHash: sourceTransactionHash.toString(),
|
44
|
-
sourceErrors: sourceErrors.map((e) => e.toString()),
|
45
|
-
targetStatus: targetStatus.toString(),
|
46
|
-
targetTransactionHash: targetTransactionHash.toString(),
|
47
|
-
targetErrors: targetErrors.map((e) => e.toString()),
|
48
|
-
status: status.toString(),
|
49
|
-
}),
|
50
|
-
},
|
51
27
|
];
|
52
28
|
}
|
53
29
|
start({ libp2p, topic = null, }) {
|
@@ -99,11 +75,6 @@ class Protocol extends stream_1.EventEmitter {
|
|
99
75
|
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
|
100
76
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
101
77
|
}
|
102
|
-
sendTransaction(transaction) {
|
103
|
-
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
|
104
|
-
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
|
105
|
-
this.libp2p.pubsub.publish(this.topic, encoded);
|
106
|
-
}
|
107
78
|
async requestSignatures(data, peerIds) {
|
108
79
|
try {
|
109
80
|
peerIds = peerIds || __1.peerPool.activePeerIds;
|
@@ -126,14 +126,12 @@ class ProcessWithdrawEvents extends BaseTask_1.BaseTask {
|
|
126
126
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
127
127
|
console.log('ExecutionSuccess');
|
128
128
|
transaction.targetStatus = 'success';
|
129
|
-
transaction.targetTransactionHash = txSent.hash;
|
130
129
|
transaction.status = 'success';
|
131
130
|
await transaction.save();
|
132
131
|
}
|
133
132
|
else {
|
134
133
|
console.log('ExecutionFailure');
|
135
134
|
transaction.targetStatus = 'failed';
|
136
|
-
transaction.targetTransactionHash = txSent.hash;
|
137
135
|
transaction.status = 'failed';
|
138
136
|
await transaction.save();
|
139
137
|
}
|
@@ -126,18 +126,15 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
|
|
126
126
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
127
127
|
console.log('ExecutionSuccess');
|
128
128
|
transaction.targetStatus = 'success';
|
129
|
-
transaction.targetTransactionHash = txSent.hash;
|
130
129
|
transaction.status = 'success';
|
131
130
|
await transaction.save();
|
132
131
|
}
|
133
132
|
else {
|
134
133
|
console.log('ExecutionFailure');
|
135
134
|
transaction.targetStatus = 'failed';
|
136
|
-
transaction.targetTransactionHash = txSent.hash;
|
137
135
|
transaction.status = 'failed';
|
138
136
|
await transaction.save();
|
139
137
|
}
|
140
|
-
net_1.protocol.sendTransaction(transaction);
|
141
138
|
}
|
142
139
|
async start() {
|
143
140
|
this.logger.info(`Starting execution watcher on interop chain`);
|
package/dist/src/tasks/index.js
CHANGED
@@ -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
|
}),
|
package/dist/src/utils/index.js
CHANGED
@@ -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.
|
3
|
+
"version": "0.0.0-dev.c2272fd",
|
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",
|
package/src/config/index.ts
CHANGED
@@ -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,45 +25,28 @@ dotenv.config();
|
|
25
25
|
import Logger from "@/logger";
|
26
26
|
const logger = new Logger('Process')
|
27
27
|
|
28
|
-
|
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
|
-
|
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
|
-
|
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
|
45
|
+
logger.debug(`Starting Interop X Node (v${packageJson.version} - rev.@GIT_SHORT_HASH@)`)
|
62
46
|
|
63
47
|
import { Tasks } from "@/tasks";
|
64
|
-
import { startPeer
|
48
|
+
import { startPeer } from "@/net";
|
65
49
|
import { startApiServer } from '@/api';
|
66
|
-
import { Transaction } from './db';
|
67
50
|
|
68
51
|
async function main() {
|
69
52
|
|
@@ -74,32 +57,6 @@ async function main() {
|
|
74
57
|
tasks.start();
|
75
58
|
|
76
59
|
startApiServer()
|
77
|
-
|
78
|
-
protocol.on('TransactionStatus', async (payload) => {
|
79
|
-
if (!peerPool.isLeadNode(payload.peerId)) {
|
80
|
-
const peer = peerPool.getPeer(payload.peerId)
|
81
|
-
logger.info(`ignored transaction status from ${payload.peerId} ${peer?.publicAddress} `)
|
82
|
-
return;
|
83
|
-
}
|
84
|
-
|
85
|
-
const transaction = await Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } })
|
86
|
-
|
87
|
-
if (!transaction) {
|
88
|
-
return;
|
89
|
-
}
|
90
|
-
|
91
|
-
transaction.sourceStatus = payload.data.sourceStatus
|
92
|
-
transaction.sourceTransactionHash = payload.data.sourceTransactionHash
|
93
|
-
transaction.sourceErrors = payload.data.sourceErrors
|
94
|
-
|
95
|
-
transaction.targetStatus = payload.data.targetStatus
|
96
|
-
transaction.targetTransactionHash = payload.data.targetTransactionHash
|
97
|
-
transaction.targetErrors = payload.data.targetErrors
|
98
|
-
|
99
|
-
transaction.status = payload.data.status
|
100
|
-
|
101
|
-
await transaction.save()
|
102
|
-
})
|
103
60
|
}
|
104
61
|
|
105
62
|
main()
|
package/src/net/pool/index.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { Event } from "@/types";
|
2
2
|
import config from "@/config";
|
3
3
|
import Logger from "@/logger";
|
4
|
-
import { getAddress } from "ethers/lib/utils";
|
5
4
|
|
6
5
|
|
7
6
|
const logger = new Logger('PeerPool')
|
@@ -84,8 +83,8 @@ export class PeerPool {
|
|
84
83
|
const newPeer = !this.pool.get(peer.id);
|
85
84
|
this.pool.set(peer.id, peer)
|
86
85
|
peer.pooled = true
|
87
|
-
|
88
|
-
if
|
86
|
+
|
87
|
+
if(newPeer) {
|
89
88
|
config.events.emit(Event.POOL_PEER_ADDED, peer)
|
90
89
|
logger.info(`Peer ${peer.id} with address ${peer.publicAddress} added to pool`)
|
91
90
|
}
|
@@ -111,7 +110,7 @@ export class PeerPool {
|
|
111
110
|
this.cleanup()
|
112
111
|
|
113
112
|
return this.peers.filter((p) => {
|
114
|
-
if
|
113
|
+
if(!p.pooled) return false;
|
115
114
|
|
116
115
|
const now = new Date()
|
117
116
|
|
@@ -124,21 +123,6 @@ export class PeerPool {
|
|
124
123
|
}
|
125
124
|
|
126
125
|
|
127
|
-
getPeer(id: string){
|
128
|
-
return this.pool.get(id);
|
129
|
-
}
|
130
|
-
|
131
|
-
isLeadNode(id: string) {
|
132
|
-
const peer = this.pool.get(id);
|
133
|
-
|
134
|
-
if (!peer) {
|
135
|
-
return false;
|
136
|
-
}
|
137
|
-
|
138
|
-
return getAddress(peer.publicAddress) === getAddress(config.leadNodeAddress)
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
126
|
cleanup() {
|
143
127
|
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
144
128
|
|
@@ -5,7 +5,6 @@ import { SignatureDialProtocol, ISignatureRequest, ISignatureResponse } from "./
|
|
5
5
|
import { IPeerInfo, peerPool } from "..";
|
6
6
|
import config from "@/config";
|
7
7
|
import { Event } from "@/types";
|
8
|
-
import { Transaction } from "@/db";
|
9
8
|
|
10
9
|
export interface ProtocolOptions {
|
11
10
|
/* Handshake timeout in ms (default: 8000) */
|
@@ -34,12 +33,7 @@ interface PeerInfoEvent extends BaseMessageEvent {
|
|
34
33
|
data: Omit<IPeerInfo, 'id' | 'updated' | 'idle' | 'pooled'>
|
35
34
|
}
|
36
35
|
|
37
|
-
interface TransactionStatusEvent extends BaseMessageEvent {
|
38
|
-
data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'>
|
39
|
-
}
|
40
|
-
|
41
36
|
declare interface Protocol {
|
42
|
-
on(event: 'TransactionStatus', listener: (payload: TransactionStatusEvent) => void): this;
|
43
37
|
on(event: 'PeerInfo', listener: (payload: PeerInfoEvent) => void): this;
|
44
38
|
on(event: string, listener: (payload: BaseMessageEvent) => void): this;
|
45
39
|
}
|
@@ -50,7 +44,7 @@ class Protocol extends EventEmitter {
|
|
50
44
|
private protocolMessages: Message[] = [
|
51
45
|
{
|
52
46
|
name: 'PeerInfo',
|
53
|
-
code:
|
47
|
+
code: 0x09,
|
54
48
|
encode: (info: Pick<IPeerInfo, 'publicAddress'>) => [
|
55
49
|
Buffer.from(info.publicAddress),
|
56
50
|
],
|
@@ -58,36 +52,6 @@ class Protocol extends EventEmitter {
|
|
58
52
|
publicAddress: publicAddress.toString(),
|
59
53
|
}),
|
60
54
|
},
|
61
|
-
{
|
62
|
-
name: 'TransactionStatus',
|
63
|
-
code: 0x02,
|
64
|
-
encode: (transaction: Transaction) => [
|
65
|
-
Buffer.from(transaction.transactionHash),
|
66
|
-
|
67
|
-
Buffer.from(transaction.sourceStatus),
|
68
|
-
Buffer.from(transaction.sourceTransactionHash),
|
69
|
-
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
70
|
-
|
71
|
-
Buffer.from(transaction.targetStatus),
|
72
|
-
Buffer.from(transaction.targetTransactionHash),
|
73
|
-
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
74
|
-
|
75
|
-
Buffer.from(transaction.status),
|
76
|
-
],
|
77
|
-
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]: [Buffer, Buffer, Buffer, Buffer[], Buffer, Buffer, Buffer[], Buffer]) => ({
|
78
|
-
transactionHash: transactionHash.toString(),
|
79
|
-
|
80
|
-
sourceStatus: sourceStatus.toString(),
|
81
|
-
sourceTransactionHash: sourceTransactionHash.toString(),
|
82
|
-
sourceErrors: sourceErrors.map((e) => e.toString()),
|
83
|
-
|
84
|
-
targetStatus: targetStatus.toString(),
|
85
|
-
targetTransactionHash: targetTransactionHash.toString(),
|
86
|
-
targetErrors: targetErrors.map((e) => e.toString()),
|
87
|
-
|
88
|
-
status: status.toString(),
|
89
|
-
}),
|
90
|
-
},
|
91
55
|
];
|
92
56
|
private signature: SignatureDialProtocol;
|
93
57
|
|
@@ -157,14 +121,6 @@ class Protocol extends EventEmitter {
|
|
157
121
|
this.libp2p.pubsub.publish(this.topic, encoded)
|
158
122
|
}
|
159
123
|
|
160
|
-
public sendTransaction(transaction: Transaction) {
|
161
|
-
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus')!
|
162
|
-
|
163
|
-
const encoded = rlp.encode([message.code, message.encode(transaction)]);
|
164
|
-
|
165
|
-
this.libp2p.pubsub.publish(this.topic, encoded)
|
166
|
-
}
|
167
|
-
|
168
124
|
async requestSignatures(data: ISignatureRequest, peerIds?: string[]) {
|
169
125
|
try {
|
170
126
|
peerIds = peerIds || peerPool.activePeerIds;
|
@@ -207,13 +207,11 @@ class ProcessWithdrawEvents extends BaseTask {
|
|
207
207
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
208
208
|
console.log('ExecutionSuccess')
|
209
209
|
transaction.targetStatus = 'success'
|
210
|
-
transaction.targetTransactionHash = txSent.hash
|
211
210
|
transaction.status = 'success'
|
212
211
|
await transaction.save();
|
213
212
|
} else {
|
214
213
|
console.log('ExecutionFailure')
|
215
214
|
transaction.targetStatus = 'failed'
|
216
|
-
transaction.targetTransactionHash = txSent.hash
|
217
215
|
transaction.status = 'failed'
|
218
216
|
await transaction.save();
|
219
217
|
}
|
@@ -209,18 +209,14 @@ class ProcessDepositEvents extends BaseTask {
|
|
209
209
|
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
210
210
|
console.log('ExecutionSuccess')
|
211
211
|
transaction.targetStatus = 'success'
|
212
|
-
transaction.targetTransactionHash = txSent.hash
|
213
212
|
transaction.status = 'success'
|
214
213
|
await transaction.save();
|
215
214
|
} else {
|
216
215
|
console.log('ExecutionFailure')
|
217
216
|
transaction.targetStatus = 'failed'
|
218
|
-
transaction.targetTransactionHash = txSent.hash
|
219
217
|
transaction.status = 'failed'
|
220
218
|
await transaction.save();
|
221
219
|
}
|
222
|
-
|
223
|
-
protocol.sendTransaction(transaction)
|
224
220
|
}
|
225
221
|
|
226
222
|
async start(): Promise<void> {
|
package/src/tasks/index.ts
CHANGED
@@ -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
|
}),
|
package/src/utils/index.ts
CHANGED
@@ -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,41 +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 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
|
-
await (0, await_spawn_1.default)('npm', ['-g', 'install', '@instadapp/interop-x']);
|
31
|
-
this.logger.warn(`Installed version ${version}`);
|
32
|
-
this.logger.warn(`Restarting...`);
|
33
|
-
(0, await_spawn_1.default)(process.argv[0], process.argv.slice(1), {
|
34
|
-
cwd: process.cwd(),
|
35
|
-
detached: true,
|
36
|
-
stdio: "inherit"
|
37
|
-
});
|
38
|
-
process.exit();
|
39
|
-
}
|
40
|
-
}
|
41
|
-
exports.default = AutoUpdateTask;
|
@@ -1,50 +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
|
-
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
|
-
prePollHandler(): boolean {
|
19
|
-
return config.autoUpdate && !config.isLeadNode();
|
20
|
-
}
|
21
|
-
|
22
|
-
async pollHandler() {
|
23
|
-
|
24
|
-
const { data } = await http.get('https://registry.npmjs.org/@instadapp/interop-x')
|
25
|
-
|
26
|
-
const version = data['dist-tags'].latest
|
27
|
-
|
28
|
-
if (version === currentVersion) {
|
29
|
-
return;
|
30
|
-
}
|
31
|
-
|
32
|
-
this.logger.warn(`New version ${version} available.`)
|
33
|
-
|
34
|
-
|
35
|
-
await spawn('npm', ['-g', 'install', '@instadapp/interop-x']);
|
36
|
-
|
37
|
-
this.logger.warn(`Installed version ${version}`)
|
38
|
-
this.logger.warn(`Restarting...`)
|
39
|
-
|
40
|
-
spawn(process.argv[0], process.argv.slice(1), {
|
41
|
-
cwd: process.cwd(),
|
42
|
-
detached: true,
|
43
|
-
stdio: "inherit"
|
44
|
-
});
|
45
|
-
|
46
|
-
process.exit()
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
export default AutoUpdateTask;
|