@instadapp/interop-x 0.0.0-dev.30b0db0 → 0.0.0-dev.326bdca

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 (78) hide show
  1. package/dist/package.json +3 -3
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +391 -0
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +4 -1
  6. package/dist/src/config/index.js +10 -1
  7. package/dist/src/constants/addresses.js +3 -3
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/db/models/transaction.js +27 -9
  10. package/dist/src/gnosis/actions/index.js +9 -0
  11. package/dist/src/gnosis/actions/withdraw/index.js +41 -0
  12. package/dist/src/gnosis/index.js +20 -0
  13. package/dist/src/index.js +34 -22
  14. package/dist/src/net/peer/index.js +2 -1
  15. package/dist/src/net/pool/index.js +3 -2
  16. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +3 -8
  17. package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
  18. package/dist/src/net/protocol/index.js +17 -7
  19. package/dist/src/tasks/AutoUpdateTask.js +33 -11
  20. package/dist/src/tasks/BaseTask.js +4 -0
  21. package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +44 -47
  22. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  23. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +2 -0
  24. package/dist/src/tasks/index.js +10 -19
  25. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  26. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  27. package/dist/src/typechain/factories/index.js +3 -5
  28. package/dist/src/typechain/index.js +3 -5
  29. package/dist/src/utils/index.js +15 -85
  30. package/package.json +3 -3
  31. package/src/abi/index.ts +2 -4
  32. package/src/abi/interopXContract.json +391 -0
  33. package/src/alias.ts +6 -0
  34. package/src/api/index.ts +4 -1
  35. package/src/config/index.ts +9 -1
  36. package/src/constants/addresses.ts +3 -3
  37. package/src/constants/index.ts +0 -1
  38. package/src/db/models/transaction.ts +59 -21
  39. package/src/gnosis/actions/index.ts +5 -0
  40. package/src/gnosis/actions/withdraw/index.ts +56 -0
  41. package/src/gnosis/index.ts +19 -0
  42. package/src/index.ts +47 -26
  43. package/src/net/peer/index.ts +2 -1
  44. package/src/net/pool/index.ts +3 -2
  45. package/src/net/protocol/dial/SignatureDialProtocol.ts +5 -11
  46. package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
  47. package/src/net/protocol/index.ts +17 -7
  48. package/src/tasks/AutoUpdateTask.ts +36 -14
  49. package/src/tasks/BaseTask.ts +5 -0
  50. package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +69 -92
  51. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +116 -0
  52. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
  53. package/src/tasks/index.ts +13 -21
  54. package/src/typechain/InteropXContract.ts +524 -0
  55. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  56. package/src/typechain/factories/index.ts +1 -2
  57. package/src/typechain/index.ts +2 -4
  58. package/src/utils/index.ts +47 -126
  59. package/tsconfig.json +7 -2
  60. package/dist/src/abi/interopBridgeToken.json +0 -286
  61. package/dist/src/abi/interopXGateway.json +0 -184
  62. package/dist/src/constants/itokens.js +0 -13
  63. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -146
  64. package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -69
  65. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
  66. package/dist/src/typechain/InteropXGateway.js +0 -2
  67. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  68. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  69. package/src/abi/interopBridgeToken.json +0 -286
  70. package/src/abi/interopXGateway.json +0 -184
  71. package/src/constants/itokens.ts +0 -10
  72. package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -119
  73. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -243
  74. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
  75. package/src/typechain/InteropBridgeToken.ts +0 -686
  76. package/src/typechain/InteropXGateway.ts +0 -407
  77. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  78. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -1,40 +1,61 @@
1
1
  import { sequelize } from '@/db/sequelize'
2
2
  import { CreationOptional, InferAttributes, InferCreationAttributes, Model, DataTypes } from 'sequelize';
3
3
 
