@develit-services/blockchain 0.8.1 → 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 +537 -15
- package/dist/export/worker.d.cts +1 -1
- package/dist/export/worker.d.mts +1 -1
- package/dist/export/worker.d.ts +1 -1
- package/dist/export/worker.mjs +537 -15
- package/dist/shared/{blockchain.C1uxxlk3.d.ts → blockchain.5Ld6uEay.d.ts} +32 -4
- package/dist/shared/{blockchain.C0wB1XUE.cjs → blockchain.BBjLLe8v.cjs} +31 -19
- package/dist/shared/{blockchain.Bq5JL2Nn.d.cts → blockchain.CtIjPvX8.d.cts} +32 -4
- package/dist/shared/{blockchain.B_9YwgFd.mjs → blockchain.DTJULMBV.mjs} +31 -20
- package/dist/shared/{blockchain.BFesyGyk.d.mts → blockchain.DZbyq0JM.d.mts} +32 -4
- package/dist/types.cjs +2 -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/export/worker.cjs
CHANGED
|
@@ -3,25 +3,538 @@
|
|
|
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";
|
|
369
|
+
this.client = null;
|
|
370
|
+
}
|
|
371
|
+
createClient() {
|
|
372
|
+
if (!this.client) {
|
|
373
|
+
this.client = viem.createPublicClient({
|
|
374
|
+
transport: viem.http(this.rpcUrl)
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return this.client;
|
|
378
|
+
}
|
|
379
|
+
async getTransaction(txHash) {
|
|
380
|
+
const client = this.createClient();
|
|
381
|
+
const [tx, txError] = await backendSdk.useResult(
|
|
382
|
+
client.getTransaction({ hash: txHash })
|
|
383
|
+
);
|
|
384
|
+
if (txError || !tx) {
|
|
385
|
+
throw backendSdk.createInternalError(txError);
|
|
386
|
+
}
|
|
387
|
+
let status = "pending";
|
|
388
|
+
let gasUsed = null;
|
|
389
|
+
let timestamp = null;
|
|
390
|
+
if (tx.blockNumber) {
|
|
391
|
+
const [receipt, receiptError] = await backendSdk.useResult(
|
|
392
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
393
|
+
);
|
|
394
|
+
if (receiptError || !receipt) {
|
|
395
|
+
throw backendSdk.createInternalError(receiptError);
|
|
396
|
+
}
|
|
397
|
+
const [block, blockError] = await backendSdk.useResult(
|
|
398
|
+
client.getBlock({ blockNumber: tx.blockNumber })
|
|
399
|
+
);
|
|
400
|
+
if (blockError || !block) {
|
|
401
|
+
throw backendSdk.createInternalError(blockError);
|
|
402
|
+
}
|
|
403
|
+
status = receipt.status === "success" ? "success" : "reverted";
|
|
404
|
+
gasUsed = receipt.gasUsed.toString();
|
|
405
|
+
timestamp = Number(block.timestamp) * 1e3;
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
hash: tx.hash,
|
|
409
|
+
from: tx.from,
|
|
410
|
+
to: tx.to,
|
|
411
|
+
value: tx.value.toString(),
|
|
412
|
+
blockNumber: tx.blockNumber?.toString() ?? null,
|
|
413
|
+
blockHash: tx.blockHash ?? null,
|
|
414
|
+
gasPrice: tx.gasPrice?.toString() ?? null,
|
|
415
|
+
gas: tx.gas.toString(),
|
|
416
|
+
nonce: tx.nonce,
|
|
417
|
+
transactionIndex: tx.transactionIndex,
|
|
418
|
+
status,
|
|
419
|
+
gasUsed,
|
|
420
|
+
timestamp
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
async getTransactionReceipt(txHash) {
|
|
424
|
+
const client = this.createClient();
|
|
425
|
+
const [receipt, error] = await backendSdk.useResult(
|
|
426
|
+
client.getTransactionReceipt({ hash: txHash })
|
|
427
|
+
);
|
|
428
|
+
if (error || !receipt) {
|
|
429
|
+
throw backendSdk.createInternalError(error);
|
|
430
|
+
}
|
|
431
|
+
return receipt;
|
|
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";
|
|
23
537
|
this.client = null;
|
|
24
|
-
this.rpcUrl = config.rpcUrl;
|
|
25
538
|
}
|
|
26
539
|
createClient() {
|
|
27
540
|
if (!this.client) {
|
|
@@ -111,6 +624,15 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
111
624
|
if (kind && result) __defProp(target, key, result);
|
|
112
625
|
return result;
|
|
113
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
|
+
};
|
|
114
636
|
let BlockchainServiceBase = class extends backendSdk.develitWorker(
|
|
115
637
|
cloudflare_workers.WorkerEntrypoint
|
|
116
638
|
) {
|
|
@@ -140,12 +662,12 @@ let BlockchainServiceBase = class extends backendSdk.develitWorker(
|
|
|
140
662
|
return this.handleAction(
|
|
141
663
|
{ data: input, schema: syncAddress.getTransactionInputSchema },
|
|
142
664
|
{ successMessage: "Transaction retrieved successfully." },
|
|
143
|
-
async ({ txHash }) => {
|
|
665
|
+
async ({ chain, txHash }) => {
|
|
666
|
+
const connector = new CHAIN_CONNECTOR[chain]();
|
|
144
667
|
const rpcUrl = (await this.env.SECRETS_STORE.get({
|
|
145
|
-
secretName:
|
|
668
|
+
secretName: connector.rpcSecretName
|
|
146
669
|
})).data?.secretValue || "";
|
|
147
|
-
|
|
148
|
-
return connector.getTransaction(txHash);
|
|
670
|
+
return connector.init(rpcUrl).getTransaction(txHash);
|
|
149
671
|
}
|
|
150
672
|
);
|
|
151
673
|
}
|
|
@@ -153,12 +675,12 @@ let BlockchainServiceBase = class extends backendSdk.develitWorker(
|
|
|
153
675
|
return this.handleAction(
|
|
154
676
|
{ data: input, schema: syncAddress.getBlockInputSchema },
|
|
155
677
|
{ successMessage: "Block retrieved successfully." },
|
|
156
|
-
async ({ blockHash, blockNumber, blockTag }) => {
|
|
678
|
+
async ({ chain, blockHash, blockNumber, blockTag }) => {
|
|
679
|
+
const connector = new CHAIN_CONNECTOR[chain]();
|
|
157
680
|
const rpcUrl = (await this.env.SECRETS_STORE.get({
|
|
158
|
-
secretName:
|
|
681
|
+
secretName: connector.rpcSecretName
|
|
159
682
|
})).data?.secretValue || "";
|
|
160
|
-
|
|
161
|
-
return connector.getBlock({
|
|
683
|
+
return connector.init(rpcUrl).getBlock({
|
|
162
684
|
blockHash,
|
|
163
685
|
blockNumber,
|
|
164
686
|
blockTag
|
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, c as GetBlockInput, d as GetBlockOutput } 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';
|
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, c as GetBlockInput, d as GetBlockOutput } 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';
|
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, c as GetBlockInput, d as GetBlockOutput } 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';
|