@instadapp/interop-x 0.0.0-dev.2c0a756 → 0.0.0-dev.30b0db0

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.
Files changed (48) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/abi/interopBridgeToken.json +9 -21
  3. package/dist/src/abi/interopXGateway.json +11 -11
  4. package/dist/src/api/index.js +1 -1
  5. package/dist/src/config/index.js +1 -10
  6. package/dist/src/constants/addresses.js +1 -1
  7. package/dist/src/constants/itokens.js +1 -1
  8. package/dist/src/index.js +5 -28
  9. package/dist/src/net/peer/index.js +1 -2
  10. package/dist/src/net/pool/index.js +2 -3
  11. package/dist/src/net/protocol/dial/{TransactionStatusDialProtocol.js → SignatureDialProtocol.1.js} +0 -0
  12. package/dist/src/net/protocol/index.js +6 -6
  13. package/dist/src/tasks/AutoUpdateTask.js +11 -33
  14. package/dist/src/tasks/BaseTask.js +0 -4
  15. package/dist/src/tasks/InteropBridge/{SyncBurnEvents.js → SyncWithdrawEvents.js} +8 -10
  16. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +1 -14
  17. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +2 -2
  18. package/dist/src/tasks/index.js +5 -17
  19. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +11 -23
  20. package/dist/src/typechain/factories/InteropXGateway__factory.js +14 -14
  21. package/dist/src/utils/index.js +7 -7
  22. package/package.json +2 -2
  23. package/src/abi/interopBridgeToken.json +9 -21
  24. package/src/abi/interopXGateway.json +11 -11
  25. package/src/api/index.ts +1 -1
  26. package/src/config/index.ts +1 -9
  27. package/src/constants/addresses.ts +1 -1
  28. package/src/constants/itokens.ts +1 -1
  29. package/src/index.ts +9 -41
  30. package/src/net/peer/index.ts +1 -2
  31. package/src/net/pool/index.ts +2 -3
  32. package/src/net/protocol/dial/{TransactionStatusDialProtocol.ts → SignatureDialProtocol.1.ts} +0 -0
  33. package/src/net/protocol/index.ts +5 -5
  34. package/src/tasks/AutoUpdateTask.ts +14 -36
  35. package/src/tasks/BaseTask.ts +0 -5
  36. package/src/tasks/InteropBridge/{SyncBurnEvents.ts → SyncWithdrawEvents.ts} +8 -10
  37. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +4 -18
  38. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +2 -2
  39. package/src/tasks/index.ts +4 -24
  40. package/src/typechain/InteropBridgeToken.ts +17 -23
  41. package/src/typechain/InteropXGateway.ts +13 -13
  42. package/src/typechain/factories/InteropBridgeToken__factory.ts +11 -23
  43. package/src/typechain/factories/InteropXGateway__factory.ts +14 -14
  44. package/src/utils/index.ts +7 -7
  45. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -66
  46. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -71
  47. package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -98
  48. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -103
@@ -57,17 +57,11 @@ const _abi = [
57
57
  name: "amount",
58
58
  type: "uint256",
59
59
  },
60
- {
61
- indexed: false,
62
- internalType: "uint32",
63
- name: "sourceChainId",
64
- type: "uint32",
65
- },
66
60
  {
67
61
  indexed: true,
68
- internalType: "uint32",
69
- name: "targetChainId",
70
- type: "uint32",
62
+ internalType: "uint256",
63
+ name: "chainId",
64
+ type: "uint256",
71
65
  },
72
66
  ],
73
67
  name: "Burn",
@@ -90,20 +84,14 @@ const _abi = [
90
84
  },
91
85
  {
92
86
  indexed: true,
93
- internalType: "uint32",
94
- name: "sourceChainId",
95
- type: "uint32",
96
- },
97
- {
98
- indexed: false,
99
- internalType: "uint32",
100
- name: "targetChainId",
101
- type: "uint32",
87
+ internalType: "uint256",
88
+ name: "chainId",
89
+ type: "uint256",
102
90
  },
103
91
  {
104
92
  indexed: true,
105
93
  internalType: "bytes32",
106
- name: "submitTransactionHash",
94
+ name: "transactionHash",
107
95
  type: "bytes32",
108
96
  },
109
97
  ],
@@ -234,9 +222,9 @@ const _abi = [
234
222
  type: "uint256",
235
223
  },
