@clonegod/ttd-base-common 1.0.14 → 1.0.16
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,11 @@
|
|
|
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
|
+
private initWsConnection;
|
|
8
|
+
sendTransaction(signedTx: string): Promise<string>;
|
|
9
|
+
private sendTransactionByHttp;
|
|
10
|
+
private sendTransactionByWs;
|
|
7
11
|
}
|
|
@@ -17,17 +17,51 @@ 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';
|
|
23
|
+
this.initWsConnection();
|
|
22
24
|
}
|
|
23
|
-
|
|
25
|
+
initWsConnection() {
|
|
26
|
+
if (!this.wsClient) {
|
|
27
|
+
this.wsClient = new dist_1.WebSocketClient(this.ws_endpoint, {
|
|
28
|
+
headers: {
|
|
29
|
+
'Authorization': this.authToken || ''
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
this.wsClient.onOpen(() => {
|
|
33
|
+
console.log('BloXroute Base ws connected:', this.ws_endpoint);
|
|
34
|
+
});
|
|
35
|
+
this.wsClient.onMessage((message) => {
|
|
36
|
+
console.log('BloXroute Base ws message', message);
|
|
37
|
+
});
|
|
38
|
+
this.wsClient.connect();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
sendTransaction(signedTx) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
if (!this.authToken) {
|
|
44
|
+
(0, dist_1.log_warn)('BloXroute Base authToken is not set!!! BASE_BLOXROUTE_AUTH_TOKEN is empty or null');
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
if (signedTx.startsWith('0x')) {
|
|
48
|
+
signedTx = signedTx.slice(2);
|
|
49
|
+
}
|
|
50
|
+
this.sendTransactionByWs(signedTx);
|
|
51
|
+
return yield this.sendTransactionByHttp(signedTx);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
sendTransactionByHttp(signedTx) {
|
|
24
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
56
|
try {
|
|
26
57
|
const response = yield axios_1.default.post(this.endpoint, {
|
|
27
58
|
jsonrpc: "2.0",
|
|
28
59
|
id: "1",
|
|
29
|
-
method: "
|
|
30
|
-
params:
|
|
60
|
+
method: "blxr_tx",
|
|
61
|
+
params: {
|
|
62
|
+
"transaction": signedTx,
|
|
63
|
+
"blockchain_network": "Base-Mainnet"
|
|
64
|
+
}
|
|
31
65
|
}, {
|
|
32
66
|
headers: {
|
|
33
67
|
'Content-Type': 'application/json',
|
|
@@ -38,7 +72,7 @@ class BloxrouteBase {
|
|
|
38
72
|
if (response.data.error) {
|
|
39
73
|
throw new Error(`BloXroute Base Error: ${response.data.error.code} - ${response.data.error.message}`);
|
|
40
74
|
}
|
|
41
|
-
return response.data.result;
|
|
75
|
+
return response.data.result.txHash;
|
|
42
76
|
}
|
|
43
77
|
catch (error) {
|
|
44
78
|
(0, dist_1.log_error)('BloXroute Base sendPrivateTransaction failed!!!', error);
|
|
@@ -46,36 +80,29 @@ class BloxrouteBase {
|
|
|
46
80
|
}
|
|
47
81
|
});
|
|
48
82
|
}
|
|
49
|
-
|
|
83
|
+
sendTransactionByWs(signedTx) {
|
|
50
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
if (!this.ws_endpoint) {
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
51
88
|
try {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
89
|
+
if (!this.wsClient || !this.wsClient.isConnected()) {
|
|
90
|
+
(0, dist_1.log_warn)('BloXroute Base ws is not connected!!!');
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
this.wsClient.send(JSON.stringify({
|
|
55
94
|
jsonrpc: "2.0",
|
|
56
95
|
id: "1",
|
|
57
|
-
method: "
|
|
58
|
-
params:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, {
|
|
65
|
-
headers: {
|
|
66
|
-
'Content-Type': 'application/json',
|
|
67
|
-
'Authorization': this.authToken
|
|
68
|
-
},
|
|
69
|
-
timeout: 3000
|
|
70
|
-
});
|
|
71
|
-
if (response.data.error) {
|
|
72
|
-
throw new Error(`BloXroute Base Bundle Error: ${response.data.error.code} - ${response.data.error.message}`);
|
|
73
|
-
}
|
|
74
|
-
return response.data.result.bundleHash;
|
|
96
|
+
method: "blxr_tx",
|
|
97
|
+
params: {
|
|
98
|
+
"transaction": signedTx,
|
|
99
|
+
"blockchain_network": "Base-Mainnet"
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
return '';
|
|
75
103
|
}
|
|
76
104
|
catch (error) {
|
|
77
|
-
(0, dist_1.log_error)('BloXroute Base
|
|
78
|
-
throw error;
|
|
105
|
+
(0, dist_1.log_error)('BloXroute Base sendTransactionByWs failed!!!', error);
|
|
79
106
|
}
|
|
80
107
|
});
|
|
81
108
|
}
|
|
@@ -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.16",
|
|
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"
|