@instadapp/interop-x 0.0.0-dev.59f2858 → 0.0.0-dev.59f84ce
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/interop-x +1 -1
- package/dist/package.json +73 -0
- package/dist/{abi → src/abi}/erc20.json +0 -0
- package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
- package/dist/{abi → src/abi}/index.js +2 -4
- package/dist/src/abi/interopXContract.json +391 -0
- package/dist/src/alias.js +10 -0
- package/dist/{api → src/api}/index.js +6 -3
- package/dist/{config → src/config}/index.js +11 -1
- package/dist/{constants → src/constants}/addresses.js +3 -11
- package/dist/{constants → src/constants}/index.js +0 -0
- package/dist/{constants → src/constants}/tokens.js +0 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +0 -0
- package/dist/{db → src/db}/models/transaction.js +27 -7
- package/dist/{db → src/db}/sequelize.js +0 -0
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +41 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +117 -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 +17 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/{net → src/net}/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
- package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +146 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
- package/dist/src/tasks/index.js +33 -0
- package/dist/{typechain → src/typechain}/Erc20.js +0 -0
- package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
- package/dist/{typechain/InteropBridgeToken.js → src/typechain/InteropXContract.js} +0 -0
- package/dist/{typechain → src/typechain}/common.js +0 -0
- package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
- package/dist/src/typechain/factories/index.js +12 -0
- package/dist/{typechain → src/typechain}/index.js +3 -5
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +168 -0
- package/package.json +10 -6
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +391 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +5 -2
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +3 -11
- package/src/db/models/transaction.ts +61 -19
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +56 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +95 -24
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +19 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +14 -4
- package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +208 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
- package/src/tasks/index.ts +16 -4
- package/src/typechain/InteropXContract.ts +524 -0
- package/src/typechain/factories/InteropXContract__factory.ts +533 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +118 -7
- package/tsconfig.json +7 -2
- package/dist/abi/interopBridgeToken.json +0 -286
- package/dist/abi/interopXGateway.json +0 -184
- package/dist/index.js +0 -66
- package/dist/tasks/InteropXGateway/SyncDepositEvents.js +0 -66
- package/dist/tasks/index.js +0 -27
- package/dist/typechain/InteropXGateway.js +0 -2
- package/dist/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/typechain/factories/InteropXGateway__factory.js +0 -265
- package/dist/typechain/factories/index.js +0 -14
- package/dist/utils/index.js +0 -101
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -111
- package/src/typechain/InteropBridgeToken.ts +0 -686
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -0,0 +1,9 @@
|
|
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 withdraw_1 = __importDefault(require("./withdraw"));
|
7
|
+
exports.default = {
|
8
|
+
withdraw: withdraw_1.default,
|
9
|
+
};
|
@@ -0,0 +1,41 @@
|
|
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 abi_1 = __importDefault(require("@/abi"));
|
7
|
+
const config_1 = __importDefault(require("@/config"));
|
8
|
+
const constants_1 = require("@/constants");
|
9
|
+
const utils_1 = require("@/utils");
|
10
|
+
const ethers_1 = require("ethers");
|
11
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
12
|
+
async function default_1(transaction, type) {
|
13
|
+
const transactions = [];
|
14
|
+
const logs = [];
|
15
|
+
if (transaction.action !== 'withdraw') {
|
16
|
+
throw new Error(`Invalid action: ${transaction.action}`);
|
17
|
+
}
|
18
|
+
if (type !== 'source') {
|
19
|
+
throw new Error(`Type not supported: ${type}`);
|
20
|
+
}
|
21
|
+
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
22
|
+
throw Error('Cannot build data for pending withdraw transaction');
|
23
|
+
}
|
24
|
+
if (!transaction.requestEvent) {
|
25
|
+
throw Error('Cannot build data for transaction without requestEvent');
|
26
|
+
}
|
27
|
+
const { bridger, position, sourceChainId, targetChainId, metadata, } = transaction.requestEvent;
|
28
|
+
const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
29
|
+
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
30
|
+
const contractAddress = constants_1.addresses[sourceChainId].interopXContract;
|
31
|
+
const contract = (0, utils_1.getContract)(contractAddress, abi_1.default.interopXContract, sourceWallet);
|
32
|
+
const { data } = await contract.populateTransaction.withdrawRequested(bridger, position.withdraw[0].sourceToken, position.withdraw[0].targetToken, position.withdraw[0].amount, targetChainId, transaction.requestTransactionHash, metadata);
|
33
|
+
transactions.push({
|
34
|
+
to: contractAddress,
|
35
|
+
data: data,
|
36
|
+
value: '0',
|
37
|
+
operation: ethers_multisend_1.OperationType.Call,
|
38
|
+
});
|
39
|
+
return { transactions, logs };
|
40
|
+
}
|
41
|
+
exports.default = default_1;
|
@@ -0,0 +1,20 @@
|
|
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
|
+
exports.buildGnosisAction = void 0;
|
7
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
8
|
+
const actions_1 = __importDefault(require("./actions"));
|
9
|
+
const buildGnosisAction = async (transaction, type) => {
|
10
|
+
type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
|
11
|
+
if (actions_1.default.hasOwnProperty(transaction.action)) {
|
12
|
+
const { transactions, logs } = await actions_1.default[transaction.action](transaction, type);
|
13
|
+
return {
|
14
|
+
data: (0, ethers_multisend_1.encodeMulti)(transactions).data,
|
15
|
+
logs
|
16
|
+
};
|
17
|
+
}
|
18
|
+
throw new Error(`Unknown action: ${transaction.action}`);
|
19
|
+
};
|
20
|
+
exports.buildGnosisAction = buildGnosisAction;
|
@@ -0,0 +1,117 @@
|
|
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
|
+
require("./alias");
|
7
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
9
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
11
|
+
const ethers_1 = require("ethers");
|
12
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
13
|
+
dotenv_1.default.config();
|
14
|
+
const logger_1 = __importDefault(require("@/logger"));
|
15
|
+
const logger = new logger_1.default('Process');
|
16
|
+
const GIT_SHORT_HASH = '59f84ce';
|
17
|
+
const printUsage = () => {
|
18
|
+
console.log();
|
19
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
20
|
+
console.log();
|
21
|
+
console.log('Usage:');
|
22
|
+
console.log(' interop-x help Show this message');
|
23
|
+
console.log(' interop-x version Print out the installed version of Interop X');
|
24
|
+
console.log();
|
25
|
+
console.log(' interop-x down Put the node into maintenance mode');
|
26
|
+
console.log(' interop-x up Take the node out of maintenance mode');
|
27
|
+
console.log();
|
28
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
|
29
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
|
30
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
|
31
|
+
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');
|
32
|
+
console.log();
|
33
|
+
};
|
34
|
+
if (process.argv.at(-1) === 'help') {
|
35
|
+
printUsage();
|
36
|
+
process.exit(0);
|
37
|
+
}
|
38
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
39
|
+
if (process.argv.at(-1) === 'down') {
|
40
|
+
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
41
|
+
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
42
|
+
process.exit(0);
|
43
|
+
}
|
44
|
+
if (process.argv.at(-1) === 'up') {
|
45
|
+
fs_extra_1.default.removeSync(basePath + '/maintenance');
|
46
|
+
console.log(chalk_1.default.green('Maintenance mode disabled'));
|
47
|
+
process.exit(0);
|
48
|
+
}
|
49
|
+
if (process.argv.at(-1) === 'version') {
|
50
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
51
|
+
process.exit(0);
|
52
|
+
}
|
53
|
+
if (!process.env.PRIVATE_KEY) {
|
54
|
+
console.error(chalk_1.default.bgRed.white.bold('Please provide a private key\n'));
|
55
|
+
printUsage();
|
56
|
+
process.exit(1);
|
57
|
+
}
|
58
|
+
try {
|
59
|
+
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
60
|
+
}
|
61
|
+
catch (e) {
|
62
|
+
console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
|
63
|
+
printUsage();
|
64
|
+
process.exit(1);
|
65
|
+
}
|
66
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
67
|
+
const tasks_1 = require("@/tasks");
|
68
|
+
const net_1 = require("@/net");
|
69
|
+
const api_1 = require("@/api");
|
70
|
+
const db_1 = require("./db");
|
71
|
+
const utils_1 = require("./utils");
|
72
|
+
async function main() {
|
73
|
+
(0, net_1.startPeer)({});
|
74
|
+
const tasks = new tasks_1.Tasks();
|
75
|
+
tasks.start();
|
76
|
+
(0, api_1.startApiServer)();
|
77
|
+
net_1.protocol.on('TransactionStatus', async (payload) => {
|
78
|
+
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
79
|
+
const peer = net_1.peerPool.getPeer(payload.peerId);
|
80
|
+
if (!peer) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${(0, utils_1.shortenHash)(peer.publicAddress)} `);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
87
|
+
if (!transaction) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
transaction.sourceStatus = payload.data.sourceStatus;
|
91
|
+
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
92
|
+
transaction.sourceErrors = payload.data.sourceErrors;
|
93
|
+
transaction.sourceLogs = payload.data.sourceLogs;
|
94
|
+
transaction.targetStatus = payload.data.targetStatus;
|
95
|
+
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
96
|
+
transaction.targetErrors = payload.data.targetErrors;
|
97
|
+
transaction.targetLogs = payload.data.targetLogs;
|
98
|
+
transaction.status = payload.data.status;
|
99
|
+
await transaction.save();
|
100
|
+
});
|
101
|
+
}
|
102
|
+
main()
|
103
|
+
.then(() => {
|
104
|
+
}).catch(err => {
|
105
|
+
console.error(err);
|
106
|
+
});
|
107
|
+
process.on('SIGINT', () => {
|
108
|
+
logger.debug('received SIGINT signal. exiting.');
|
109
|
+
process.exit(0);
|
110
|
+
});
|
111
|
+
process.on('SIGTERM', () => {
|
112
|
+
logger.debug('received SIGTERM signal. exiting.');
|
113
|
+
process.exit(0);
|
114
|
+
});
|
115
|
+
process.on('unhandledRejection', (reason, p) => {
|
116
|
+
logger.error('unhandled rejection: promise:', p, 'reason:', reason);
|
117
|
+
});
|
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
|
@@ -8,6 +8,9 @@ const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
|
8
8
|
const waait_1 = __importDefault(require("waait"));
|
9
9
|
const config_1 = __importDefault(require("@/config"));
|
10
10
|
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const gnosis_1 = require("@/gnosis");
|
11
14
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
12
15
|
constructor(libp2p) {
|
13
16
|
super(libp2p, '/interop-x/signatures');
|
@@ -15,31 +18,33 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
15
18
|
}
|
16
19
|
async response(data) {
|
17
20
|
const signer = config_1.default.wallet;
|
18
|
-
let
|
21
|
+
let transaction;
|
19
22
|
let maxTimeout = 20000;
|
20
23
|
do {
|
21
|
-
|
22
|
-
if (!
|
24
|
+
transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
|
25
|
+
if (!transaction) {
|
23
26
|
await (0, waait_1.default)(1000);
|
24
27
|
maxTimeout -= 1000;
|
25
28
|
}
|
26
|
-
} while (!
|
27
|
-
if (!
|
29
|
+
} while (!transaction && maxTimeout > 0);
|
30
|
+
if (!transaction) {
|
28
31
|
return {
|
29
32
|
signer: signer.address,
|
30
33
|
data: null,
|
31
34
|
error: 'Event not found'
|
32
35
|
};
|
33
36
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
38
|
+
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
39
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
40
|
+
data: gnosisData,
|
41
|
+
chainId: transaction.targetChainId,
|
42
|
+
safeTxGas: data.safeTxGas,
|
43
|
+
nonce: data.safeNonce,
|
44
|
+
}, { signer });
|
40
45
|
return {
|
41
46
|
signer: signer.address,
|
42
|
-
data:
|
47
|
+
data: signedData
|
43
48
|
};
|
44
49
|
}
|
45
50
|
}
|
@@ -0,0 +1,30 @@
|
|
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
|
+
sourceLogs: transaction.sourceLogs,
|
22
|
+
targetStatus: transaction.targetStatus,
|
23
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
24
|
+
targetErrors: transaction.targetErrors,
|
25
|
+
targetLogs: transaction.targetLogs,
|
26
|
+
status: transaction.status,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
}
|
30
|
+
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,40 @@ 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
|
+
transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
37
|
+
Buffer.from(transaction.targetStatus),
|
38
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
39
|
+
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
40
|
+
transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
41
|
+
Buffer.from(transaction.status),
|
42
|
+
],
|
43
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
|
44
|
+
transactionHash: transactionHash.toString(),
|
45
|
+
sourceStatus: sourceStatus.toString(),
|
46
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
47
|
+
sourceErrors: sourceErrors.map((e) => e.toString()),
|
48
|
+
sourceLogs: sourceLogs.map(e => ({
|
49
|
+
type: e[0].toString(),
|
50
|
+
message: e[1].toString(),
|
51
|
+
})),
|
52
|
+
targetStatus: targetStatus.toString(),
|
53
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
54
|
+
targetErrors: targetErrors.map((e) => e.toString()),
|
55
|
+
targetLogs: targetLogs.map(e => ({
|
56
|
+
type: e[0].toString(),
|
57
|
+
message: e[1].toString(),
|
58
|
+
})),
|
59
|
+
status: status.toString(),
|
60
|
+
}),
|
61
|
+
},
|
27
62
|
];
|
28
63
|
}
|
29
64
|
start({ libp2p, topic = null, }) {
|
@@ -40,6 +75,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
40
75
|
});
|
41
76
|
});
|
42
77
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
78
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
43
79
|
}
|
44
80
|
init() {
|
45
81
|
this.libp2p.pubsub.subscribe(this.topic);
|
@@ -75,6 +111,11 @@ class Protocol extends stream_1.EventEmitter {
|
|
75
111
|
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
|
76
112
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
77
113
|
}
|
114
|
+
sendTransaction(transaction) {
|
115
|
+
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
|
116
|
+
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
|
117
|
+
this.libp2p.pubsub.publish(this.topic, encoded);
|
118
|
+
}
|
78
119
|
async requestSignatures(data, peerIds) {
|
79
120
|
try {
|
80
121
|
peerIds = peerIds || __1.peerPool.activePeerIds;
|
@@ -88,5 +129,14 @@ class Protocol extends stream_1.EventEmitter {
|
|
88
129
|
return [];
|
89
130
|
}
|
90
131
|
}
|
132
|
+
async requestTransactionStatus(transactionHash, peerId) {
|
133
|
+
try {
|
134
|
+
return await this.transactionStatus.send(transactionHash, peerId);
|
135
|
+
}
|
136
|
+
catch (error) {
|
137
|
+
console.log(error);
|
138
|
+
return null;
|
139
|
+
}
|
140
|
+
}
|
91
141
|
}
|
92
142
|
exports.protocol = new Protocol();
|
@@ -0,0 +1,70 @@
|
|
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 await_spawn_1 = __importDefault(require("await-spawn"));
|
9
|
+
const child_process_1 = require("child_process");
|
10
|
+
const config_1 = __importDefault(require("@/config"));
|
11
|
+
const waait_1 = __importDefault(require("waait"));
|
12
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
13
|
+
const currentVersion = package_json_1.default.version;
|
14
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
15
|
+
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
16
|
+
constructor() {
|
17
|
+
super({
|
18
|
+
logger: new logger_1.default("AutoUpdateTask"),
|
19
|
+
});
|
20
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
21
|
+
}
|
22
|
+
prePollHandler() {
|
23
|
+
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
24
|
+
}
|
25
|
+
async getInstalledVersion() {
|
26
|
+
try {
|
27
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['-g', 'ls', '--depth=0', '--json']);
|
28
|
+
return JSON.parse(stdout.toString()).dependencies[package_json_1.default.name].version;
|
29
|
+
}
|
30
|
+
catch (error) {
|
31
|
+
this.logger.error(error);
|
32
|
+
return currentVersion;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
async getLatestVersion() {
|
36
|
+
try {
|
37
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
|
38
|
+
return stdout.toString().trim();
|
39
|
+
}
|
40
|
+
catch (error) {
|
41
|
+
this.logger.error(error);
|
42
|
+
return currentVersion;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
async pollHandler() {
|
46
|
+
const version = await this.getLatestVersion();
|
47
|
+
if (version === currentVersion) {
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
this.logger.warn(`New version ${version} available.`);
|
51
|
+
this.logger.info('Updating...');
|
52
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
53
|
+
await (0, waait_1.default)(5000);
|
54
|
+
if (version !== await this.getInstalledVersion()) {
|
55
|
+
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
this.logger.warn(`Installed version ${version}`);
|
59
|
+
this.logger.warn(`Restarting...`);
|
60
|
+
// TODO: its restarting in the bg, but it should be in the fg
|
61
|
+
const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
|
62
|
+
cwd: process.cwd(),
|
63
|
+
stdio: "inherit",
|
64
|
+
// shell: process.env.SHELL,
|
65
|
+
});
|
66
|
+
subprocess.unref();
|
67
|
+
process.exit();
|
68
|
+
}
|
69
|
+
}
|
70
|
+
exports.default = AutoUpdateTask;
|
@@ -14,6 +14,7 @@ class BaseTask extends events_1.default {
|
|
14
14
|
this.started = false;
|
15
15
|
this.pollIntervalMs = 10 * 1000;
|
16
16
|
this.leadNodeOnly = false;
|
17
|
+
this.exceptLeadNode = false;
|
17
18
|
this.logger = logger !== null && logger !== void 0 ? logger : new logger_1.default('BaseTask');
|
18
19
|
}
|
19
20
|
async pollCheck() {
|
@@ -28,16 +29,23 @@ class BaseTask extends events_1.default {
|
|
28
29
|
}
|
29
30
|
}
|
30
31
|
catch (err) {
|
31
|
-
this.logger.error(`poll check error
|
32
|
+
this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`);
|
32
33
|
}
|
33
34
|
await this.postPollHandler();
|
34
35
|
}
|
35
36
|
}
|
36
37
|
prePollHandler() {
|
37
|
-
if (
|
38
|
-
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
40
|
+
return false;
|
39
41
|
}
|
40
|
-
|
42
|
+
if (this.exceptLeadNode) {
|
43
|
+
return !config_1.default.isLeadNode();
|
44
|
+
}
|
45
|
+
if (this.leadNodeOnly) {
|
46
|
+
return config_1.default.isLeadNode();
|
47
|
+
}
|
48
|
+
return true;
|
41
49
|
}
|
42
50
|
async pollHandler() {
|
43
51
|
this.logger.warn('pollHandler not implemented');
|