4
+ export interface IPositionTokenInfo{
5
+ amount: string;
6
+ sourceToken: string;
7
+ targetToken: string;
8
+ }
9
+
10
+ export interface IPosition {
11
+ supply: IPositionTokenInfo[];
12
+ withdraw: IPositionTokenInfo[];
13
+ }
14
+
4
15
  export class Transaction extends Model<InferAttributes<Transaction>, InferCreationAttributes<Transaction>> {
5
16
  declare id: CreationOptional<number>;
6
17
 
7
18
  declare transactionHash: string;
19
+
8
20
  declare action: string;
9
- declare from: string;
10
- declare to: string;
21
+ declare bridger: string;
22
+ declare requestTransactionHash: string;
11
23
 
12
- declare submitTransactionHash: string;
13
- declare submitBlockNumber: number;
24
+ declare requestBlockNumber: number;
14
25
 
15
26
  declare sourceChainId: number;
16
27
  declare sourceTransactionHash: CreationOptional<string>;
17
28
  declare sourceBlockNumber: CreationOptional<number>;
18
- declare sourceStatus: string;
29
+ declare sourceStatus: CreationOptional<string>;
19
30
  declare sourceErrors: CreationOptional<string[]>;
31
+ declare sourceLogs: CreationOptional<any[]>;
20
32
  declare sourceCreatedAt: CreationOptional<Date>;
21
33
  declare sourceDelayUntil: CreationOptional<Date>;
22
34
 
23
35
  declare targetChainId: number;
24
36
  declare targetTransactionHash: CreationOptional<string>;
25
37
  declare targetBlockNumber: CreationOptional<number>;
26
- declare targetStatus: string;
38
+ declare targetStatus: CreationOptional<string>;
27
39
  declare targetErrors: CreationOptional<string[]>;
40
+ declare targetLogs: CreationOptional<any[]>;
28
41
  declare targetCreatedAt: CreationOptional<Date>;
29
42
  declare targetDelayUntil: CreationOptional<Date>;
30
43
 
31
- declare submitEvent: any;
32
- declare sourceEvent: CreationOptional<any>;
33
- declare targetEvent: CreationOptional<any>;
34
-
44
+ declare requestEvent: {
45
+ bridger: string;
46
+ metadata: string;
47
+ position: IPosition;
48
+ sourceChainId: number;
49
+ targetChainId: number;
50
+ };
51
+ declare requestSendEvent: CreationOptional<any>;
52
+ declare committedEvent: CreationOptional<any>;
53
+ declare completedEvent: CreationOptional<any>;
54
+
55
+ declare position: any;
35
56
  declare metadata: CreationOptional<any>;
36
57
 
37
- declare status: string;
58
+ declare status: CreationOptional<string>;
38
59
 
39
60
  declare createdAt: CreationOptional<Date>;
40
61
  declare updatedAt: CreationOptional<Date>;
@@ -47,23 +68,28 @@ Transaction.init({
47
68
  primaryKey: true
48
69
  },
49
70
 
50
- submitTransactionHash: DataTypes.NUMBER,
51
- submitBlockNumber: DataTypes.NUMBER,
71
+ requestTransactionHash: DataTypes.NUMBER,
72
+ requestBlockNumber: DataTypes.NUMBER,
52
73
 
53
74
  transactionHash: DataTypes.STRING,
54
75
  action: DataTypes.STRING,
55
-
56
- from: DataTypes.STRING,
57
- to: DataTypes.STRING,
76
+ bridger: DataTypes.STRING,
58
77
 
59
78
  sourceChainId: DataTypes.NUMBER,
60
79
  sourceTransactionHash: DataTypes.STRING,
61
80
  sourceBlockNumber: DataTypes.NUMBER,
62
- sourceStatus: DataTypes.STRING,
81
+ sourceStatus: {
82
+ type: DataTypes.STRING,
83
+ defaultValue: 'uninitialised'
84
+ },
63
85
  sourceErrors: {
64
86
  type: DataTypes.JSON,
65
87
  // defaultValue: [],
66
88
  },
89
+ sourceLogs: {
90
+ type: DataTypes.JSON,
91
+ // defaultValue: [],
92
+ },
67
93
  sourceCreatedAt: {
68
94
  type: DataTypes.DATE,
69
95
  defaultValue: Date.now()
@@ -73,18 +99,30 @@ Transaction.init({
73
99
  targetChainId: DataTypes.NUMBER,
74
100
  targetTransactionHash: DataTypes.STRING,
75
101
  targetBlockNumber: DataTypes.NUMBER,
76
- targetStatus: DataTypes.STRING,
102
+ targetStatus: {
103
+ type: DataTypes.STRING,
104
+ defaultValue: 'uninitialised'
105
+ },
77
106
  targetErrors: {
78
107
  type: DataTypes.JSON,
79
108
  // defaultValue: [],
80
109
  },
110
+ targetLogs: {
111
+ type: DataTypes.JSON,
112
+ // defaultValue: [],
113
+ },
81
114
  targetCreatedAt: DataTypes.DATE,
82
115
  targetDelayUntil: DataTypes.DATE,
83
116
 
84
- submitEvent: DataTypes.JSON,
85
- sourceEvent: DataTypes.JSON,
86
- targetEvent: DataTypes.JSON,
117
+ requestEvent: {
118
+ type: DataTypes.JSON,
119
+ allowNull: false
120
+ },
121
+ requestSendEvent: DataTypes.JSON,
122
+ committedEvent: DataTypes.JSON,
123
+ completedEvent: DataTypes.JSON,
87
124
 
125
+ position: DataTypes.JSON,
88
126
  metadata: DataTypes.JSON,
89
127
 
90
128
  status: {
@@ -0,0 +1,5 @@
1
+ import withdraw from "./withdraw"
2
+
3
+ export default {
4
+ withdraw,
5
+ }
@@ -0,0 +1,56 @@
1
+ import abi from "@/abi";
2
+ import config from "@/config";
3
+ import { addresses, tokens } from "@/constants";
4
+ import { Transaction } from "@/db";
5
+ import { InteropXContract } from "@/typechain";
6
+ import { ChainId } from "@/types";
7
+ import { getContract, getRpcProviderUrl } from "@/utils";
8
+ import { ethers } from "ethers";
9
+ import { MetaTransaction, OperationType } from "ethers-multisend";
10
+
11
+ export default async function (transaction: Transaction, type: 'source' | 'target') {
12
+ const transactions: MetaTransaction[] = [];
13
+ const logs: any[] = [];
14
+
15
+ if (transaction.action !== 'withdraw') {
16
+ throw new Error(`Invalid action: ${transaction.action}`)
17
+ }
18
+
19
+ if (type !== 'source') {
20
+ throw new Error(`Type not supported: ${type}`)
21
+ }
22
+
23
+ if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
24
+ throw Error('Cannot build data for pending withdraw transaction');
25
+ }
26
+
27
+ if (!transaction.requestEvent) {
28
+ throw Error('Cannot build data for transaction without requestEvent');
29
+ }
30
+
31
+ const { bridger, position, sourceChainId, targetChainId, metadata, } = transaction.requestEvent;
32
+
33
+ const sourceChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
34
+ const sourceWallet = new ethers.Wallet(config.privateKey, sourceChainProvider);
35
+ const contractAddress = addresses[sourceChainId].interopXContract;
36
+ const contract = getContract<InteropXContract>(contractAddress, abi.interopXContract, sourceWallet);
37
+
38
+ const { data } = await contract.populateTransaction.withdrawRequested(
39
+ bridger,
40
+ position.withdraw[0].sourceToken,
41
+ position.withdraw[0].targetToken,
42
+ position.withdraw[0].amount,
43
+ targetChainId,
44
+ transaction.requestTransactionHash,
45
+ metadata,
46
+ );
47
+
48
+ transactions.push({
49
+ to: contractAddress,
50
+ data: data!,
51
+ value: '0',
52
+ operation: OperationType.Call,
53
+ });
54
+
55
+ return { transactions, logs }
56
+ }
@@ -0,0 +1,19 @@
1
+ import { Transaction } from "@/db";
2
+ import { encodeMulti } from "ethers-multisend";
3
+ import actions from "./actions";
4
+
5
+ export const buildGnosisAction = async (transaction: Transaction, type?: 'source' | 'target') => {
6
+ type = type || transaction.sourceStatus === 'success' ? 'target' : 'source';
7
+
8
+ if (actions.hasOwnProperty(transaction.action)) {
9
+
10
+ const { transactions, logs } = await actions[transaction.action](transaction, type);
11
+
12
+ return {
13
+ data: encodeMulti(transactions).data,
14
+ logs
15
+ };
16
+ }
17
+
18
+ throw new Error(`Unknown action: ${transaction.action}`);
19
+ }
package/src/index.ts CHANGED
@@ -1,21 +1,7 @@
1
- import moduleAlias from 'module-alias';
2
-
3
- moduleAlias.addAliases({
4
- "@/": __dirname + "/",
5
- "@/logger": __dirname + "/logger",
6
- "@/tasks": __dirname + "/tasks",
7
- "@/utils": __dirname + "/utils",
8
- "@/api": __dirname + "/api",
9
- "@/net": __dirname + "/net",
10
- "@/db": __dirname + "/db",
11
- "@/config": __dirname + "/config",
12
- "@/types": __dirname + "/types",
13
- "@/abi": __dirname + "/abi",
14
- "@/constants": __dirname + "/constants",
15
- "@/typechain": __dirname + "/typechain"
16
- })
1
+ import './alias'
2
+ import expandHomeDir from "expand-home-dir";
3
+ import fs from 'fs-extra'
17
4
 
18
- moduleAlias();
19
5
  import dotenv from "dotenv";
20
6
  import chalk from 'chalk';
21
7
  import { ethers } from "ethers";
@@ -25,12 +11,30 @@ dotenv.config();
25
11
  import Logger from "@/logger";
26
12
  const logger = new Logger('Process')
27
13
 
14
+ const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
15
+
28
16
  const printUsage = () => {
17
+ console.log()
18
+ console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
19
+ console.log()
20
+
29
21
  console.log('Usage:')
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')
22
+ console.log(' interop-x help Show this message')
23
+ console.log(' interop-x version Print out the installed version of Interop X')
24
+
25
+ console.log()
26
+
27
+ console.log(' interop-x down Put the node into maintenance mode')
28
+ console.log(' interop-x up Take the node out of maintenance mode')
29
+
30
+ console.log()
31
+
32
+ console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key')
33
+ console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode')
34
+ console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode')
35
+ 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')
36
+ console.log()
37
+
34
38
  }
35
39
 
36
40
  if (process.argv.at(-1) === 'help') {
@@ -38,14 +42,27 @@ if (process.argv.at(-1) === 'help') {
38
42
  process.exit(0)
39
43
  }
40
44
 
41
- const GIT_SHORT_HASH = '@GIT_SHORT_HASH@';
45
+ const basePath = expandHomeDir(`~/.interop-x`);
46
+
47
+ if (process.argv.at(-1) === 'down') {
48
+ fs.outputFileSync(basePath + '/maintenance', Date.now().toString())
49
+ console.log(chalk.red('Maintenance mode enabled'))
50
+ process.exit(0)
51
+ }
52
+
53
+ if (process.argv.at(-1) === 'up') {
54
+ fs.removeSync(basePath + '/maintenance')
55
+ console.log(chalk.green('Maintenance mode disabled'))
56
+ process.exit(0)
57
+ }
58
+
42
59
 
43
60
  if (process.argv.at(-1) === 'version') {
44
61
  console.log(`Interop X Node (v${packageJson.version} - rev.${GIT_SHORT_HASH})`)
45
62
  process.exit(0)
46
63
  }
47
64
 
48
- if(! process.env.PRIVATE_KEY) {
65
+ if (!process.env.PRIVATE_KEY) {
49
66
  console.error(chalk.bgRed.white.bold('Please provide a private key\n'))
50
67
  printUsage()
51
68
  process.exit(1)
@@ -72,7 +89,9 @@ async function main() {
72
89
 
73
90
  const tasks = new Tasks()
74
91
 
75
- tasks.start();
92
+ setTimeout(() => {
93
+ tasks.start();
94
+ }, 10000)
76
95
 
77
96
  startApiServer()
78
97
 
@@ -80,10 +99,10 @@ async function main() {
80
99
  if (!peerPool.isLeadNode(payload.peerId)) {
81
100
  const peer = peerPool.getPeer(payload.peerId)
82
101
 
83
- if(! peer) {
102
+ if (!peer) {
84
103
  return;
85
104
  }
86
-
105
+
87
106
  logger.info(`ignored transaction status from ${payload.peerId} ${shortenHash(peer.publicAddress)} `)
88
107
  return;
89
108
  }
@@ -97,10 +116,12 @@ async function main() {
97
116
  transaction.sourceStatus = payload.data.sourceStatus
98
117
  transaction.sourceTransactionHash = payload.data.sourceTransactionHash
99
118
  transaction.sourceErrors = payload.data.sourceErrors
119
+ transaction.sourceLogs = payload.data.sourceLogs
100
120
 
101
121
  transaction.targetStatus = payload.data.targetStatus
102
122
  transaction.targetTransactionHash = payload.data.targetTransactionHash
103
123
  transaction.targetErrors = payload.data.targetErrors
124
+ transaction.targetLogs = payload.data.targetLogs
104
125
 
105
126
  transaction.status = payload.data.status
106
127
 
@@ -17,6 +17,7 @@ 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";
20
21
 
21
22
  const logger = new Logger("Peer");
22
23
 
@@ -80,7 +81,7 @@ export const startPeer = async ({ }: IPeerOptions) => {
80
81
  },
81
82
  });
82
83
 
83
- logger.info("Peer ID:", node.peerId.toB58String());
84
+ logger.info("Peer ID:", chalk.bold(node.peerId.toB58String()));
84
85
 
85
86
  await node.start();
86
87
 
@@ -3,6 +3,7 @@ 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";
6
7
 
7
8
 
8
9
  const logger = new Logger('PeerPool')
@@ -88,7 +89,7 @@ export class PeerPool {
88
89
 
89
90
  if (newPeer) {
90
91
  config.events.emit(Event.POOL_PEER_ADDED, peer)
91
- logger.info(`Peer ${peer.id} with address ${shortenHash(peer.publicAddress)} added to pool`)
92
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} added to pool`)
92
93
  }
93
94
  }
94
95
  }
@@ -103,7 +104,7 @@ export class PeerPool {
103
104
  if (this.pool.delete(peer.id)) {
104
105
  peer.pooled = false
105
106
  config.events.emit(Event.POOL_PEER_REMOVED, peer)
106
- logger.info(`Peer ${peer.id} with address ${shortenHash(peer.publicAddress)} removed from pool`)
107
+ logger.info(`Peer ${chalk.bold(shortenHash(peer.id, 16))} with address ${chalk.bold(shortenHash(peer.publicAddress))} removed from pool`)
107
108
  }
108
109
  }
109
110
  }
@@ -2,12 +2,13 @@ import { BaseDialProtocol } from "./BaseDialProtocol";
2
2
  import wait from "waait";
3
3
  import config from "@/config";
4
4
  import { Transaction } from "@/db";
5
- import { buildDataForTransaction, signGnosisSafeTx } from "@/utils";
5
+ import { signGnosisSafeTx } from "@/utils";
6
6
  import { addresses } from "@/constants";
7
7
  import { ChainId } from "@/types";
8
+ import { buildGnosisAction } from "@/gnosis";
8
9
 
9
10
  export interface ISignatureRequest {
10
- type: 'source' | 'target' ,
11
+ type: 'source' | 'target',
11
12
  transactionHash: string
12
13
  safeTxGas: string
13
14
  safeNonce: string
@@ -46,18 +47,11 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
46
47
  error: 'Event not found'
47
48
  };
48
49
  }
49
-
50
- console.log("signing:", {
51
- to: addresses[transaction.targetChainId].multisend,
52
- data: await buildDataForTransaction(transaction, data.type),
53
- chainId: transaction.targetChainId as ChainId,
54
- safeTxGas: data.safeTxGas,
55
- nonce: data.safeNonce,
56
- });
50
+ const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
57
51
 
58
52
  const signedData = await signGnosisSafeTx({
59
53
  to: addresses[transaction.targetChainId].multisend,
60
- data: await buildDataForTransaction(transaction, data.type),
54
+ data: gnosisData,
61
55
  chainId: transaction.targetChainId as ChainId,
62
56
  safeTxGas: data.safeTxGas,
63
57
  nonce: data.safeNonce,
@@ -1,7 +1,7 @@
1
1
  import { BaseDialProtocol } from "./BaseDialProtocol";
2
2
  import { Transaction } from "@/db";
3
3
 
4
- export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'> | null> {
4
+ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'> | null> {
5
5
  protected timeout = 30000;
6
6
 
7
7
  constructor(libp2p) {
@@ -20,10 +20,12 @@ export class TransactionStatusDialProtocol extends BaseDialProtocol<string, Pick
20
20
  sourceStatus: transaction.sourceStatus,
21
21
  sourceTransactionHash: transaction.sourceTransactionHash,
22
22
  sourceErrors: transaction.sourceErrors,
23
+ sourceLogs: transaction.sourceLogs,
23
24
 
24
25
  targetStatus: transaction.targetStatus,
25
26
  targetTransactionHash: transaction.targetTransactionHash,
26
27
  targetErrors: transaction.targetErrors,
28
+ targetLogs: transaction.targetLogs,
27
29
 
28
30
  status: transaction.status,
29
31
  }
@@ -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/SignatureDialProtocol.1";
9
+ import { TransactionStatusDialProtocol } from "./dial/TransactionStatusDialProtocol";
10
10
 
11
11
  export interface ProtocolOptions {
12
12
  /* Handshake timeout in ms (default: 8000) */
@@ -36,7 +36,7 @@ interface PeerInfoEvent extends BaseMessageEvent {
36
36
  }
37
37
 
38
38
  interface TransactionStatusEvent extends BaseMessageEvent {
39
- data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'>
39
+ data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'sourceLogs' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'targetLogs' | 'status'>
40
40
  }
41
41
 
42
42
  declare interface Protocol {
@@ -66,25 +66,35 @@ 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
+ transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
71
72
 
72
73
  Buffer.from(transaction.targetStatus),
73
- Buffer.from(transaction.targetTransactionHash),
74
+ Buffer.from(transaction.targetTransactionHash || ''),
74
75
  transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
76
+ transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
75
77
 
76
78
  Buffer.from(transaction.status),
77
79
  ],
78
- decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]: [Buffer, Buffer, Buffer, Buffer[], Buffer, Buffer, Buffer[], Buffer]) => ({
80
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]: [Buffer, Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer, Buffer, Buffer[],[Buffer,Buffer][], Buffer]) => ({
79
81
  transactionHash: transactionHash.toString(),
80
82
 
81
83
  sourceStatus: sourceStatus.toString(),
82
- sourceTransactionHash: sourceTransactionHash.toString(),
84
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
83
85
  sourceErrors: sourceErrors.map((e) => e.toString()),
86
+ sourceLogs: sourceLogs.map(e => ({
87
+ type: e[0].toString(),
88
+ message: e[1].toString(),
89
+ })),
84
90
 
85
91
  targetStatus: targetStatus.toString(),
86
- targetTransactionHash: targetTransactionHash.toString(),
92
+ targetTransactionHash: targetTransactionHash.toString() || null,
87
93
  targetErrors: targetErrors.map((e) => e.toString()),
94
+ targetLogs: targetLogs.map(e => ({
95
+ type: e[0].toString(),
96
+ message: e[1].toString(),
97
+ })),
88
98
 
89
99
  status: status.toString(),
90
100
  }),
@@ -1,12 +1,16 @@
1
1
  import { BaseTask } from "./BaseTask";
2
2
  import Logger from '@/logger';
3
- import { http } from "@/utils";
4
- import spawn from 'await-spawn';
3
+ import spawnAsync from 'await-spawn';
4
+ import { spawn } from 'child_process'
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';
7
11
 
8
12
  class AutoUpdateTask extends BaseTask {
9
- pollIntervalMs: number = 60 * 5 * 1000
13
+ pollIntervalMs: number = 60 * 10 * 1000
10
14
 
11
15
  constructor() {
12
16
  super({
@@ -18,15 +22,28 @@ class AutoUpdateTask extends BaseTask {
18
22
  return config.autoUpdate && !config.isLeadNode();
19
23
  }
20
24
 
21
- getCurrentVersion() {
22
- return require('../../package.json').version
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
+ }
23
33
  }
24
- async pollHandler() {
25
34
 
26
- const { data } = await http.get('https://registry.npmjs.org/@instadapp/interop-x')
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
+ }
27
44
 
28
- const version = data['dist-tags'].latest
29
- const currentVersion = this.getCurrentVersion()
45
+ async pollHandler() {
46
+ const version = await this.getLatestVersion()
30
47
 
31
48
  if (version === currentVersion) {
32
49
  return;
@@ -34,13 +51,13 @@ class AutoUpdateTask extends BaseTask {
34
51
 
35
52
  this.logger.warn(`New version ${version} available.`)
36
53
 
54
+ this.logger.info('Updating...')
37
55
 
38
- await spawn('npm', ['-g', 'install', '@instadapp/interop-x', '-f']);
39
-
56
+ await spawnAsync('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
40
57
 
41
58
  await wait(5000)
42
59
 
43
- if (currentVersion === this.getCurrentVersion()) {
60
+ if (version !== await this.getInstalledVersion()) {
44
61
  this.logger.warn(`failed to install ${version}, retrying in 5 minutes`)
45
62
  return;
46
63
  }
@@ -48,11 +65,16 @@ class AutoUpdateTask extends BaseTask {
48
65
  this.logger.warn(`Installed version ${version}`)
49
66
  this.logger.warn(`Restarting...`)
50
67
 
51
- spawn(process.argv[0], process.argv.slice(1), {
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), {
52
71
  cwd: process.cwd(),
53
- stdio: "inherit"
72
+ stdio: "inherit",
73
+ // shell: process.env.SHELL,
54
74
  });
55
75
 
76
+ subprocess.unref();
77
+
56
78
  process.exit()
57
79
  }
58
80
  }
@@ -46,6 +46,11 @@ export class BaseTask extends EventEmitter implements IBaseTask {
46
46
  }
47
47
 
48
48
  prePollHandler(): boolean {
49
+ if(config.isMaintenanceMode()){
50
+ this.logger.warn('Maintenance mode is enabled. Skipping task.')
51
+ return false
52
+ }
53
+
49
54
  if (this.exceptLeadNode) {
50
55
  return !config.isLeadNode();
51
56
  }