236
224
  {
237
- internalType: "uint32",
225
+ internalType: "uint256",
238
226
  name: "chainId",
239
- type: "uint32",
227
+ type: "uint256",
240
228
  },
241
229
  ],
242
230
  name: "burn",
@@ -318,9 +306,9 @@ const _abi = [
318
306
  type: "uint256",
319
307
  },
320
308
  {
321
- internalType: "uint32",
309
+ internalType: "uint256",
322
310
  name: "chainId",
323
- type: "uint32",
311
+ type: "uint256",
324
312
  },
325
313
  {
326
314
  internalType: "bytes32",
@@ -46,15 +46,15 @@ const _abi = [
46
46
  },
47
47
  {
48
48
  indexed: false,
49
- internalType: "uint32",
49
+ internalType: "uint256",
50
50
  name: "sourceChainId",
51
- type: "uint32",
51
+ type: "uint256",
52
52
  },
53
53
  {
54
54
  indexed: true,
55
- internalType: "uint32",
55
+ internalType: "uint256",
56
56
  name: "targetChainId",
57
- type: "uint32",
57
+ type: "uint256",
58
58
  },
59
59
  ],
60
60
  name: "LogGatewayDeposit",
@@ -83,15 +83,15 @@ const _abi = [
83
83
  },
84
84
  {
85
85
  indexed: true,
86
- internalType: "uint32",
86
+ internalType: "uint256",
87
87
  name: "sourceChainId",
88
- type: "uint32",
88
+ type: "uint256",
89
89
  },
90
90
  {
91
91
  indexed: false,
92
- internalType: "uint32",
92
+ internalType: "uint256",
93
93
  name: "targetChainId",
94
- type: "uint32",
94
+ type: "uint256",
95
95
  },
96
96
  {
97
97
  indexed: true,
@@ -148,9 +148,9 @@ const _abi = [
148
148
  type: "uint256",
149
149
  },
150
150
  {
151
- internalType: "uint32",
151
+ internalType: "uint256",
152
152
  name: "chainId_",
153
- type: "uint32",
153
+ type: "uint256",
154
154
  },
155
155
  ],
156
156
  name: "deposit",
@@ -176,9 +176,9 @@ const _abi = [
176
176
  type: "uint256",
177
177
  },
178
178
  {
179
- internalType: "uint32",
179
+ internalType: "uint256",
180
180
  name: "chainId_",
181
- type: "uint32",
181
+ type: "uint256",
182
182
  },
183
183
  ],
184
184
  name: "depositFor",
@@ -224,9 +224,9 @@ const _abi = [
224
224
  type: "address",
225
225
  },
226
226
  {
227
- internalType: "uint32",
227
+ internalType: "uint256",
228
228
  name: "chainId_",
229
- type: "uint32",
229
+ type: "uint256",
230
230
  },
