@instadapp/interop-x 0.0.0-dev.1abc1ca → 0.0.0-dev.2c0a756
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/bin/interop-x +1 -1
- package/dist/package.json +9 -5
- package/dist/src/abi/interopBridgeToken.json +21 -9
- package/dist/src/abi/interopXGateway.json +11 -11
- package/dist/src/api/index.js +3 -3
- package/dist/src/config/index.js +11 -1
- package/dist/src/constants/addresses.js +1 -1
- package/dist/src/constants/itokens.js +1 -1
- package/dist/src/index.js +69 -7
- package/dist/src/net/peer/index.js +8 -3
- package/dist/src/net/pool/index.js +32 -9
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +11 -4
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/src/net/protocol/index.js +41 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/src/tasks/BaseTask.js +12 -4
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +146 -0
- package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +71 -0
- package/dist/src/tasks/InteropBridge/SyncMintEvents.js +66 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +45 -23
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +6 -7
- package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +71 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +29 -0
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +23 -11
- package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
- package/dist/src/utils/index.js +111 -10
- package/package.json +9 -5
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/interopBridgeToken.json +21 -9
- package/src/abi/interopXGateway.json +11 -11
- package/src/api/index.ts +2 -2
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/itokens.ts +1 -1
- package/src/index.ts +90 -9
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +12 -4
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +57 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +14 -4
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +231 -0
- package/src/tasks/InteropBridge/SyncBurnEvents.ts +121 -0
- package/src/tasks/InteropBridge/SyncMintEvents.ts +98 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +57 -32
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +8 -10
- package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +103 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +44 -2
- package/src/typechain/InteropBridgeToken.ts +23 -17
- package/src/typechain/InteropXGateway.ts +13 -13
- package/src/typechain/factories/InteropBridgeToken__factory.ts +23 -11
- package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
- package/src/utils/index.ts +146 -12
package/bin/interop-x
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
require('../dist/index')
|
2
|
+
require('../dist/src/index')
|
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.2c0a756",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -12,7 +12,8 @@
|
|
12
12
|
"build": "yarn generate-abi-types && export GIT_REF=$(git rev-parse --short HEAD) && rimraf ./dist && tsc -p tsconfig.json && replace-in-file '@GIT_SHORT_HASH@' $GIT_REF ./dist/**/*.js",
|
13
13
|
"dev": "yarn generate-abi-types && NODE_ENV=development nodemon",
|
14
14
|
"generate-abi-types": "typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
|
15
|
-
"prepublishOnly": "yarn build"
|
15
|
+
"prepublishOnly": "yarn build",
|
16
|
+
"postinstall": "patch-package"
|
16
17
|
},
|
17
18
|
"nodemonConfig": {
|
18
19
|
"watch": [
|
@@ -23,9 +24,10 @@
|
|
23
24
|
},
|
24
25
|
"dependencies": {
|
25
26
|
"@achingbrain/libp2p-gossipsub": "^0.12.2",
|
27
|
+
"@fastify/cors": "^7.0.0",
|
28
|
+
"await-spawn": "^4.0.2",
|
26
29
|
"axios": "^0.27.1",
|
27
30
|
"axios-retry": "^3.2.4",
|
28
|
-
"bignumber.js": "^9.0.2",
|
29
31
|
"chalk": "4.1.2",
|
30
32
|
"dotenv": "^16.0.0",
|
31
33
|
"ethereumjs-util": "^7.1.4",
|
@@ -33,7 +35,7 @@
|
|
33
35
|
"ethers-multisend": "^2.1.1",
|
34
36
|
"expand-home-dir": "^0.0.3",
|
35
37
|
"fastify": "^3.28.0",
|
36
|
-
"
|
38
|
+
"fs-extra": "^10.1.0",
|
37
39
|
"libp2p": "^0.36.2",
|
38
40
|
"libp2p-bootstrap": "^0.14.0",
|
39
41
|
"libp2p-kad-dht": "^0.28.6",
|
@@ -45,7 +47,9 @@
|
|
45
47
|
"libp2p-websockets": "^0.16.2",
|
46
48
|
"luxon": "^2.3.2",
|
47
49
|
"module-alias": "^2.2.2",
|
48
|
-
"
|
50
|
+
"patch-package": "^6.4.7",
|
51
|
+
"postinstall-postinstall": "^2.1.0",
|
52
|
+
"sequelize": "6.18.0",
|
49
53
|
"sqlite3": "^5.0.5",
|
50
54
|
"waait": "^1.0.5"
|
51
55
|
},
|
@@ -46,11 +46,17 @@
|
|
46
46
|
"name": "amount",
|
47
47
|
"type": "uint256"
|
48
48
|
},
|
49
|
+
{
|
50
|
+
"indexed": false,
|
51
|
+
"internalType": "uint32",
|
52
|
+
"name": "sourceChainId",
|
53
|
+
"type": "uint32"
|
54
|
+
},
|
49
55
|
{
|
50
56
|
"indexed": true,
|
51
|
-
"internalType": "
|
52
|
-
"name": "
|
53
|
-
"type": "
|
57
|
+
"internalType": "uint32",
|
58
|
+
"name": "targetChainId",
|
59
|
+
"type": "uint32"
|
54
60
|
}
|
55
61
|
],
|
56
62
|
"name": "Burn",
|
@@ -73,14 +79,20 @@
|
|
73
79
|
},
|
74
80
|
{
|
75
81
|
"indexed": true,
|
76
|
-
"internalType": "
|
77
|
-
"name": "
|
78
|
-
"type": "
|
82
|
+
"internalType": "uint32",
|
83
|
+
"name": "sourceChainId",
|
84
|
+
"type": "uint32"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"indexed": false,
|
88
|
+
"internalType": "uint32",
|
89
|
+
"name": "targetChainId",
|
90
|
+
"type": "uint32"
|
79
91
|
},
|
80
92
|
{
|
81
93
|
"indexed": true,
|
82
94
|
"internalType": "bytes32",
|
83
|
-
"name": "
|
95
|
+
"name": "submitTransactionHash",
|
84
96
|
"type": "bytes32"
|
85
97
|
}
|
86
98
|
],
|
@@ -164,7 +176,7 @@
|
|
164
176
|
"inputs": [
|
165
177
|
{ "internalType": "address", "name": "to", "type": "address" },
|
166
178
|
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
167
|
-
{ "internalType": "
|
179
|
+
{ "internalType": "uint32", "name": "chainId", "type": "uint32" }
|
168
180
|
],
|
169
181
|
"name": "burn",
|
170
182
|
"outputs": [],
|
@@ -206,7 +218,7 @@
|
|
206
218
|
"inputs": [
|
207
219
|
{ "internalType": "address", "name": "to", "type": "address" },
|
208
220
|
{ "internalType": "uint256", "name": "amount", "type": "uint256" },
|
209
|
-
{ "internalType": "
|
221
|
+
{ "internalType": "uint32", "name": "chainId", "type": "uint32" },
|
210
222
|
{
|
211
223
|
"internalType": "bytes32",
|
212
224
|
"name": "transactionHash",
|
@@ -35,15 +35,15 @@
|
|
35
35
|
},
|
36
36
|
{
|
37
37
|
"indexed": false,
|
38
|
-
"internalType": "
|
38
|
+
"internalType": "uint32",
|
39
39
|
"name": "sourceChainId",
|
40
|
-
"type": "
|
40
|
+
"type": "uint32"
|
41
41
|
},
|
42
42
|
{
|
43
43
|
"indexed": true,
|
44
|
-
"internalType": "
|
44
|
+
"internalType": "uint32",
|
45
45
|
"name": "targetChainId",
|
46
|
-
"type": "
|
46
|
+
"type": "uint32"
|
47
47
|
}
|
48
48
|
],
|
49
49
|
"name": "LogGatewayDeposit",
|
@@ -72,15 +72,15 @@
|
|
72
72
|
},
|
73
73
|
{
|
74
74
|
"indexed": true,
|
75
|
-
"internalType": "
|
75
|
+
"internalType": "uint32",
|
76
76
|
"name": "sourceChainId",
|
77
|
-
"type": "
|
77
|
+
"type": "uint32"
|
78
78
|
},
|
79
79
|
{
|
80
80
|
"indexed": false,
|
81
|
-
"internalType": "
|
81
|
+
"internalType": "uint32",
|
82
82
|
"name": "targetChainId",
|
83
|
-
"type": "
|
83
|
+
"type": "uint32"
|
84
84
|
},
|
85
85
|
{
|
86
86
|
"indexed": true,
|
@@ -122,7 +122,7 @@
|
|
122
122
|
"inputs": [
|
123
123
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
124
124
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
125
|
-
{ "internalType": "
|
125
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
126
126
|
],
|
127
127
|
"name": "deposit",
|
128
128
|
"outputs": [],
|
@@ -134,7 +134,7 @@
|
|
134
134
|
{ "internalType": "address", "name": "to_", "type": "address" },
|
135
135
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
136
136
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
137
|
-
{ "internalType": "
|
137
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" }
|
138
138
|
],
|
139
139
|
"name": "depositFor",
|
140
140
|
"outputs": [],
|
@@ -160,7 +160,7 @@
|
|
160
160
|
{ "internalType": "uint256", "name": "amount_", "type": "uint256" },
|
161
161
|
{ "internalType": "address", "name": "user_", "type": "address" },
|
162
162
|
{ "internalType": "address", "name": "token_", "type": "address" },
|
163
|
-
{ "internalType": "
|
163
|
+
{ "internalType": "uint32", "name": "chainId_", "type": "uint32" },
|
164
164
|
{
|
165
165
|
"internalType": "bytes32",
|
166
166
|
"name": "transactionHash_",
|
package/dist/src/api/index.js
CHANGED
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.startApiServer = void 0;
|
7
7
|
const fastify_1 = __importDefault(require("fastify"));
|
8
|
-
const
|
8
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
9
9
|
const logger_1 = __importDefault(require("@/logger"));
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const logger = new logger_1.default("RPC");
|
12
12
|
const server = (0, fastify_1.default)({ logger: false });
|
13
|
-
server.register(
|
13
|
+
server.register(cors_1.default, {});
|
14
14
|
server.get('/', async () => 'Interop X API');
|
15
15
|
const startApiServer = async () => {
|
16
16
|
const HOST = process.env.API_HOST || '0.0.0.0';
|
@@ -26,7 +26,7 @@ const startApiServer = async () => {
|
|
26
26
|
logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
|
27
27
|
}
|
28
28
|
catch (err) {
|
29
|
-
logger.error(err);
|
29
|
+
logger.error(err.message);
|
30
30
|
process.exit(1);
|
31
31
|
}
|
32
32
|
};
|
package/dist/src/config/index.js
CHANGED
@@ -1,15 +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';
|
16
|
+
this.autoUpdate = !!process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
|
11
17
|
this.wallet = new ethers_1.Wallet(this.privateKey);
|
12
18
|
this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E';
|
19
|
+
this.baseConfigPath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
13
20
|
}
|
14
21
|
get publicAddress() {
|
15
22
|
return this.wallet.address;
|
@@ -17,5 +24,8 @@ class Config {
|
|
17
24
|
isLeadNode() {
|
18
25
|
return ethers_1.ethers.utils.getAddress(this.leadNodeAddress) === ethers_1.ethers.utils.getAddress(this.wallet.address);
|
19
26
|
}
|
27
|
+
isMaintenanceMode() {
|
28
|
+
return fs_extra_1.default.existsSync(this.baseConfigPath + '/maintenance');
|
29
|
+
}
|
20
30
|
}
|
21
31
|
exports.default = new Config();
|
@@ -15,6 +15,6 @@ exports.addresses = {
|
|
15
15
|
43114: {
|
16
16
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
17
17
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
18
|
-
interopXGateway: '
|
18
|
+
interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
|
19
19
|
}
|
20
20
|
};
|
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",
|
@@ -19,36 +21,96 @@ module_alias_1.default.addAliases({
|
|
19
21
|
"@/typechain": __dirname + "/typechain"
|
20
22
|
});
|
21
23
|
(0, module_alias_1.default)();
|
22
|
-
const assert_1 = __importDefault(require("assert"));
|
23
24
|
const dotenv_1 = __importDefault(require("dotenv"));
|
25
|
+
const chalk_1 = __importDefault(require("chalk"));
|
24
26
|
const ethers_1 = require("ethers");
|
25
27
|
const package_json_1 = __importDefault(require("../package.json"));
|
26
28
|
dotenv_1.default.config();
|
27
29
|
const logger_1 = __importDefault(require("@/logger"));
|
28
30
|
const logger = new logger_1.default('Process');
|
29
|
-
|
31
|
+
const GIT_SHORT_HASH = '2c0a756';
|
32
|
+
const printUsage = () => {
|
33
|
+
console.log();
|
34
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
35
|
+
console.log();
|
30
36
|
console.log('Usage:');
|
31
|
-
console.log('
|
32
|
-
console.log('
|
37
|
+
console.log(' interop-x help Show this message');
|
38
|
+
console.log(' interop-x version Print out the installed version of Interop X');
|
39
|
+
console.log();
|
40
|
+
console.log(' interop-x down Put the node into maintenance mode');
|
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();
|
48
|
+
};
|
49
|
+
if (process.argv.at(-1) === 'help') {
|
50
|
+
printUsage();
|
33
51
|
process.exit(0);
|
34
52
|
}
|
35
|
-
(0,
|
53
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
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
|
+
}
|
64
|
+
if (process.argv.at(-1) === 'version') {
|
65
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
66
|
+
process.exit(0);
|
67
|
+
}
|
68
|
+
if (!process.env.PRIVATE_KEY) {
|
69
|
+
console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
|
70
|
+
printUsage();
|
71
|
+
process.exit(1);
|
72
|
+
}
|
36
73
|
try {
|
37
74
|
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
38
75
|
}
|
39
76
|
catch (e) {
|
40
|
-
|
77
|
+
console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
|
78
|
+
printUsage();
|
41
79
|
process.exit(1);
|
42
80
|
}
|
43
|
-
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev
|
81
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
44
82
|
const tasks_1 = require("@/tasks");
|
45
83
|
const net_1 = require("@/net");
|
46
84
|
const api_1 = require("@/api");
|
85
|
+
const db_1 = require("./db");
|
86
|
+
const utils_1 = require("./utils");
|
47
87
|
async function main() {
|
48
88
|
(0, net_1.startPeer)({});
|
49
89
|
const tasks = new tasks_1.Tasks();
|
50
90
|
tasks.start();
|
51
91
|
(0, api_1.startApiServer)();
|
92
|
+
net_1.protocol.on('TransactionStatus', async (payload) => {
|
93
|
+
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
94
|
+
const peer = net_1.peerPool.getPeer(payload.peerId);
|
95
|
+
if (!peer) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
102
|
+
if (!transaction) {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
transaction.sourceStatus = payload.data.sourceStatus;
|
106
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
107
|
+
transaction.sourceErrors = payload.data.sourceErrors;
|
108
|
+
transaction.targetStatus = payload.data.targetStatus;
|
109
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
110
|
+
transaction.targetErrors = payload.data.targetErrors;
|
111
|
+
transaction.status = payload.data.status;
|
112
|
+
await transaction.save();
|
113
|
+
});
|
52
114
|
}
|
53
115
|
main()
|
54
116
|
.then(() => {
|
@@ -23,6 +23,7 @@ const libp2p_kad_dht_1 = __importDefault(require("libp2p-kad-dht"));
|
|
23
23
|
const libp2p_pubsub_peer_discovery_1 = __importDefault(require("libp2p-pubsub-peer-discovery"));
|
24
24
|
const net_1 = require("@/net");
|
25
25
|
const config_1 = __importDefault(require("@/config"));
|
26
|
+
const chalk_1 = __importDefault(require("chalk"));
|
26
27
|
const logger = new logger_1.default("Peer");
|
27
28
|
let node;
|
28
29
|
// Known peers addresses
|
@@ -77,13 +78,17 @@ const startPeer = async ({}) => {
|
|
77
78
|
persistence: true,
|
78
79
|
},
|
79
80
|
});
|
80
|
-
logger.info("Peer ID:", node.peerId.toB58String());
|
81
|
+
logger.info("Peer ID:", chalk_1.default.bold(node.peerId.toB58String()));
|
81
82
|
await node.start();
|
82
83
|
net_1.protocol.start({
|
83
84
|
libp2p: node
|
84
85
|
});
|
85
|
-
node.on("peer:discovery", (peer) =>
|
86
|
-
|
86
|
+
node.on("peer:discovery", (peer) => {
|
87
|
+
// logger.log(`Discovered peer ${peer}`)
|
88
|
+
}); // peer disc.
|
89
|
+
node.connectionManager.on("peer:connect", (connection) => {
|
90
|
+
// logger.log(`Connected to ${connection.remotePeer.toB58String()}`)
|
91
|
+
});
|
87
92
|
logger.log("Peer discovery started");
|
88
93
|
await (0, waait_1.default)(1000);
|
89
94
|
setInterval(() => net_1.protocol.sendPeerInfo({
|
@@ -6,6 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.peerPool = exports.PeerPool = void 0;
|
7
7
|
const types_1 = require("@/types");
|
8
8
|
const config_1 = __importDefault(require("@/config"));
|
9
|
+
const logger_1 = __importDefault(require("@/logger"));
|
10
|
+
const utils_1 = require("ethers/lib/utils");
|
11
|
+
const utils_2 = require("@/utils");
|
12
|
+
const chalk_1 = __importDefault(require("chalk"));
|
13
|
+
const logger = new logger_1.default('PeerPool');
|
9
14
|
class PeerPool {
|
10
15
|
constructor() {
|
11
16
|
this.PEERS_CLEANUP_TIME_LIMIT = 1;
|
@@ -62,10 +67,14 @@ class PeerPool {
|
|
62
67
|
* @emits {@link Event.POOL_PEER_ADDED}
|
63
68
|
*/
|
64
69
|
add(peer) {
|
65
|
-
if (peer && peer.id
|
70
|
+
if (peer && peer.id) {
|
71
|
+
const newPeer = !this.pool.get(peer.id);
|
66
72
|
this.pool.set(peer.id, peer);
|
67
73
|
peer.pooled = true;
|
68
|
-
|
74
|
+
if (newPeer) {
|
75
|
+
config_1.default.events.emit(types_1.Event.POOL_PEER_ADDED, peer);
|
76
|
+
logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} added to pool`);
|
77
|
+
}
|
69
78
|
}
|
70
79
|
}
|
71
80
|
/**
|
@@ -78,6 +87,7 @@ class PeerPool {
|
|
78
87
|
if (this.pool.delete(peer.id)) {
|
79
88
|
peer.pooled = false;
|
80
89
|
config_1.default.events.emit(types_1.Event.POOL_PEER_REMOVED, peer);
|
90
|
+
logger.info(`Peer ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.id, 16))} with address ${chalk_1.default.bold((0, utils_2.shortenHash)(peer.publicAddress))} removed from pool`);
|
81
91
|
}
|
82
92
|
}
|
83
93
|
}
|
@@ -93,14 +103,27 @@ class PeerPool {
|
|
93
103
|
get activePeerIds() {
|
94
104
|
return this.activePeers.map((p) => p.id);
|
95
105
|
}
|
106
|
+
getPeer(id) {
|
107
|
+
return this.pool.get(id);
|
108
|
+
}
|
109
|
+
isLeadNode(id) {
|
110
|
+
const peer = this.pool.get(id);
|
111
|
+
if (!peer) {
|
112
|
+
return false;
|
113
|
+
}
|
114
|
+
return (0, utils_1.getAddress)(peer.publicAddress) === (0, utils_1.getAddress)(config_1.default.leadNodeAddress);
|
115
|
+
}
|
116
|
+
getLeadPeer() {
|
117
|
+
return this.peers.find((p) => this.isLeadNode(p.id));
|
118
|
+
}
|
96
119
|
cleanup() {
|
97
|
-
let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
98
|
-
this.peers.forEach((peerInfo) => {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
})
|
120
|
+
// let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
|
121
|
+
// this.peers.forEach((peerInfo) => {
|
122
|
+
// if (peerInfo.updated.getTime() < compDate) {
|
123
|
+
// console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
|
124
|
+
// this.remove(peerInfo)
|
125
|
+
// }
|
126
|
+
// })
|
104
127
|
}
|
105
128
|
}
|
106
129
|
exports.PeerPool = PeerPool;
|
@@ -33,12 +33,19 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
33
33
|
error: 'Event not found'
|
34
34
|
};
|
35
35
|
}
|
36
|
+
console.log("signing:", {
|
37
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
38
|
+
data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
|
39
|
+
chainId: transaction.targetChainId,
|
40
|
+
safeTxGas: data.safeTxGas,
|
41
|
+
nonce: data.safeNonce,
|
42
|
+
});
|
36
43
|
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
chainId: transaction.sourceChainId,
|
44
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
45
|
+
data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
|
46
|
+
chainId: transaction.targetChainId,
|
41
47
|
safeTxGas: data.safeTxGas,
|
48
|
+
nonce: data.safeNonce,
|
42
49
|
}, { signer });
|
43
50
|
return {
|
44
51
|
signer: signer.address,
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TransactionStatusDialProtocol = void 0;
|
4
|
+
const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
5
|
+
const db_1 = require("@/db");
|
6
|
+
class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
7
|
+
constructor(libp2p) {
|
8
|
+
super(libp2p, '/interop-x/transaction-status');
|
9
|
+
this.timeout = 30000;
|
10
|
+
}
|
11
|
+
async response(transactionHash) {
|
12
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
13
|
+
if (!transaction) {
|
14
|
+
return null;
|
15
|
+
}
|
16
|
+
return {
|
17
|
+
transactionHash: transaction.transactionHash,
|
18
|
+
sourceStatus: transaction.sourceStatus,
|
19
|
+
sourceTransactionHash: transaction.sourceTransactionHash,
|
20
|
+
sourceErrors: transaction.sourceErrors,
|
21
|
+
targetStatus: transaction.targetStatus,
|
22
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
23
|
+
targetErrors: transaction.targetErrors,
|
24
|
+
status: transaction.status,
|
25
|
+
};
|
26
|
+
}
|
27
|
+
}
|
28
|
+
exports.TransactionStatusDialProtocol = TransactionStatusDialProtocol;
|
@@ -10,13 +10,14 @@ const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
|
|
10
10
|
const __1 = require("..");
|
11
11
|
const config_1 = __importDefault(require("@/config"));
|
12
12
|
const types_1 = require("@/types");
|
13
|
+
const TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
|
13
14
|
class Protocol extends stream_1.EventEmitter {
|
14
15
|
constructor() {
|
15
16
|
super(...arguments);
|
16
17
|
this.protocolMessages = [
|
17
18
|
{
|
18
19
|
name: 'PeerInfo',
|
19
|
-
code:
|
20
|
+
code: 0x01,
|
20
21
|
encode: (info) => [
|
21
22
|
Buffer.from(info.publicAddress),
|
22
23
|
],
|
@@ -24,6 +25,30 @@ class Protocol extends stream_1.EventEmitter {
|
|
24
25
|
publicAddress: publicAddress.toString(),
|
25
26
|
}),
|
26
27
|
},
|
28
|
+
{
|
29
|
+
name: 'TransactionStatus',
|
30
|
+
code: 0x02,
|
31
|
+
encode: (transaction) => [
|
32
|
+
Buffer.from(transaction.transactionHash),
|
33
|
+
Buffer.from(transaction.sourceStatus),
|
34
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
35
|
+
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
36
|
+
Buffer.from(transaction.targetStatus),
|
37
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
38
|
+
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
39
|
+
Buffer.from(transaction.status),
|
40
|
+
],
|
41
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
|
42
|
+
transactionHash: transactionHash.toString(),
|
43
|
+
sourceStatus: sourceStatus.toString(),
|
44
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
45
|
+
sourceErrors: sourceErrors.map((e) => e.toString()),
|
46
|
+
targetStatus: targetStatus.toString(),
|
47
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
48
|
+
targetErrors: targetErrors.map((e) => e.toString()),
|
49
|
+
status: status.toString(),
|
50
|
+
}),
|
51
|
+
},
|
27
52
|
];
|
28
53
|
}
|
29
54
|
start({ libp2p, topic = null, }) {
|
@@ -40,6 +65,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
40
65
|
});
|
41
66
|
});
|
42
67
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
68
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
43
69
|
}
|
44
70
|
init() {
|
45
71
|
this.libp2p.pubsub.subscribe(this.topic);
|
@@ -75,6 +101,11 @@ class Protocol extends stream_1.EventEmitter {
|
|
75
101
|
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
|
76
102
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
77
103
|
}
|
104
|
+
sendTransaction(transaction) {
|
105
|
+
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
|
106
|
+
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
|
107
|
+
this.libp2p.pubsub.publish(this.topic, encoded);
|
108
|
+
}
|
78
109
|
async requestSignatures(data, peerIds) {
|
79
110
|
try {
|
80
111
|
peerIds = peerIds || __1.peerPool.activePeerIds;
|
@@ -88,5 +119,14 @@ class Protocol extends stream_1.EventEmitter {
|
|
88
119
|
return [];
|
89
120
|
}
|
90
121
|
}
|
122
|
+
async requestTransactionStatus(transactionHash, peerId) {
|
123
|
+
try {
|
124
|
+
return await this.transactionStatus.send(transactionHash, peerId);
|
125
|
+
}
|
126
|
+
catch (error) {
|
127
|
+
console.log(error);
|
128
|
+
return null;
|
129
|
+
}
|
130
|
+
}
|
91
131
|
}
|
92
132
|
exports.protocol = new Protocol();
|