@develit-services/blockchain 0.8.0 → 0.8.2
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/export/worker.cjs +567 -11
- package/dist/export/worker.d.cts +2 -1
- package/dist/export/worker.d.mts +2 -1
- package/dist/export/worker.d.ts +2 -1
- package/dist/export/worker.mjs +567 -11
- package/dist/shared/blockchain.5Ld6uEay.d.ts +138 -0
- package/dist/shared/blockchain.BBjLLe8v.cjs +95 -0
- package/dist/shared/blockchain.CtIjPvX8.d.cts +138 -0
- package/dist/shared/blockchain.DTJULMBV.mjs +87 -0
- package/dist/shared/blockchain.DZbyq0JM.d.mts +138 -0
- package/dist/types.cjs +4 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/types.mjs +1 -1
- package/package.json +1 -1
- package/dist/shared/blockchain.4Hzh__vM.d.ts +0 -61
- package/dist/shared/blockchain.B49xpPZ0.cjs +0 -36
- package/dist/shared/blockchain.BDDFE27V.d.mts +0 -61
- package/dist/shared/blockchain.B_Tqqlia.mjs +0 -31
- package/dist/shared/blockchain.DbsOmkkX.d.cts +0 -61
package/dist/export/worker.cjs
CHANGED
|
@@ -3,25 +3,370 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const backendSdk = require('@develit-io/backend-sdk');
|
|
6
|
-
const viem = require('viem');
|
|
7
6
|
const drizzle = require('../shared/blockchain.DN735AwB.cjs');
|
|
8
|
-
const syncAddress = require('../shared/blockchain.
|
|
7
|
+
const syncAddress = require('../shared/blockchain.BBjLLe8v.cjs');
|
|
9
8
|
const cloudflare_workers = require('cloudflare:workers');
|
|
10
9
|
const d1 = require('drizzle-orm/d1');
|
|
10
|
+
const viem = require('viem');
|
|
11
11
|
require('../shared/blockchain.BBvwu2_7.cjs');
|
|
12
12
|
require('drizzle-orm/sqlite-core');
|
|
13
13
|
require('drizzle-orm');
|
|
14
14
|
require('zod');
|
|
15
15
|
|
|
16
16
|
class IBlockchainConnector {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.rpcUrl = "";
|
|
19
|
+
}
|
|
20
|
+
get rpcSecretName() {
|
|
21
|
+
return `BLOCKCHAIN_SERVICE_${this.connectorKey}_RPC_URL`;
|
|
22
|
+
}
|
|
23
|
+
init(rpcUrl) {
|
|
24
|
+
this.rpcUrl = rpcUrl;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class ArbitrumConnector extends IBlockchainConnector {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.connectorKey = "ARBITRUM";
|
|
33
|
+
this.client = null;
|
|
34
|
+
}
|
|
35
|
+
createClient() {
|
|
36
|
+
if (!this.client) {
|
|
37
|
+
this.client = viem.createPublicClient({
|
|
38
|
+
transport: viem.http(this.rpcUrl)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return this.client;
|
|
42
|
+
}
|
|
43
|
+
async getTransaction(txHash) {
|
|
44
|
+
const client = this.createClient();
|
|
45
|
+
const [tx, txError] = await backendSdk.useResult(
|
|
46
|
+
client.getTransaction({ hash: txHash })
|
|
47
|
+
);
|
|
48
|
+
if (txError || !tx) {
|
|
49
|
+
throw backendSdk.createInternalError(txError);
|
|
50
|
+
}
|
|
51
|
+
let status = "pending";
|
|
52
|
+
let gasUsed = null;
|
|
53
|
+
let timestamp = null;
|
|
54
|
+
if (tx.blockNumber) {
|
|
55
|
+
const [receipt, receiptError] = await backendSdk.useResult(
|
|
56
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
57
|
+
);
|
|
58
|
+
if (receiptError || !receipt) {
|
|
59
|
+
throw backendSdk.createInternalError(receiptError);
|
|
60
|
+
}
|
|
61
|
+
const [block, blockError] = await backendSdk.useResult(
|
|
62
|
+
client.getBlock({ blockNumber: tx.blockNumber })
|
|
63
|
+
);
|
|
64
|
+
if (blockError || !block) {
|
|
65
|
+
throw backendSdk.createInternalError(blockError);
|
|
66
|
+
}
|
|
67
|
+
status = receipt.status === "success" ? "success" : "reverted";
|
|
68
|
+
gasUsed = receipt.gasUsed.toString();
|
|
69
|
+
timestamp = Number(block.timestamp) * 1e3;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
hash: tx.hash,
|
|
73
|
+
from: tx.from,
|
|
74
|
+
to: tx.to,
|
|
75
|
+
value: tx.value.toString(),
|
|
76
|
+
blockNumber: tx.blockNumber?.toString() ?? null,
|
|
77
|
+
blockHash: tx.blockHash ?? null,
|
|
78
|
+
gasPrice: tx.gasPrice?.toString() ?? null,
|
|
79
|
+
gas: tx.gas.toString(),
|
|
80
|
+
nonce: tx.nonce,
|
|
81
|
+
transactionIndex: tx.transactionIndex,
|
|
82
|
+
status,
|
|
83
|
+
gasUsed,
|
|
84
|
+
timestamp
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async getTransactionReceipt(txHash) {
|
|
88
|
+
const client = this.createClient();
|
|
89
|
+
const [receipt, error] = await backendSdk.useResult(
|
|
90
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
91
|
+
);
|
|
92
|
+
if (error || !receipt) {
|
|
93
|
+
throw backendSdk.createInternalError(error);
|
|
94
|
+
}
|
|
95
|
+
return receipt;
|
|
96
|
+
}
|
|
97
|
+
async getBlock({
|
|
98
|
+
blockHash,
|
|
99
|
+
blockNumber,
|
|
100
|
+
blockTag
|
|
101
|
+
}) {
|
|
102
|
+
const client = this.createClient();
|
|
103
|
+
const [block, error] = await backendSdk.useResult(
|
|
104
|
+
blockHash !== void 0 ? client.getBlock({ blockHash }) : blockNumber !== void 0 ? client.getBlock({ blockNumber }) : client.getBlock({ blockTag: blockTag ?? "finalized" })
|
|
105
|
+
);
|
|
106
|
+
if (error || !block) {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
return block;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class AvalancheConnector extends IBlockchainConnector {
|
|
114
|
+
constructor() {
|
|
115
|
+
super(...arguments);
|
|
116
|
+
this.connectorKey = "AVALANCHE";
|
|
117
|
+
this.client = null;
|
|
118
|
+
}
|
|
119
|
+
createClient() {
|
|
120
|
+
if (!this.client) {
|
|
121
|
+
this.client = viem.createPublicClient({
|
|
122
|
+
transport: viem.http(this.rpcUrl)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return this.client;
|
|
126
|
+
}
|
|
127
|
+
async getTransaction(txHash) {
|
|
128
|
+
const client = this.createClient();
|
|
129
|
+
const [tx, txError] = await backendSdk.useResult(
|
|
130
|
+
client.getTransaction({ hash: txHash })
|
|
131
|
+
);
|
|
132
|
+
if (txError || !tx) {
|
|
133
|
+
throw backendSdk.createInternalError(txError);
|
|
134
|
+
}
|
|
135
|
+
let status = "pending";
|
|
136
|
+
let gasUsed = null;
|
|
137
|
+
let timestamp = null;
|
|
138
|
+
if (tx.blockNumber) {
|
|
139
|
+
const [receipt, receiptError] = await backendSdk.useResult(
|
|
140
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
141
|
+
);
|
|
142
|
+
if (receiptError || !receipt) {
|
|
143
|
+
throw backendSdk.createInternalError(receiptError);
|
|
144
|
+
}
|
|
145
|
+
const [block, blockError] = await backendSdk.useResult(
|
|
146
|
+
client.getBlock({ blockNumber: tx.blockNumber })
|
|
147
|
+
);
|
|
148
|
+
if (blockError || !block) {
|
|
149
|
+
throw backendSdk.createInternalError(blockError);
|
|
150
|
+
}
|
|
151
|
+
status = receipt.status === "success" ? "success" : "reverted";
|
|
152
|
+
gasUsed = receipt.gasUsed.toString();
|
|
153
|
+
timestamp = Number(block.timestamp) * 1e3;
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
hash: tx.hash,
|
|
157
|
+
from: tx.from,
|
|
158
|
+
to: tx.to,
|
|
159
|
+
value: tx.value.toString(),
|
|
160
|
+
blockNumber: tx.blockNumber?.toString() ?? null,
|
|
161
|
+
blockHash: tx.blockHash ?? null,
|
|
162
|
+
gasPrice: tx.gasPrice?.toString() ?? null,
|
|
163
|
+
gas: tx.gas.toString(),
|
|
164
|
+
nonce: tx.nonce,
|
|
165
|
+
transactionIndex: tx.transactionIndex,
|
|
166
|
+
status,
|
|
167
|
+
gasUsed,
|
|
168
|
+
timestamp
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async getTransactionReceipt(txHash) {
|
|
172
|
+
const client = this.createClient();
|
|
173
|
+
const [receipt, error] = await backendSdk.useResult(
|
|
174
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
175
|
+
);
|
|
176
|
+
if (error || !receipt) {
|
|
177
|
+
throw backendSdk.createInternalError(error);
|
|
178
|
+
}
|
|
179
|
+
return receipt;
|
|
180
|
+
}
|
|
181
|
+
async getBlock({
|
|
182
|
+
blockHash,
|
|
183
|
+
blockNumber,
|
|
184
|
+
blockTag
|
|
185
|
+
}) {
|
|
186
|
+
const client = this.createClient();
|
|
187
|
+
const [block, error] = await backendSdk.useResult(
|
|
188
|
+
blockHash !== void 0 ? client.getBlock({ blockHash }) : blockNumber !== void 0 ? client.getBlock({ blockNumber }) : client.getBlock({ blockTag: blockTag ?? "finalized" })
|
|
189
|
+
);
|
|
190
|
+
if (error || !block) {
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
return block;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class BaseConnector extends IBlockchainConnector {
|
|
198
|
+
constructor() {
|
|
199
|
+
super(...arguments);
|
|
200
|
+
this.connectorKey = "BASE";
|
|
201
|
+
this.client = null;
|
|
202
|
+
}
|
|
203
|
+
createClient() {
|
|
204
|
+
if (!this.client) {
|
|
205
|
+
this.client = viem.createPublicClient({
|
|
206
|
+
transport: viem.http(this.rpcUrl)
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return this.client;
|
|
210
|
+
}
|
|
211
|
+
async getTransaction(txHash) {
|
|
212
|
+
const client = this.createClient();
|
|
213
|
+
const [tx, txError] = await backendSdk.useResult(
|
|
214
|
+
client.getTransaction({ hash: txHash })
|
|
215
|
+
);
|
|
216
|
+
if (txError || !tx) {
|
|
217
|
+
throw backendSdk.createInternalError(txError);
|
|
218
|
+
}
|
|
219
|
+
let status = "pending";
|
|
220
|
+
let gasUsed = null;
|
|
221
|
+
let timestamp = null;
|
|
222
|
+
if (tx.blockNumber) {
|
|
223
|
+
const [receipt, receiptError] = await backendSdk.useResult(
|
|
224
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
225
|
+
);
|
|
226
|
+
if (receiptError || !receipt) {
|
|
227
|
+
throw backendSdk.createInternalError(receiptError);
|
|
228
|
+
}
|
|
229
|
+
const [block, blockError] = await backendSdk.useResult(
|
|
230
|
+
client.getBlock({ blockNumber: tx.blockNumber })
|
|
231
|
+
);
|
|
232
|
+
if (blockError || !block) {
|
|
233
|
+
throw backendSdk.createInternalError(blockError);
|
|
234
|
+
}
|
|
235
|
+
status = receipt.status === "success" ? "success" : "reverted";
|
|
236
|
+
gasUsed = receipt.gasUsed.toString();
|
|
237
|
+
timestamp = Number(block.timestamp) * 1e3;
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
hash: tx.hash,
|
|
241
|
+
from: tx.from,
|
|
242
|
+
to: tx.to,
|
|
243
|
+
value: tx.value.toString(),
|
|
244
|
+
blockNumber: tx.blockNumber?.toString() ?? null,
|
|
245
|
+
blockHash: tx.blockHash ?? null,
|
|
246
|
+
gasPrice: tx.gasPrice?.toString() ?? null,
|
|
247
|
+
gas: tx.gas.toString(),
|
|
248
|
+
nonce: tx.nonce,
|
|
249
|
+
transactionIndex: tx.transactionIndex,
|
|
250
|
+
status,
|
|
251
|
+
gasUsed,
|
|
252
|
+
timestamp
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
async getTransactionReceipt(txHash) {
|
|
256
|
+
const client = this.createClient();
|
|
257
|
+
const [receipt, error] = await backendSdk.useResult(
|
|
258
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
259
|
+
);
|
|
260
|
+
if (error || !receipt) {
|
|
261
|
+
throw backendSdk.createInternalError(error);
|
|
262
|
+
}
|
|
263
|
+
return receipt;
|
|
264
|
+
}
|
|
265
|
+
async getBlock({
|
|
266
|
+
blockHash,
|
|
267
|
+
blockNumber,
|
|
268
|
+
blockTag
|
|
269
|
+
}) {
|
|
270
|
+
const client = this.createClient();
|
|
271
|
+
const [block, error] = await backendSdk.useResult(
|
|
272
|
+
blockHash !== void 0 ? client.getBlock({ blockHash }) : blockNumber !== void 0 ? client.getBlock({ blockNumber }) : client.getBlock({ blockTag: blockTag ?? "finalized" })
|
|
273
|
+
);
|
|
274
|
+
if (error || !block) {
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
return block;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
class EthereumConnector extends IBlockchainConnector {
|
|
282
|
+
constructor() {
|
|
283
|
+
super(...arguments);
|
|
284
|
+
this.connectorKey = "ETHEREUM";
|
|
285
|
+
this.client = null;
|
|
286
|
+
}
|
|
287
|
+
createClient() {
|
|
288
|
+
if (!this.client) {
|
|
289
|
+
this.client = viem.createPublicClient({
|
|
290
|
+
transport: viem.http(this.rpcUrl)
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return this.client;
|
|
294
|
+
}
|
|
295
|
+
async getTransaction(txHash) {
|
|
296
|
+
const client = this.createClient();
|
|
297
|
+
const [tx, txError] = await backendSdk.useResult(
|
|
298
|
+
client.getTransaction({ hash: txHash })
|
|
299
|
+
);
|
|
300
|
+
if (txError || !tx) {
|
|
301
|
+
throw backendSdk.createInternalError(txError);
|
|
302
|
+
}
|
|
303
|
+
let status = "pending";
|
|
304
|
+
let gasUsed = null;
|
|
305
|
+
let timestamp = null;
|
|
306
|
+
if (tx.blockNumber) {
|
|
307
|
+
const [receipt, receiptError] = await backendSdk.useResult(
|
|
308
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
309
|
+
);
|
|
310
|
+
if (receiptError || !receipt) {
|
|
311
|
+
throw backendSdk.createInternalError(receiptError);
|
|
312
|
+
}
|
|
313
|
+
const [block, blockError] = await backendSdk.useResult(
|
|
314
|
+
client.getBlock({ blockNumber: tx.blockNumber })
|
|
315
|
+
);
|
|
316
|
+
if (blockError || !block) {
|
|
317
|
+
throw backendSdk.createInternalError(blockError);
|
|
318
|
+
}
|
|
319
|
+
status = receipt.status === "success" ? "success" : "reverted";
|
|
320
|
+
gasUsed = receipt.gasUsed.toString();
|
|
321
|
+
timestamp = Number(block.timestamp) * 1e3;
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
hash: tx.hash,
|
|
325
|
+
from: tx.from,
|
|
326
|
+
to: tx.to,
|
|
327
|
+
value: tx.value.toString(),
|
|
328
|
+
blockNumber: tx.blockNumber?.toString() ?? null,
|
|
329
|
+
blockHash: tx.blockHash ?? null,
|
|
330
|
+
gasPrice: tx.gasPrice?.toString() ?? null,
|
|
331
|
+
gas: tx.gas.toString(),
|
|
332
|
+
nonce: tx.nonce,
|
|
333
|
+
transactionIndex: tx.transactionIndex,
|
|
334
|
+
status,
|
|
335
|
+
gasUsed,
|
|
336
|
+
timestamp
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
async getTransactionReceipt(txHash) {
|
|
340
|
+
const client = this.createClient();
|
|
341
|
+
const [receipt, error] = await backendSdk.useResult(
|
|
342
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
343
|
+
);
|
|
344
|
+
if (error || !receipt) {
|
|
345
|
+
throw backendSdk.createInternalError(error);
|
|
346
|
+
}
|
|
347
|
+
return receipt;
|
|
348
|
+
}
|
|
349
|
+
async getBlock({
|
|
350
|
+
blockHash,
|
|
351
|
+
blockNumber,
|
|
352
|
+
blockTag
|
|
353
|
+
}) {
|
|
354
|
+
const client = this.createClient();
|
|
355
|
+
const [block, error] = await backendSdk.useResult(
|
|
356
|
+
blockHash !== void 0 ? client.getBlock({ blockHash }) : blockNumber !== void 0 ? client.getBlock({ blockNumber }) : client.getBlock({ blockTag: blockTag ?? "finalized" })
|
|
357
|
+
);
|
|
358
|
+
if (error || !block) {
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
return block;
|
|
362
|
+
}
|
|
17
363
|
}
|
|
18
364
|
|
|
19
|
-
class
|
|
20
|
-
constructor(
|
|
21
|
-
super();
|
|
22
|
-
this.connectorKey = "
|
|
365
|
+
class GnosisConnector extends IBlockchainConnector {
|
|
366
|
+
constructor() {
|
|
367
|
+
super(...arguments);
|
|
368
|
+
this.connectorKey = "GNOSIS";
|
|
23
369
|
this.client = null;
|
|
24
|
-
this.rpcUrl = config.rpcUrl;
|
|
25
370
|
}
|
|
26
371
|
createClient() {
|
|
27
372
|
if (!this.client) {
|
|
@@ -85,6 +430,188 @@ class AlchemyConnector extends IBlockchainConnector {
|
|
|
85
430
|
}
|
|
86
431
|
return receipt;
|
|
87
432
|
}
|
|
433
|
+
async getBlock({
|
|
434
|
+
blockHash,
|
|
435
|
+
blockNumber,
|
|
436
|
+
blockTag
|
|
437
|
+
}) {
|
|
438
|
+
const client = this.createClient();
|
|
439
|
+
const [block, error] = await backendSdk.useResult(
|
|
440
|
+
blockHash !== void 0 ? client.getBlock({ blockHash }) : blockNumber !== void 0 ? client.getBlock({ blockNumber }) : client.getBlock({ blockTag: blockTag ?? "finalized" })
|
|
441
|
+
);
|
|
442
|
+
if (error || !block) {
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
return block;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
class OptimismConnector extends IBlockchainConnector {
|
|
450
|
+
constructor() {
|
|
451
|
+
super(...arguments);
|
|
452
|
+
this.connectorKey = "OPTIMISM";
|
|
453
|
+
this.client = null;
|
|
454
|
+
}
|
|
455
|
+
createClient() {
|
|
456
|
+
if (!this.client) {
|
|
457
|
+
this.client = viem.createPublicClient({
|
|
458
|
+
transport: viem.http(this.rpcUrl)
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
return this.client;
|
|
462
|
+
}
|
|
463
|
+
async getTransaction(txHash) {
|
|
464
|
+
const client = this.createClient();
|
|
465
|
+
const [tx, txError] = await backendSdk.useResult(
|
|
466
|
+
client.getTransaction({ hash: txHash })
|
|
467
|
+
);
|
|
468
|
+
if (txError || !tx) {
|
|
469
|
+
throw backendSdk.createInternalError(txError);
|
|
470
|
+
}
|
|
471
|
+
let status = "pending";
|
|
472
|
+
let gasUsed = null;
|
|
473
|
+
let timestamp = null;
|
|
474
|
+
if (tx.blockNumber) {
|
|
475
|
+
const [receipt, receiptError] = await backendSdk.useResult(
|
|
476
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
477
|
+
);
|
|
478
|
+
if (receiptError || !receipt) {
|
|
479
|
+
throw backendSdk.createInternalError(receiptError);
|
|
480
|
+
}
|
|
481
|
+
const [block, blockError] = await backendSdk.useResult(
|
|
482
|
+
client.getBlock({ blockNumber: tx.blockNumber })
|
|
483
|
+
);
|
|
484
|
+
if (blockError || !block) {
|
|
485
|
+
throw backendSdk.createInternalError(blockError);
|
|
486
|
+
}
|
|
487
|
+
status = receipt.status === "success" ? "success" : "reverted";
|
|
488
|
+
gasUsed = receipt.gasUsed.toString();
|
|
489
|
+
timestamp = Number(block.timestamp) * 1e3;
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
hash: tx.hash,
|
|
493
|
+
from: tx.from,
|
|
494
|
+
to: tx.to,
|
|
495
|
+
value: tx.value.toString(),
|
|
496
|
+
blockNumber: tx.blockNumber?.toString() ?? null,
|
|
497
|
+
blockHash: tx.blockHash ?? null,
|
|
498
|
+
gasPrice: tx.gasPrice?.toString() ?? null,
|
|
499
|
+
gas: tx.gas.toString(),
|
|
500
|
+
nonce: tx.nonce,
|
|
501
|
+
transactionIndex: tx.transactionIndex,
|
|
502
|
+
status,
|
|
503
|
+
gasUsed,
|
|
504
|
+
timestamp
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
async getTransactionReceipt(txHash) {
|
|
508
|
+
const client = this.createClient();
|
|
509
|
+
const [receipt, error] = await backendSdk.useResult(
|
|
510
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
511
|
+
);
|
|
512
|
+
if (error || !receipt) {
|
|
513
|
+
throw backendSdk.createInternalError(error);
|
|
514
|
+
}
|
|
515
|
+
return receipt;
|
|
516
|
+
}
|
|
517
|
+
async getBlock({
|
|
518
|
+
blockHash,
|
|
519
|
+
blockNumber,
|
|
520
|
+
blockTag
|
|
521
|
+
}) {
|
|
522
|
+
const client = this.createClient();
|
|
523
|
+
const [block, error] = await backendSdk.useResult(
|
|
524
|
+
blockHash !== void 0 ? client.getBlock({ blockHash }) : blockNumber !== void 0 ? client.getBlock({ blockNumber }) : client.getBlock({ blockTag: blockTag ?? "finalized" })
|
|
525
|
+
);
|
|
526
|
+
if (error || !block) {
|
|
527
|
+
throw error;
|
|
528
|
+
}
|
|
529
|
+
return block;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
class ScrollConnector extends IBlockchainConnector {
|
|
534
|
+
constructor() {
|
|
535
|
+
super(...arguments);
|
|
536
|
+
this.connectorKey = "SCROLL";
|
|
537
|
+
this.client = null;
|
|
538
|
+
}
|
|
539
|
+
createClient() {
|
|
540
|
+
if (!this.client) {
|
|
541
|
+
this.client = viem.createPublicClient({
|
|
542
|
+
transport: viem.http(this.rpcUrl)
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
return this.client;
|
|
546
|
+
}
|
|
547
|
+
async getTransaction(txHash) {
|
|
548
|
+
const client = this.createClient();
|
|
549
|
+
const [tx, txError] = await backendSdk.useResult(
|
|
550
|
+
client.getTransaction({ hash: txHash })
|
|
551
|
+
);
|
|
552
|
+
if (txError || !tx) {
|
|
553
|
+
throw backendSdk.createInternalError(txError);
|
|
554
|
+
}
|
|
555
|
+
let status = "pending";
|
|
556
|
+
let gasUsed = null;
|
|
557
|
+
let timestamp = null;
|
|
558
|
+
if (tx.blockNumber) {
|
|
559
|
+
const [receipt, receiptError] = await backendSdk.useResult(
|
|
560
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
561
|
+
);
|
|
562
|
+
if (receiptError || !receipt) {
|
|
563
|
+
throw backendSdk.createInternalError(receiptError);
|
|
564
|
+
}
|
|
565
|
+
const [block, blockError] = await backendSdk.useResult(
|
|
566
|
+
client.getBlock({ blockNumber: tx.blockNumber })
|
|
567
|
+
);
|
|
568
|
+
if (blockError || !block) {
|
|
569
|
+
throw backendSdk.createInternalError(blockError);
|
|
570
|
+
}
|
|
571
|
+
status = receipt.status === "success" ? "success" : "reverted";
|
|
572
|
+
gasUsed = receipt.gasUsed.toString();
|
|
573
|
+
timestamp = Number(block.timestamp) * 1e3;
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
hash: tx.hash,
|
|
577
|
+
from: tx.from,
|
|
578
|
+
to: tx.to,
|
|
579
|
+
value: tx.value.toString(),
|
|
580
|
+
blockNumber: tx.blockNumber?.toString() ?? null,
|
|
581
|
+
blockHash: tx.blockHash ?? null,
|
|
582
|
+
gasPrice: tx.gasPrice?.toString() ?? null,
|
|
583
|
+
gas: tx.gas.toString(),
|
|
584
|
+
nonce: tx.nonce,
|
|
585
|
+
transactionIndex: tx.transactionIndex,
|
|
586
|
+
status,
|
|
587
|
+
gasUsed,
|
|
588
|
+
timestamp
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
async getTransactionReceipt(txHash) {
|
|
592
|
+
const client = this.createClient();
|
|
593
|
+
const [receipt, error] = await backendSdk.useResult(
|
|
594
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
595
|
+
);
|
|
596
|
+
if (error || !receipt) {
|
|
597
|
+
throw backendSdk.createInternalError(error);
|
|
598
|
+
}
|
|
599
|
+
return receipt;
|
|
600
|
+
}
|
|
601
|
+
async getBlock({
|
|
602
|
+
blockHash,
|
|
603
|
+
blockNumber,
|
|
604
|
+
blockTag
|
|
605
|
+
}) {
|
|
606
|
+
const client = this.createClient();
|
|
607
|
+
const [block, error] = await backendSdk.useResult(
|
|
608
|
+
blockHash !== void 0 ? client.getBlock({ blockHash }) : blockNumber !== void 0 ? client.getBlock({ blockNumber }) : client.getBlock({ blockTag: blockTag ?? "finalized" })
|
|
609
|
+
);
|
|
610
|
+
if (error || !block) {
|
|
611
|
+
throw error;
|
|
612
|
+
}
|
|
613
|
+
return block;
|
|
614
|
+
}
|
|
88
615
|
}
|
|
89
616
|
|
|
90
617
|
var __defProp = Object.defineProperty;
|
|
@@ -97,6 +624,15 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
97
624
|
if (kind && result) __defProp(target, key, result);
|
|
98
625
|
return result;
|
|
99
626
|
};
|
|
627
|
+
const CHAIN_CONNECTOR = {
|
|
628
|
+
ARBITRUM: ArbitrumConnector,
|
|
629
|
+
AVALANCHE: AvalancheConnector,
|
|
630
|
+
BASE: BaseConnector,
|
|
631
|
+
ETHEREUM: EthereumConnector,
|
|
632
|
+
GNOSIS: GnosisConnector,
|
|
633
|
+
OPTIMISM: OptimismConnector,
|
|
634
|
+
SCROLL: ScrollConnector
|
|
635
|
+
};
|
|
100
636
|
let BlockchainServiceBase = class extends backendSdk.develitWorker(
|
|
101
637
|
cloudflare_workers.WorkerEntrypoint
|
|
102
638
|
) {
|
|
@@ -126,12 +662,29 @@ let BlockchainServiceBase = class extends backendSdk.develitWorker(
|
|
|
126
662
|
return this.handleAction(
|
|
127
663
|
{ data: input, schema: syncAddress.getTransactionInputSchema },
|
|
128
664
|
{ successMessage: "Transaction retrieved successfully." },
|
|
129
|
-
async ({ txHash }) => {
|
|
665
|
+
async ({ chain, txHash }) => {
|
|
666
|
+
const connector = new CHAIN_CONNECTOR[chain]();
|
|
130
667
|
const rpcUrl = (await this.env.SECRETS_STORE.get({
|
|
131
|
-
secretName:
|
|
668
|
+
secretName: connector.rpcSecretName
|
|
132
669
|
})).data?.secretValue || "";
|
|
133
|
-
|
|
134
|
-
|
|
670
|
+
return connector.init(rpcUrl).getTransaction(txHash);
|
|
671
|
+
}
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
async getBlock(input) {
|
|
675
|
+
return this.handleAction(
|
|
676
|
+
{ data: input, schema: syncAddress.getBlockInputSchema },
|
|
677
|
+
{ successMessage: "Block retrieved successfully." },
|
|
678
|
+
async ({ chain, blockHash, blockNumber, blockTag }) => {
|
|
679
|
+
const connector = new CHAIN_CONNECTOR[chain]();
|
|
680
|
+
const rpcUrl = (await this.env.SECRETS_STORE.get({
|
|
681
|
+
secretName: connector.rpcSecretName
|
|
682
|
+
})).data?.secretValue || "";
|
|
683
|
+
return connector.init(rpcUrl).getBlock({
|
|
684
|
+
blockHash,
|
|
685
|
+
blockNumber,
|
|
686
|
+
blockTag
|
|
687
|
+
});
|
|
135
688
|
}
|
|
136
689
|
);
|
|
137
690
|
}
|
|
@@ -142,6 +695,9 @@ __decorateClass([
|
|
|
142
695
|
__decorateClass([
|
|
143
696
|
backendSdk.action("get-transaction")
|
|
144
697
|
], BlockchainServiceBase.prototype, "getTransaction", 1);
|
|
698
|
+
__decorateClass([
|
|
699
|
+
backendSdk.action("get-block")
|
|
700
|
+
], BlockchainServiceBase.prototype, "getBlock", 1);
|
|
145
701
|
BlockchainServiceBase = __decorateClass([
|
|
146
702
|
backendSdk.service("blockchain")
|
|
147
703
|
], BlockchainServiceBase);
|
package/dist/export/worker.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
2
|
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { t as tables, S as SyncAddressInput, a as SyncAddressOutput, G as GetTransactionInput, b as GetTransactionOutput } from '../shared/blockchain.
|
|
3
|
+
import { t as tables, S as SyncAddressInput, a as SyncAddressOutput, G as GetTransactionInput, b as GetTransactionOutput, c as GetBlockInput, d as GetBlockOutput } from '../shared/blockchain.CtIjPvX8.cjs';
|
|
4
4
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
5
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
6
6
|
import 'zod';
|
|
@@ -13,6 +13,7 @@ declare class BlockchainServiceBase extends BlockchainServiceBase_base {
|
|
|
13
13
|
constructor(ctx: ExecutionContext, env: BlockchainEnv);
|
|
14
14
|
syncAddress(input: SyncAddressInput): Promise<IRPCResponse<SyncAddressOutput>>;
|
|
15
15
|
getTransaction(input: GetTransactionInput): Promise<IRPCResponse<GetTransactionOutput>>;
|
|
16
|
+
getBlock(input: GetBlockInput): Promise<IRPCResponse<GetBlockOutput>>;
|
|
16
17
|
}
|
|
17
18
|
declare function defineBlockchainService(): new (ctx: ExecutionContext, env: BlockchainEnv) => BlockchainServiceBase;
|
|
18
19
|
|
package/dist/export/worker.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
2
|
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { t as tables, S as SyncAddressInput, a as SyncAddressOutput, G as GetTransactionInput, b as GetTransactionOutput } from '../shared/blockchain.
|
|
3
|
+
import { t as tables, S as SyncAddressInput, a as SyncAddressOutput, G as GetTransactionInput, b as GetTransactionOutput, c as GetBlockInput, d as GetBlockOutput } from '../shared/blockchain.DZbyq0JM.mjs';
|
|
4
4
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
5
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
6
6
|
import 'zod';
|
|
@@ -13,6 +13,7 @@ declare class BlockchainServiceBase extends BlockchainServiceBase_base {
|
|
|
13
13
|
constructor(ctx: ExecutionContext, env: BlockchainEnv);
|
|
14
14
|
syncAddress(input: SyncAddressInput): Promise<IRPCResponse<SyncAddressOutput>>;
|
|
15
15
|
getTransaction(input: GetTransactionInput): Promise<IRPCResponse<GetTransactionOutput>>;
|
|
16
|
+
getBlock(input: GetBlockInput): Promise<IRPCResponse<GetBlockOutput>>;
|
|
16
17
|
}
|
|
17
18
|
declare function defineBlockchainService(): new (ctx: ExecutionContext, env: BlockchainEnv) => BlockchainServiceBase;
|
|
18
19
|
|
package/dist/export/worker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _develit_io_backend_sdk from '@develit-io/backend-sdk';
|
|
2
2
|
import { IRPCResponse } from '@develit-io/backend-sdk';
|
|
3
|
-
import { t as tables, S as SyncAddressInput, a as SyncAddressOutput, G as GetTransactionInput, b as GetTransactionOutput } from '../shared/blockchain.
|
|
3
|
+
import { t as tables, S as SyncAddressInput, a as SyncAddressOutput, G as GetTransactionInput, b as GetTransactionOutput, c as GetBlockInput, d as GetBlockOutput } from '../shared/blockchain.5Ld6uEay.js';
|
|
4
4
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
5
5
|
import { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
6
6
|
import 'zod';
|
|
@@ -13,6 +13,7 @@ declare class BlockchainServiceBase extends BlockchainServiceBase_base {
|
|
|
13
13
|
constructor(ctx: ExecutionContext, env: BlockchainEnv);
|
|
14
14
|
syncAddress(input: SyncAddressInput): Promise<IRPCResponse<SyncAddressOutput>>;
|
|
15
15
|
getTransaction(input: GetTransactionInput): Promise<IRPCResponse<GetTransactionOutput>>;
|
|
16
|
+
getBlock(input: GetBlockInput): Promise<IRPCResponse<GetBlockOutput>>;
|
|
16
17
|
}
|
|
17
18
|
declare function defineBlockchainService(): new (ctx: ExecutionContext, env: BlockchainEnv) => BlockchainServiceBase;
|
|
18
19
|
|