@instadapp/interop-x 0.0.0-dev.ef78459 → 0.0.0-dev.f0a6281
Sign up to get free protection for your applications and to get access to all the features.
- package/.env.example +2 -1
- package/bin/interop-x +1 -1
- package/dist/package.json +73 -0
- package/dist/src/abi/erc20.json +350 -0
- package/dist/src/abi/gnosisSafe.json +747 -0
- package/dist/src/abi/index.js +15 -0
- package/dist/src/abi/interopBridgeToken.json +298 -0
- package/dist/src/abi/interopXGateway.json +184 -0
- package/dist/src/api/index.js +33 -0
- package/dist/src/config/index.js +31 -0
- package/dist/src/constants/addresses.js +20 -0
- package/dist/{constants → src/constants}/index.js +2 -0
- package/dist/src/constants/itokens.js +13 -0
- package/dist/src/constants/tokens.js +107 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +1 -1
- package/dist/src/db/models/transaction.js +54 -0
- package/dist/{db → src/db}/sequelize.js +2 -1
- package/dist/src/index.js +130 -0
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +8 -3
- package/dist/{net → src/net}/pool/index.js +32 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +20 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/{net → src/net}/protocol/index.js +44 -4
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +13 -5
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +146 -0
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +71 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +161 -0
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +74 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +44 -0
- package/dist/src/typechain/Erc20.js +2 -0
- package/dist/src/typechain/GnosisSafe.js +2 -0
- package/dist/src/typechain/InteropBridgeToken.js +2 -0
- package/dist/src/typechain/InteropXGateway.js +2 -0
- package/dist/src/typechain/common.js +2 -0
- package/dist/src/typechain/factories/Erc20__factory.js +367 -0
- package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +471 -0
- package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
- package/dist/src/typechain/factories/index.js +14 -0
- package/dist/src/typechain/index.js +35 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +238 -0
- package/package.json +18 -10
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/erc20.json +350 -0
- package/src/abi/gnosisSafe.json +747 -0
- package/src/abi/index.ts +11 -0
- package/src/abi/interopBridgeToken.json +298 -0
- package/src/abi/interopXGateway.json +184 -0
- package/src/api/index.ts +33 -0
- package/src/config/index.ts +17 -1
- package/src/constants/addresses.ts +9 -2
- package/src/constants/index.ts +2 -0
- package/src/constants/itokens.ts +10 -0
- package/src/constants/tokens.ts +104 -0
- package/src/db/models/index.ts +1 -1
- package/src/db/models/transaction.ts +96 -0
- package/src/db/sequelize.ts +2 -1
- package/src/index.ts +119 -7
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +24 -15
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +60 -4
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +15 -6
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +231 -0
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +121 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +256 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +124 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +26 -1
- package/src/typechain/Erc20.ts +491 -0
- package/src/typechain/GnosisSafe.ts +1728 -0
- package/src/typechain/InteropBridgeToken.ts +692 -0
- package/src/typechain/InteropXGateway.ts +407 -0
- package/src/typechain/common.ts +44 -0
- package/src/typechain/factories/Erc20__factory.ts +368 -0
- package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
- package/src/typechain/factories/InteropBridgeToken__factory.ts +478 -0
- package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
- package/src/typechain/factories/index.ts +7 -0
- package/src/typechain/index.ts +12 -0
- package/src/types.ts +1 -1
- package/src/utils/index.ts +206 -3
- package/dist/config/index.js +0 -17
- package/dist/constants/addresses.js +0 -13
- package/dist/db/models/execution.js +0 -38
- package/dist/index.js +0 -43
- package/dist/tasks/index.js +0 -19
- package/dist/utils/index.js +0 -89
- package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,107 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.tokens = void 0;
|
4
|
+
exports.tokens = {
|
5
|
+
1: [
|
6
|
+
{
|
7
|
+
symbol: "ETH",
|
8
|
+
name: "Ethereum",
|
9
|
+
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
10
|
+
decimals: 18,
|
11
|
+
},
|
12
|
+
{
|
13
|
+
symbol: "DAI",
|
14
|
+
name: "DAI Stable",
|
15
|
+
address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
16
|
+
decimals: 18,
|
17
|
+
},
|
18
|
+
{
|
19
|
+
symbol: "USDC",
|
20
|
+
name: "USD Coin",
|
21
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
22
|
+
decimals: 6,
|
23
|
+
},
|
24
|
+
{
|
25
|
+
symbol: "USDT",
|
26
|
+
name: "Tether USD Coin",
|
27
|
+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
28
|
+
decimals: 6,
|
29
|
+
},
|
30
|
+
{
|
31
|
+
symbol: "WBTC",
|
32
|
+
name: "Wrapped BTC",
|
33
|
+
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
34
|
+
decimals: 8,
|
35
|
+
},
|
36
|
+
],
|
37
|
+
137: [
|
38
|
+
{
|
39
|
+
symbol: "ETH",
|
40
|
+
name: "Ethereum",
|
41
|
+
address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
42
|
+
decimals: 18,
|
43
|
+
},
|
44
|
+
{
|
45
|
+
symbol: "DAI",
|
46
|
+
name: "DAI Stable",
|
47
|
+
address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
|
48
|
+
decimals: 18,
|
49
|
+
},
|
50
|
+
{
|
51
|
+
symbol: "USDC",
|
52
|
+
name: "USD Coin",
|
53
|
+
address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
54
|
+
decimals: 6,
|
55
|
+
},
|
56
|
+
{
|
57
|
+
symbol: "USDT",
|
58
|
+
name: "Tether USD Coin",
|
59
|
+
address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
60
|
+
decimals: 6,
|
61
|
+
},
|
62
|
+
{
|
63
|
+
symbol: "WBTC",
|
64
|
+
name: "Wrapped BTC",
|
65
|
+
address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
66
|
+
decimals: 8,
|
67
|
+
},
|
68
|
+
{
|
69
|
+
symbol: "AVAX",
|
70
|
+
name: "Avalanche Token",
|
71
|
+
address: "0x2C89bbc92BD86F8075d1DEcc58C7F4E0107f286b",
|
72
|
+
decimals: 18,
|
73
|
+
},
|
74
|
+
],
|
75
|
+
43114: [
|
76
|
+
{
|
77
|
+
symbol: "ETH",
|
78
|
+
name: "Ethereum",
|
79
|
+
address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
|
80
|
+
decimals: 18,
|
81
|
+
},
|
82
|
+
{
|
83
|
+
symbol: "DAI",
|
84
|
+
name: "DAI Stable",
|
85
|
+
address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
|
86
|
+
decimals: 18,
|
87
|
+
},
|
88
|
+
{
|
89
|
+
symbol: "USDC",
|
90
|
+
name: "USD Coin",
|
91
|
+
address: "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
|
92
|
+
decimals: 6,
|
93
|
+
},
|
94
|
+
{
|
95
|
+
symbol: "USDT",
|
96
|
+
name: "Tether USD Coin",
|
97
|
+
address: "0xc7198437980c041c805A1EDcbA50c1Ce5db95118",
|
98
|
+
decimals: 6,
|
99
|
+
},
|
100
|
+
{
|
101
|
+
symbol: "WBTC",
|
102
|
+
name: "Wrapped BTC",
|
103
|
+
address: "0x50b7545627a5162F82A992c33b87aDc75187B218",
|
104
|
+
decimals: 8,
|
105
|
+
},
|
106
|
+
],
|
107
|
+
};
|
File without changes
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./
|
17
|
+
__exportStar(require("./transaction"), exports);
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Transaction = void 0;
|
4
|
+
const sequelize_1 = require("@/db/sequelize");
|
5
|
+
const sequelize_2 = require("sequelize");
|
6
|
+
class Transaction extends sequelize_2.Model {
|
7
|
+
}
|
8
|
+
exports.Transaction = Transaction;
|
9
|
+
Transaction.init({
|
10
|
+
id: {
|
11
|
+
type: sequelize_2.DataTypes.INTEGER,
|
12
|
+
autoIncrement: true,
|
13
|
+
primaryKey: true
|
14
|
+
},
|
15
|
+
submitTransactionHash: sequelize_2.DataTypes.NUMBER,
|
16
|
+
submitBlockNumber: sequelize_2.DataTypes.NUMBER,
|
17
|
+
transactionHash: sequelize_2.DataTypes.STRING,
|
18
|
+
action: sequelize_2.DataTypes.STRING,
|
19
|
+
from: sequelize_2.DataTypes.STRING,
|
20
|
+
to: sequelize_2.DataTypes.STRING,
|
21
|
+
sourceChainId: sequelize_2.DataTypes.NUMBER,
|
22
|
+
sourceTransactionHash: sequelize_2.DataTypes.STRING,
|
23
|
+
sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
|
24
|
+
sourceStatus: sequelize_2.DataTypes.STRING,
|
25
|
+
sourceErrors: {
|
26
|
+
type: sequelize_2.DataTypes.JSON,
|
27
|
+
// defaultValue: [],
|
28
|
+
},
|
29
|
+
sourceCreatedAt: {
|
30
|
+
type: sequelize_2.DataTypes.DATE,
|
31
|
+
defaultValue: Date.now()
|
32
|
+
},
|
33
|
+
sourceDelayUntil: sequelize_2.DataTypes.STRING,
|
34
|
+
targetChainId: sequelize_2.DataTypes.NUMBER,
|
35
|
+
targetTransactionHash: sequelize_2.DataTypes.STRING,
|
36
|
+
targetBlockNumber: sequelize_2.DataTypes.NUMBER,
|
37
|
+
targetStatus: sequelize_2.DataTypes.STRING,
|
38
|
+
targetErrors: {
|
39
|
+
type: sequelize_2.DataTypes.JSON,
|
40
|
+
// defaultValue: [],
|
41
|
+
},
|
42
|
+
targetCreatedAt: sequelize_2.DataTypes.DATE,
|
43
|
+
targetDelayUntil: sequelize_2.DataTypes.DATE,
|
44
|
+
submitEvent: sequelize_2.DataTypes.JSON,
|
45
|
+
sourceEvent: sequelize_2.DataTypes.JSON,
|
46
|
+
targetEvent: sequelize_2.DataTypes.JSON,
|
47
|
+
metadata: sequelize_2.DataTypes.JSON,
|
48
|
+
status: {
|
49
|
+
type: sequelize_2.DataTypes.STRING,
|
50
|
+
defaultValue: 'pending'
|
51
|
+
},
|
52
|
+
createdAt: sequelize_2.DataTypes.DATE,
|
53
|
+
updatedAt: sequelize_2.DataTypes.DATE,
|
54
|
+
}, { sequelize: sequelize_1.sequelize, tableName: 'transactions' });
|
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.sequelize = void 0;
|
7
7
|
//@ts-ignore
|
8
|
+
const config_1 = __importDefault(require("@/config"));
|
8
9
|
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
9
10
|
const sequelize_1 = require("sequelize");
|
10
|
-
const basePath = (0, expand_home_dir_1.default)(
|
11
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
|
11
12
|
exports.sequelize = new sequelize_1.Sequelize({
|
12
13
|
dialect: 'sqlite',
|
13
14
|
storage: `${basePath}/localDB.sqlite`,
|
@@ -0,0 +1,130 @@
|
|
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 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
|
+
module_alias_1.default.addAliases({
|
10
|
+
"@/": __dirname + "/",
|
11
|
+
"@/logger": __dirname + "/logger",
|
12
|
+
"@/tasks": __dirname + "/tasks",
|
13
|
+
"@/utils": __dirname + "/utils",
|
14
|
+
"@/api": __dirname + "/api",
|
15
|
+
"@/net": __dirname + "/net",
|
16
|
+
"@/db": __dirname + "/db",
|
17
|
+
"@/config": __dirname + "/config",
|
18
|
+
"@/types": __dirname + "/types",
|
19
|
+
"@/abi": __dirname + "/abi",
|
20
|
+
"@/constants": __dirname + "/constants",
|
21
|
+
"@/typechain": __dirname + "/typechain"
|
22
|
+
});
|
23
|
+
(0, module_alias_1.default)();
|
24
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
25
|
+
const chalk_1 = __importDefault(require("chalk"));
|
26
|
+
const ethers_1 = require("ethers");
|
27
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
28
|
+
dotenv_1.default.config();
|
29
|
+
const logger_1 = __importDefault(require("@/logger"));
|
30
|
+
const logger = new logger_1.default('Process');
|
31
|
+
const GIT_SHORT_HASH = 'f0a6281';
|
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();
|
36
|
+
console.log('Usage:');
|
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();
|
51
|
+
process.exit(0);
|
52
|
+
}
|
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
|
+
}
|
73
|
+
try {
|
74
|
+
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
75
|
+
}
|
76
|
+
catch (e) {
|
77
|
+
console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
|
78
|
+
printUsage();
|
79
|
+
process.exit(1);
|
80
|
+
}
|
81
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
82
|
+
const tasks_1 = require("@/tasks");
|
83
|
+
const net_1 = require("@/net");
|
84
|
+
const api_1 = require("@/api");
|
85
|
+
const db_1 = require("./db");
|
86
|
+
const utils_1 = require("./utils");
|
87
|
+
async function main() {
|
88
|
+
(0, net_1.startPeer)({});
|
89
|
+
const tasks = new tasks_1.Tasks();
|
90
|
+
tasks.start();
|
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
|
+
});
|
114
|
+
}
|
115
|
+
main()
|
116
|
+
.then(() => {
|
117
|
+
}).catch(err => {
|
118
|
+
console.error(err);
|
119
|
+
});
|
120
|
+
process.on('SIGINT', () => {
|
121
|
+
logger.debug('received SIGINT signal. exiting.');
|
122
|
+
process.exit(0);
|
123
|
+
});
|
124
|
+
process.on('SIGTERM', () => {
|
125
|
+
logger.debug('received SIGTERM signal. exiting.');
|
126
|
+
process.exit(0);
|
127
|
+
});
|
128
|
+
process.on('unhandledRejection', (reason, p) => {
|
129
|
+
logger.error('unhandled rejection: promise:', p, 'reason:', reason);
|
130
|
+
});
|
File without changes
|
File without changes
|
@@ -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;
|
File without changes
|
@@ -4,44 +4,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.SignatureDialProtocol = void 0;
|
7
|
-
const utils_1 = require("@/utils");
|
8
7
|
const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
9
8
|
const waait_1 = __importDefault(require("waait"));
|
10
9
|
const config_1 = __importDefault(require("@/config"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
11
12
|
const constants_1 = require("@/constants");
|
12
|
-
const db_1 = require("db");
|
13
13
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
14
14
|
constructor(libp2p) {
|
15
|
-
super(libp2p, '/signatures');
|
15
|
+
super(libp2p, '/interop-x/signatures');
|
16
16
|
this.timeout = 30000;
|
17
17
|
}
|
18
18
|
async response(data) {
|
19
19
|
const signer = config_1.default.wallet;
|
20
|
-
let
|
20
|
+
let transaction;
|
21
21
|
let maxTimeout = 20000;
|
22
22
|
do {
|
23
|
-
|
24
|
-
if (!
|
23
|
+
transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
|
24
|
+
if (!transaction) {
|
25
25
|
await (0, waait_1.default)(1000);
|
26
26
|
maxTimeout -= 1000;
|
27
27
|
}
|
28
|
-
} while (!
|
29
|
-
if (!
|
28
|
+
} while (!transaction && maxTimeout > 0);
|
29
|
+
if (!transaction) {
|
30
30
|
return {
|
31
31
|
signer: signer.address,
|
32
32
|
data: null,
|
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
|
-
to: constants_1.addresses[
|
38
|
-
data:
|
39
|
-
chainId:
|
44
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
45
|
+
data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
|
46
|
+
chainId: transaction.targetChainId,
|
40
47
|
safeTxGas: data.safeTxGas,
|
48
|
+
nonce: data.safeNonce,
|
41
49
|
}, { signer });
|
42
50
|
return {
|
43
51
|
signer: signer.address,
|
44
|
-
data: signedData
|
52
|
+
data: signedData
|
45
53
|
};
|
46
54
|
}
|
47
55
|
}
|
@@ -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;
|
@@ -8,15 +8,16 @@ const stream_1 = require("stream");
|
|
8
8
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
9
9
|
const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
|
10
10
|
const __1 = require("..");
|
11
|
-
const config_1 = __importDefault(require("config"));
|
12
|
-
const types_1 = require("types");
|
11
|
+
const config_1 = __importDefault(require("@/config"));
|
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,11 +25,35 @@ 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(),
|
45
|
+
sourceErrors: sourceErrors.map((e) => e.toString()),
|
46
|
+
targetStatus: targetStatus.toString(),
|
47
|
+
targetTransactionHash: targetTransactionHash.toString(),
|
48
|
+
targetErrors: targetErrors.map((e) => e.toString()),
|
49
|
+
status: status.toString(),
|
50
|
+
}),
|
51
|
+
},
|
27
52
|
];
|
28
53
|
}
|
29
54
|
start({ libp2p, topic = null, }) {
|
30
55
|
this.libp2p = libp2p;
|
31
|
-
this.topic = topic || 'protocol';
|
56
|
+
this.topic = topic || 'itnerop-x-protocol';
|
32
57
|
if (this.libp2p.isStarted())
|
33
58
|
this.init();
|
34
59
|
this.on('PeerInfo', (payload) => {
|
@@ -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();
|