231
231
  {
232
232
  internalType: "bytes32",
@@ -22,7 +22,7 @@ function shortenHash(hash, length = 4) {
22
22
  if (hash.length < 12)
23
23
  return hash;
24
24
  const beginningChars = hash.startsWith("0x") ? length + 2 : length;
25
- const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
25
+ const shortened = hash.substring(0, beginningChars) + "…" + hash.substring(-length);
26
26
  return shortened;
27
27
  }
28
28
  exports.shortenHash = shortenHash;
@@ -167,20 +167,20 @@ const buildWithdrawDataForTransaction = async (transaction, type) => {
167
167
  if (!transaction.submitEvent) {
168
168
  throw Error('Cannot build data for transaction without submitEvent');
169
169
  }
170
- const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
171
- const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
170
+ const { to, amount, chainId, itoken: itokenAddress } = transaction.submitEvent;
171
+ const itoken = constants_1.itokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
172
172
  if (!itoken) {
173
173
  throw Error('Cannot build data for transaction without itoken');
174
174
  }
175
- const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
175
+ const token = constants_1.tokens[chainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
176
176
  if (!token) {
177
177
  throw Error('Cannot build data for transaction without token');
178
178
  }
179
- const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(targetChainId));
179
+ const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
180
180
  const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
181
- const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
181
+ const gatewayAddress = constants_1.addresses[chainId].interopXGateway;
182
182
  const interopBridgeContract = getContract(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
183
- const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(sourceChainId.toString()), transaction.submitTransactionHash);
183
+ const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(transaction.sourceChainId.toString()), transaction.submitTransactionHash);
184
184
  transactions.push({
185
185
  to: gatewayAddress,
186
186
  data: data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.2c0a756",
3
+ "version": "0.0.0-dev.30b0db0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -28,6 +28,7 @@
28
28
  "await-spawn": "^4.0.2",
29
29
  "axios": "^0.27.1",
30
30
  "axios-retry": "^3.2.4",
31
+ "bignumber.js": "^9.0.2",
31
32
  "chalk": "4.1.2",
32
33
  "dotenv": "^16.0.0",
33
34
  "ethereumjs-util": "^7.1.4",
@@ -35,7 +36,6 @@
35
36
  "ethers-multisend": "^2.1.1",
36
37
  "expand-home-dir": "^0.0.3",
37
38
  "fastify": "^3.28.0",
38
- "fs-extra": "^10.1.0",
39
39
  "libp2p": "^0.36.2",
40
40
  "libp2p-bootstrap": "^0.14.0",
41
41
  "libp2p-kad-dht": "^0.28.6",
@@ -46,17 +46,11 @@
46
46
  "name": "amount",
47
47
  "type": "uint256"
48
48
  },
49
- {
50
- "indexed": false,
51
- "internalType": "uint32",
52
- "name": "sourceChainId",
53
- "type": "uint32"
54
- },
55
49
  {
56
50
  "indexed": true,
57
- "internalType": "uint32",
58
- "name": "targetChainId",
59
- "type": "uint32"
51
+ "internalType": "uint256",
52
+ "name": "chainId",
53
+ "type": "uint256"
60
54
  }
61
55
  ],
62
56
  "name": "Burn",
@@ -79,20 +73,14 @@
79
73
  },
80
74
  {
81
75
  "indexed": true,
82
- "internalType": "uint32",
83
- "name": "sourceChainId",
84
- "type": "uint32"
85
- },
86
- {
87
- "indexed": false,
88
- "internalType": "uint32",
89
- "name": "targetChainId",
90
- "type": "uint32"
76
+ "internalType": "uint256",
77
+ "name": "chainId",
78
+ "type": "uint256"
91
79
  },
92
80
  {
93
81
  "indexed": true,
94
82
  "internalType": "bytes32",
95
- "name": "submitTransactionHash",
83
+ "name": "transactionHash",
96
84
  "type": "bytes32"
97
85
  }
98
86
  ],
@@ -176,7 +164,7 @@
176
164
  "inputs": [
177
165
  { "internalType": "address", "name": "to", "type": "address" },
178
166
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
179
- { "internalType": "uint32", "name": "chainId", "type": "uint32" }
167
+ { "internalType": "uint256", "name": "chainId", "type": "uint256" }
180
168
  ],
181
169
  "name": "burn",
182
170
  "outputs": [],
@@ -218,7 +206,7 @@
218
206
  "inputs": [
219
207
  { "internalType": "address", "name": "to", "type": "address" },
220
208
  { "internalType": "uint256", "name": "amount", "type": "uint256" },
221
- { "internalType": "uint32", "name": "chainId", "type": "uint32" },
209
+ { "internalType": "uint256", "name": "chainId", "type": "uint256" },
222
210
  {
223
211
  "internalType": "bytes32",
224
212
  "name": "transactionHash",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  {
37
37
  "indexed": false,
38
- "internalType": "uint32",
38
+ "internalType": "uint256",
39
39
  "name": "sourceChainId",
40
- "type": "uint32"
40
+ "type": "uint256"
41
41
  },
42
42
  {
43
43
  "indexed": true,
44
- "internalType": "uint32",
44
+ "internalType": "uint256",
45
45
  "name": "targetChainId",
46
- "type": "uint32"
46
+ "type": "uint256"
47
47
  }
48
48
  ],
49
49
  "name": "LogGatewayDeposit",
@@ -72,15 +72,15 @@
72
72
  },
73
73
  {
74
74
  "indexed": true,
75
- "internalType": "uint32",
75
+ "internalType": "uint256",
76
76
  "name": "sourceChainId",
77
- "type": "uint32"
77
+ "type": "uint256"
78
78
  },
