@clonegod/ttd-base-common 1.0.14 → 1.0.15
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.
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare class BloxrouteBase {
|
|
2
2
|
private endpoint;
|
|
3
3
|
private authToken;
|
|
4
|
+
private ws_endpoint;
|
|
5
|
+
private wsClient;
|
|
4
6
|
constructor();
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
sendTransaction(signedTx: string): Promise<string>;
|
|
8
|
+
private sendTransactionByWs;
|
|
9
|
+
private sendTransactionByHttp;
|
|
7
10
|
}
|
|
@@ -17,50 +17,71 @@ const dist_1 = require("@clonegod/ttd-core/dist");
|
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
18
|
class BloxrouteBase {
|
|
19
19
|
constructor() {
|
|
20
|
-
this.endpoint = process.env.BASE_BLOXROUTE_RPC_ENDPOINT || '';
|
|
20
|
+
this.endpoint = process.env.BASE_BLOXROUTE_RPC_ENDPOINT || 'https://api.blxrbdn.com';
|
|
21
21
|
this.authToken = process.env.BASE_BLOXROUTE_AUTH_TOKEN || '';
|
|
22
|
+
this.ws_endpoint = process.env.BASE_BLOXROUTE_WS_ENDPOINT || 'wss://api.blxrbdn.com/ws';
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
sendTransaction(signedTx) {
|
|
24
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!this.authToken) {
|
|
27
|
+
(0, dist_1.log_warn)('BloXroute Base authToken is not set!!! BASE_BLOXROUTE_AUTH_TOKEN is empty or null');
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
if (signedTx.startsWith('0x')) {
|
|
31
|
+
signedTx = signedTx.slice(2);
|
|
32
|
+
}
|
|
33
|
+
this.sendTransactionByWs(signedTx);
|
|
34
|
+
return yield this.sendTransactionByHttp(signedTx);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
sendTransactionByWs(signedTx) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (!this.ws_endpoint) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
25
42
|
try {
|
|
26
|
-
|
|
43
|
+
if (!this.wsClient) {
|
|
44
|
+
this.wsClient = new dist_1.WebSocketClient(this.ws_endpoint, {
|
|
45
|
+
headers: {
|
|
46
|
+
'Authorization': this.authToken || ''
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
this.wsClient.onMessage((message) => {
|
|
50
|
+
console.log('BloXroute Base ws message', message);
|
|
51
|
+
});
|
|
52
|
+
this.wsClient.connect();
|
|
53
|
+
}
|
|
54
|
+
if (!this.wsClient.isConnected()) {
|
|
55
|
+
(0, dist_1.log_warn)('BloXroute Base ws is not connected!!!');
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
this.wsClient.send(JSON.stringify({
|
|
27
59
|
jsonrpc: "2.0",
|
|
28
60
|
id: "1",
|
|
29
|
-
method: "
|
|
30
|
-
params:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
timeout: 3000
|
|
37
|
-
});
|
|
38
|
-
if (response.data.error) {
|
|
39
|
-
throw new Error(`BloXroute Base Error: ${response.data.error.code} - ${response.data.error.message}`);
|
|
40
|
-
}
|
|
41
|
-
return response.data.result;
|
|
61
|
+
method: "blxr_tx",
|
|
62
|
+
params: {
|
|
63
|
+
"transaction": signedTx,
|
|
64
|
+
"blockchain_network": "Base-Mainnet"
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
return '';
|
|
42
68
|
}
|
|
43
69
|
catch (error) {
|
|
44
|
-
(0, dist_1.log_error)('BloXroute Base
|
|
45
|
-
throw error;
|
|
70
|
+
(0, dist_1.log_error)('BloXroute Base sendTransactionByWs failed!!!', error);
|
|
46
71
|
}
|
|
47
72
|
});
|
|
48
73
|
}
|
|
49
|
-
|
|
74
|
+
sendTransactionByHttp(signedTx) {
|
|
50
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
76
|
try {
|
|
52
|
-
const currentBlock = targetBlockNumber || Math.floor(Date.now() / 1000);
|
|
53
|
-
const targetBlock = currentBlock + 1;
|
|
54
77
|
const response = yield axios_1.default.post(this.endpoint, {
|
|
55
78
|
jsonrpc: "2.0",
|
|
56
79
|
id: "1",
|
|
57
|
-
method: "
|
|
58
|
-
params:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
maxTimestamp: Math.floor(Date.now() / 1000) + 30
|
|
63
|
-
}]
|
|
80
|
+
method: "blxr_tx",
|
|
81
|
+
params: {
|
|
82
|
+
"transaction": signedTx,
|
|
83
|
+
"blockchain_network": "Base-Mainnet"
|
|
84
|
+
}
|
|
64
85
|
}, {
|
|
65
86
|
headers: {
|
|
66
87
|
'Content-Type': 'application/json',
|
|
@@ -69,12 +90,12 @@ class BloxrouteBase {
|
|
|
69
90
|
timeout: 3000
|
|
70
91
|
});
|
|
71
92
|
if (response.data.error) {
|
|
72
|
-
throw new Error(`BloXroute Base
|
|
93
|
+
throw new Error(`BloXroute Base Error: ${response.data.error.code} - ${response.data.error.message}`);
|
|
73
94
|
}
|
|
74
|
-
return response.data.result.
|
|
95
|
+
return response.data.result.tx_hash;
|
|
75
96
|
}
|
|
76
97
|
catch (error) {
|
|
77
|
-
(0, dist_1.log_error)('BloXroute Base
|
|
98
|
+
(0, dist_1.log_error)('BloXroute Base sendPrivateTransaction failed!!!', error);
|
|
78
99
|
throw error;
|
|
79
100
|
}
|
|
80
101
|
});
|
|
@@ -120,9 +120,9 @@ class BaseTransactionSender {
|
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
122
|
name: 'BloXroute - Private Transaction',
|
|
123
|
-
enable: process.env.
|
|
123
|
+
enable: process.env.SEND_TX_BLOXROUTE_RPC === 'true',
|
|
124
124
|
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
return yield this.bloxroute.
|
|
125
|
+
return yield this.bloxroute.sendTransaction(signedMainTx);
|
|
126
126
|
})
|
|
127
127
|
}
|
|
128
128
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-base-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "Base common library",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"push": "npm run build && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@clonegod/ttd-core": "2.0.
|
|
17
|
+
"@clonegod/ttd-core": "2.0.85",
|
|
18
18
|
"axios": "^1.11.00",
|
|
19
19
|
"dotenv": "^16.4.7",
|
|
20
20
|
"ethers": "^5.8.0"
|