@instadapp/interop-x 0.0.0-dev.c3250d9 → 0.0.0-dev.eb2b141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +3 -3
- package/dist/src/index.js +17 -6
- package/dist/src/net/pool/index.js +3 -0
- package/dist/src/net/protocol/index.js +2 -2
- package/dist/src/utils/index.js +5 -0
- package/package.json +3 -3
- package/src/index.ts +17 -6
- package/src/net/pool/index.ts +4 -0
- package/src/net/protocol/index.ts +4 -4
- package/src/utils/index.ts +6 -0
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instadapp/interop-x",
|
3
|
-
"version": "0.0.0-dev.
|
3
|
+
"version": "0.0.0-dev.eb2b141",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -46,6 +46,8 @@
|
|
46
46
|
"libp2p-websockets": "^0.16.2",
|
47
47
|
"luxon": "^2.3.2",
|
48
48
|
"module-alias": "^2.2.2",
|
49
|
+
"patch-package": "^6.4.7",
|
50
|
+
"postinstall-postinstall": "^2.1.0",
|
49
51
|
"sequelize": "6.18.0",
|
50
52
|
"sqlite3": "^5.0.5",
|
51
53
|
"waait": "^1.0.5"
|
@@ -60,8 +62,6 @@
|
|
60
62
|
"@types/fs-extra": "^9.0.13",
|
61
63
|
"@types/node": "^17.0.17",
|
62
64
|
"nodemon": "^2.0.15",
|
63
|
-
"patch-package": "^6.4.7",
|
64
|
-
"postinstall-postinstall": "^2.1.0",
|
65
65
|
"replace-in-file": "^6.3.2",
|
66
66
|
"rimraf": "^3.0.2",
|
67
67
|
"ts-node": "^10.5.0",
|
package/dist/src/index.js
CHANGED
@@ -19,28 +19,37 @@ module_alias_1.default.addAliases({
|
|
19
19
|
"@/typechain": __dirname + "/typechain"
|
20
20
|
});
|
21
21
|
(0, module_alias_1.default)();
|
22
|
-
const assert_1 = __importDefault(require("assert"));
|
23
22
|
const dotenv_1 = __importDefault(require("dotenv"));
|
23
|
+
const chalk_1 = __importDefault(require("chalk"));
|
24
24
|
const ethers_1 = require("ethers");
|
25
25
|
const package_json_1 = __importDefault(require("../package.json"));
|
26
26
|
dotenv_1.default.config();
|
27
27
|
const logger_1 = __importDefault(require("@/logger"));
|
28
28
|
const logger = new logger_1.default('Process');
|
29
|
-
|
29
|
+
const printUsage = () => {
|
30
30
|
console.log('Usage:');
|
31
31
|
console.log(' PRIVATE_KEY=abcd1234 interop-x');
|
32
32
|
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x');
|
33
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x');
|
34
|
+
};
|
35
|
+
if (process.argv.at(-1) === 'help') {
|
36
|
+
printUsage();
|
33
37
|
process.exit(0);
|
34
38
|
}
|
35
|
-
|
39
|
+
if (!process.env.PRIVATE_KEY) {
|
40
|
+
console.error(chalk_1.default.bgRed.white('Please provide a private key\n'));
|
41
|
+
printUsage();
|
42
|
+
process.exit(1);
|
43
|
+
}
|
36
44
|
try {
|
37
45
|
new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY);
|
38
46
|
}
|
39
47
|
catch (e) {
|
40
|
-
|
48
|
+
console.error(chalk_1.default.bgRed.white('Invalid private key\n'));
|
49
|
+
printUsage();
|
41
50
|
process.exit(1);
|
42
51
|
}
|
43
|
-
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.
|
52
|
+
logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.eb2b141)`);
|
44
53
|
const tasks_1 = require("@/tasks");
|
45
54
|
const net_1 = require("@/net");
|
46
55
|
const api_1 = require("@/api");
|
@@ -50,8 +59,10 @@ async function main() {
|
|
50
59
|
const tasks = new tasks_1.Tasks();
|
51
60
|
tasks.start();
|
52
61
|
(0, api_1.startApiServer)();
|
53
|
-
net_1.protocol.on('
|
62
|
+
net_1.protocol.on('TransactionStatus', async (payload) => {
|
54
63
|
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
64
|
+
const peer = net_1.peerPool.getPeer(payload.peerId);
|
65
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${peer === null || peer === void 0 ? void 0 : peer.publicAddress} `);
|
55
66
|
return;
|
56
67
|
}
|
57
68
|
const transaction = await db_1.Transaction.findOne({ where: { transactionHash: payload.data.transactionHash } });
|
@@ -25,7 +25,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
25
25
|
}),
|
26
26
|
},
|
27
27
|
{
|
28
|
-
name: '
|
28
|
+
name: 'TransactionStatus',
|
29
29
|
code: 0x02,
|
30
30
|
encode: (transaction) => [
|
31
31
|
Buffer.from(transaction.transactionHash),
|
@@ -100,7 +100,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
100
100
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
101
101
|
}
|
102
102
|
sendTransaction(transaction) {
|
103
|
-
const message = this.protocolMessages.find((m) => m.name === '
|
103
|
+
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
|
104
104
|
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
|
105
105
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
106
106
|
}
|
package/dist/src/utils/index.js
CHANGED
@@ -185,6 +185,11 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
185
185
|
throw Error(`Invalid 'address' parameter '${address}'.`);
|
186
186
|
}
|
187
187
|
const contract = new ethers_1.ethers.Contract(address, contractInterface, signerOrProvider);
|
188
|
+
// Make sure the contract properties is writable
|
189
|
+
const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
|
190
|
+
if (!desc || desc.writable !== true) {
|
191
|
+
return contract;
|
192
|
+
}
|
188
193
|
return new Proxy(contract, {
|
189
194
|
get(target, prop, receiver) {
|
190
195
|
const value = Reflect.get(target, prop, receiver);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instadapp/interop-x",
|
3
|
-
"version": "0.0.0-dev.
|
3
|
+
"version": "0.0.0-dev.eb2b141",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -46,6 +46,8 @@
|
|
46
46
|
"libp2p-websockets": "^0.16.2",
|
47
47
|
"luxon": "^2.3.2",
|
48
48
|
"module-alias": "^2.2.2",
|
49
|
+
"patch-package": "^6.4.7",
|
50
|
+
"postinstall-postinstall": "^2.1.0",
|
49
51
|
"sequelize": "6.18.0",
|
50
52
|
"sqlite3": "^5.0.5",
|
51
53
|
"waait": "^1.0.5"
|
@@ -60,8 +62,6 @@
|
|
60
62
|
"@types/fs-extra": "^9.0.13",
|
61
63
|
"@types/node": "^17.0.17",
|
62
64
|
"nodemon": "^2.0.15",
|
63
|
-
"patch-package": "^6.4.7",
|
64
|
-
"postinstall-postinstall": "^2.1.0",
|
65
65
|
"replace-in-file": "^6.3.2",
|
66
66
|
"rimraf": "^3.0.2",
|
67
67
|
"ts-node": "^10.5.0",
|
package/src/index.ts
CHANGED
@@ -16,8 +16,8 @@ moduleAlias.addAliases({
|
|
16
16
|
})
|
17
17
|
|
18
18
|
moduleAlias();
|
19
|
-
import assert from "assert";
|
20
19
|
import dotenv from "dotenv";
|
20
|
+
import chalk from 'chalk';
|
21
21
|
import { ethers } from "ethers";
|
22
22
|
import packageJson from '../package.json'
|
23
23
|
dotenv.config();
|
@@ -25,20 +25,29 @@ dotenv.config();
|
|
25
25
|
import Logger from "@/logger";
|
26
26
|
const logger = new Logger('Process')
|
27
27
|
|
28
|
-
|
29
|
-
if (process.argv.at(-1) === 'help') {
|
28
|
+
const printUsage = () => {
|
30
29
|
console.log('Usage:')
|
31
30
|
console.log(' PRIVATE_KEY=abcd1234 interop-x')
|
32
31
|
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x')
|
32
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x')
|
33
|
+
}
|
34
|
+
|
35
|
+
if (process.argv.at(-1) === 'help') {
|
36
|
+
printUsage()
|
33
37
|
process.exit(0)
|
34
38
|
}
|
35
39
|
|
36
|
-
assert(process.env.PRIVATE_KEY, "PRIVATE_KEY is not defined");
|
37
40
|
|
41
|
+
if(! process.env.PRIVATE_KEY) {
|
42
|
+
console.error(chalk.bgRed.white('Please provide a private key\n'))
|
43
|
+
printUsage()
|
44
|
+
process.exit(1)
|
45
|
+
}
|
38
46
|
try {
|
39
47
|
new ethers.Wallet(process.env.PRIVATE_KEY!)
|
40
48
|
} catch (e) {
|
41
|
-
|
49
|
+
console.error(chalk.bgRed.white('Invalid private key\n'))
|
50
|
+
printUsage()
|
42
51
|
process.exit(1)
|
43
52
|
}
|
44
53
|
|
@@ -59,8 +68,10 @@ async function main() {
|
|
59
68
|
|
60
69
|
startApiServer()
|
61
70
|
|
62
|
-
protocol.on('
|
71
|
+
protocol.on('TransactionStatus', async (payload) => {
|
63
72
|
if (!peerPool.isLeadNode(payload.peerId)) {
|
73
|
+
const peer = peerPool.getPeer(payload.peerId)
|
74
|
+
logger.info(`ignored transaction status from ${payload.peerId} ${peer?.publicAddress} `)
|
64
75
|
return;
|
65
76
|
}
|
66
77
|
|
package/src/net/pool/index.ts
CHANGED
@@ -34,12 +34,12 @@ interface PeerInfoEvent extends BaseMessageEvent {
|
|
34
34
|
data: Omit<IPeerInfo, 'id' | 'updated' | 'idle' | 'pooled'>
|
35
35
|
}
|
36
36
|
|
37
|
-
interface
|
37
|
+
interface TransactionStatusEvent extends BaseMessageEvent {
|
38
38
|
data: Pick<Transaction, 'transactionHash' | 'sourceStatus' | 'sourceTransactionHash' | 'sourceErrors' | 'targetStatus' | 'targetTransactionHash' | 'targetErrors' | 'status'>
|
39
39
|
}
|
40
40
|
|
41
41
|
declare interface Protocol {
|
42
|
-
on(event: '
|
42
|
+
on(event: 'TransactionStatus', listener: (payload: TransactionStatusEvent) => void): this;
|
43
43
|
on(event: 'PeerInfo', listener: (payload: PeerInfoEvent) => void): this;
|
44
44
|
on(event: string, listener: (payload: BaseMessageEvent) => void): this;
|
45
45
|
}
|
@@ -59,7 +59,7 @@ class Protocol extends EventEmitter {
|
|
59
59
|
}),
|
60
60
|
},
|
61
61
|
{
|
62
|
-
name: '
|
62
|
+
name: 'TransactionStatus',
|
63
63
|
code: 0x02,
|
64
64
|
encode: (transaction: Transaction) => [
|
65
65
|
Buffer.from(transaction.transactionHash),
|
@@ -158,7 +158,7 @@ class Protocol extends EventEmitter {
|
|
158
158
|
}
|
159
159
|
|
160
160
|
public sendTransaction(transaction: Transaction) {
|
161
|
-
const message = this.protocolMessages.find((m) => m.name === '
|
161
|
+
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus')!
|
162
162
|
|
163
163
|
const encoded = rlp.encode([message.code, message.encode(transaction)]);
|
164
164
|
|
package/src/utils/index.ts
CHANGED
@@ -259,6 +259,12 @@ export function getContract<TContract extends ethers.Contract>(address: string,
|
|
259
259
|
signerOrProvider
|
260
260
|
) as TContract
|
261
261
|
|
262
|
+
// Make sure the contract properties is writable
|
263
|
+
const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
|
264
|
+
|
265
|
+
if (!desc || desc.writable !== true) {
|
266
|
+
return contract
|
267
|
+
}
|
262
268
|
|
263
269
|
return new Proxy(contract, {
|
264
270
|
get(target, prop, receiver) {
|