79
79
  {
80
80
  "indexed": false,
81
- "internalType": "uint32",
81
+ "internalType": "uint256",
82
82
  "name": "targetChainId",
83
- "type": "uint32"
83
+ "type": "uint256"
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": "uint32", "name": "chainId_", "type": "uint32" }
125
+ { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
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": "uint32", "name": "chainId_", "type": "uint32" }
137
+ { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
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": "uint32", "name": "chainId_", "type": "uint32" },
163
+ { "internalType": "uint256", "name": "chainId_", "type": "uint256" },
164
164
  {
165
165
  "internalType": "bytes32",
166
166
  "name": "transactionHash_",
package/src/api/index.ts CHANGED
@@ -27,7 +27,7 @@ export const startApiServer = async () => {
27
27
 
28
28
  logger.log(`RPC Server listening at http://${HOST}:${PORT}`)
29
29
  } catch (err) {
30
- logger.error(err.message)
30
+ logger.error(err)
31
31
  process.exit(1)
32
32
  }
33
33
  }
@@ -1,7 +1,5 @@
1
1
  import { ethers, Wallet } from "ethers"
2
2
  import { EventBus, EventBusType } from "@/types"
3
- import fs from 'fs-extra'
4
- import expandHomeDir from "expand-home-dir";
5
3
 
6
4
  class Config {
7
5
  public readonly events: EventBusType
@@ -11,17 +9,15 @@ class Config {
11
9
  public readonly wallet: Wallet
12
10
  public readonly staging: boolean
13
11
  public readonly autoUpdate: boolean
14
- public readonly baseConfigPath: string
15
12
 
16
13
  constructor() {
17
14
  this.events = new EventBus() as EventBusType
18
- this.maxPeers = 20
15
+ this.maxPeers = 10
19
16
  this.privateKey = process.env.PRIVATE_KEY as string;
20
17
  this.staging = !! process.env.STAGING && process.env.STAGING === 'true';
21
18
  this.autoUpdate = !! process.env.AUTO_UPDATE && process.env.AUTO_UPDATE === 'true';
22
19
  this.wallet = new Wallet(this.privateKey);
23
20
  this.leadNodeAddress = '0x910E413DBF3F6276Fe8213fF656726bDc142E08E'
24
- this.baseConfigPath = expandHomeDir(`~/.interop-x`);
25
21
  }
26
22
 
27
23
  get publicAddress(){
@@ -31,10 +27,6 @@ class Config {
31
27
  isLeadNode() {
32
28
  return ethers.utils.getAddress(this.leadNodeAddress) === ethers.utils.getAddress(this.wallet.address)
33
29
  }
34
-
35
- isMaintenanceMode(){
36
- return fs.existsSync(this.baseConfigPath + '/maintenance')
37
- }
38
30
  }
39
31
 
40
32
  export default new Config()
@@ -12,6 +12,6 @@ export const addresses = {
12
12
  43114: {
13
13
  gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
14
14
  multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
15
- interopXGateway: '0xF0317C5Bc206F2291dd2f3eE9C4cDB5Bbb25418d',
15
+ interopXGateway: '0x8D27758751BA488690974B6Ccfcda771D462945f',
16
16
  }
17
17
  }
@@ -2,7 +2,7 @@ export const itokens = {
2
2
  1: [],
3
3
  137: [
4
4
  {
5
- address: '0x62C0045f3277E7067cAcad3c8038eEaBB1Bd92D1',
5
+ address: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
6
6
  symbol: 'USDC',
7
7
  }
8
8
  ],
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import moduleAlias from 'module-alias';
2
- import expandHomeDir from "expand-home-dir";
3
- import fs from 'fs-extra'
2
+
4
3
  moduleAlias.addAliases({
5
4
  "@/": __dirname + "/",
6
5
  "@/logger": __dirname + "/logger",
@@ -26,30 +25,12 @@ dotenv.config();
26
25
  import Logger from "@/logger";
27
26
  const logger = new Logger('Process')
28
27
 
29
- const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
30
-
31
28
  const printUsage = () => {
32
- console.log()
33
- console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
34
- console.log()
35
-
36
29
  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
-
40
- console.log()
41
-
42
- console.log(' interop-x down Put the node into maintenance mode')
43
- console.log(' interop-x up Take the node out of maintenance mode')
44
-
45
- console.log()
46
-
47
- console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key')
48
- console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode')
49
- console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode')
50
- 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')
51
- console.log()
52
-
30
+ console.log(' PRIVATE_KEY=abcd1234 interop-x')
31
+ 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')
53
34
  }
54
35
 
55
36
  if (process.argv.at(-1) === 'help') {
@@ -57,27 +38,14 @@ if (process.argv.at(-1) === 'help') {
57
38
  process.exit(0)
58
39
  }
59
40
 
60
- const basePath = expandHomeDir(`~/.interop-x`);
61
-
62
- if (process.argv.at(-1) === 'down') {
63
- fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
64
- console.log(chalk.red('Maintenance mode enabled'))
65
- process.exit(0)
66
- }
67
-
68
- if (process.argv.at(-1) === 'up') {
69
- fs.removeSync(basePath + '/maintenance')
70
- console.log(chalk.green('Maintenance mode disabled'))
71
- process.exit(0)
72
- }
73
-
41
+ const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
74
42
 
75
43
  if (process.argv.at(-1) === 'version') {
76
44
  console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
77
45
  process.exit(0)
78
46
  }
79
47
 
80
- if (!process.env.PRIVATE_KEY) {
48
+ if(! process.env.PRIVATE_KEY) {
81
49
  console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
82
50
  printUsage()
83
51
  process.exit(1)
@@ -112,10 +80,10 @@ async function main() {
112
80
  if (!peerPool.isLeadNode(payload.peerId)) {
113
81
  const peer = peerPool.getPeer(payload.peerId)
114
82
 
115
- if (!peer) {
83
+ if(! peer) {
116
84
  return;
117
85
  }
118
-
86
+
119
87
  logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
120
88
  return;
121
89
  }
@@ -17,7 +17,6 @@ import KadDHT from "libp2p-kad-dht";
17
17
  import PubsubPeerDiscovery from "libp2p-pubsub-peer-discovery";
18
18
  import { protocol } from "@/net";
19
19
  import config from "@/config";
20
- import chalk from "chalk";
21
20
 
22
21
  const logger = new Logger("Peer");
23
22
 
@@ -81,7 +80,7 @@ export const startPeer = async ({ }: IPeerOptions) => {
81
80
  },
82
81
  });
83
82
 
84
- logger.info("Peer ID:", chalk.bold(node.peerId.toB58String()));
83
+ logger.info("Peer ID:", node.peerId.toB58String());
85
84
 
86
85
  await node.start();
87
86
 
@@ -3,7 +3,6 @@ import config from "@/config";
3
3
  import Logger from "@/logger";
4
4
  import { getAddress } from "ethers/lib/utils";
5
5
  import { shortenHash } from "@/utils";
6
- import chalk from "chalk";
7
6
 
8
7
 
9
8
  const logger = new Logger('PeerPool')
@@ -89,7 +88,7 @@ export class PeerPool {
89
88
 
90
89
  if (newPeer) {
91
90
  config.events.emit(Event.POOL_PEER_ADDED, peer)
92
- logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
91
+ logger.info(`Peer ${peer.id} with address ${shortenHash(peer.publicAddress)} added to pool`)
93
92
  }
94
93
  }
95
94
  }
@@ -104,7 +103,7 @@ export class PeerPool {
104
103
  if (this.pool.delete(peer.id)) {
105
104
  peer.pooled = false
106
105
  config.events.emit(Event.POOL_PEER_REMOVED, peer)
107
- logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
106
+ logger.info(`Peer ${peer.id} with address ${shortenHash(peer.publicAddress)} removed from pool`)
108
107
  }
109
108
  }
110
109
  }
@@ -6,7 +6,7 @@ import { IPeerInfo, peerPool } from "..";
6
6
  import config from "@/config";
7
7
  import { Event } from "@/types";
8
8
  import { Transaction } from "@/db";
9
- import { TransactionStatusDialProtocol } from "./dial/TransactionStatusDialProtocol";
9
+ import { TransactionStatusDialProtocol } from "./dial/SignatureDialProtocol.1";
10
10
 
11
11
  export interface ProtocolOptions {
12
12
  /* Handshake timeout in ms (default: 8000) */
@@ -66,11 +66,11 @@ class Protocol extends EventEmitter {
66
66
  Buffer.from(transaction.transactionHash),
67
67
 
68
68
  Buffer.from(transaction.sourceStatus),
69
- Buffer.from(transaction.sourceTransactionHash || ''),
69
+ Buffer.from(transaction.sourceTransactionHash),
70
70
  transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
71
71
 
72
72
  Buffer.from(transaction.targetStatus),
73
- Buffer.from(transaction.targetTransactionHash || ''),
73
+ Buffer.from(transaction.targetTransactionHash),
74
74
  transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
75
75
 
76
76
  Buffer.from(transaction.status),
@@ -79,11 +79,11 @@ class Protocol extends EventEmitter {
79
79
  transactionHash: transactionHash.toString(),
80
80
 
81
81
  sourceStatus: sourceStatus.toString(),
82
- sourceTransactionHash: sourceTransactionHash.toString() || null,
82
+ sourceTransactionHash: sourceTransactionHash.toString(),
83
83
  sourceErrors: sourceErrors.map((e) => e.toString()),
84
84
 
85
85
  targetStatus: targetStatus.toString(),
86
- targetTransactionHash: targetTransactionHash.toString()|| null,
86
+ targetTransactionHash: targetTransactionHash.toString(),
87
87
  targetErrors: targetErrors.map((e) => e.toString()),
88
88
 
89
89
  status: status.toString(),
@@ -1,16 +1,12 @@
1
1
  import { BaseTask } from "./BaseTask";
2
2
  import Logger from '@/logger';
3
- import spawnAsync from 'await-spawn';
4
- import { spawn } from 'child_process'
3
+ import { http } from "@/utils";
4
+ import spawn from 'await-spawn';
5
5
  import config from "@/config";
6
6
  import wait from "waait";
7
- import packageJson from "../../package.json";
8
-
9
- const currentVersion = packageJson.version;
10
- const tag = config.staging ? 'dev' : 'latest';
11
7
 
12
8
  class AutoUpdateTask extends BaseTask {
13
- pollIntervalMs: number = 60 * 10 * 1000
9
+ pollIntervalMs: number = 60 * 5 * 1000
14
10
 
15
11
  constructor() {
16
12
  super({
@@ -22,28 +18,15 @@ class AutoUpdateTask extends BaseTask {
22
18
  return config.autoUpdate && !config.isLeadNode();
23
19
  }
24
20
 
25
- async getInstalledVersion() {
26
- try {
27
- const stdout = await spawnAsync('npm', ['-g', 'ls', '--depth=0', '--json'])
28
- return JSON.parse(stdout.toString()).dependencies[packageJson.name].version
29
- } catch (error) {
30
- this.logger.error(error)
31
- return currentVersion
32
- }
21
+ getCurrentVersion() {
22
+ return require('../../package.json').version
33
23
  }
24
+ async pollHandler() {
34
25
 
35
- async getLatestVersion() {
36
- try {
37
- const stdout = await spawnAsync('npm', ['view', `${packageJson.name}@${tag}`, 'version'])
38
- return stdout.toString().trim()
39
- } catch (error) {
40
- this.logger.error(error)
41
- return currentVersion
42
- }
43
- }
26
+ const { data } = await http.get('https://registry.npmjs.org/@instadapp/interop-x')
44
27
 
45
- async pollHandler() {
46
- const version = await this.getLatestVersion()
28
+ const version = data['dist-tags'].latest
29
+ const currentVersion = this.getCurrentVersion()
47
30
 
48
31
  if (version === currentVersion) {
49
32
  return;
@@ -51,13 +34,13 @@ class AutoUpdateTask extends BaseTask {
51
34
 
52
35
  this.logger.warn(`New version ${version} available.`)
53
36
 
54
- this.logger.info('Updating...')
55
37
 
56
- await spawnAsync('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
38
+ await spawn('npm', ['-g', 'install', '@instadapp/interop-x', '-f']);
39
+
57
40
 
58
41
  await wait(5000)
59
42
 
60
- if (version !== await this.getInstalledVersion()) {
43
+ if (currentVersion === this.getCurrentVersion()) {
61
44
  this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
62
45
  return;
63
46
  }
@@ -65,16 +48,11 @@ class AutoUpdateTask extends BaseTask {
65
48
  this.logger.warn(`Installed version ${version}`)
66
49
  this.logger.warn(`Restarting...`)
67
50
 
68
-
69
- // TODO: its restarting in the bg, but it should be in the fg
70
- const subprocess = spawn(process.argv[0], process.argv.slice(1), {
51
+ spawn(process.argv[0], process.argv.slice(1), {
71
52
  cwd: process.cwd(),
72
- stdio: "inherit",
73
- // shell: process.env.SHELL,
53
+ stdio: "inherit"
74
54
  });
75
55
 
76
- subprocess.unref();
77
-
78
56
  process.exit()
79
57
  }
80
58
  }