@net-protocol/storage 0.1.8 → 0.1.10

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/react.mjs ADDED
@@ -0,0 +1,1367 @@
1
+ import { useReadContract } from 'wagmi';
2
+ import { useState, useEffect, useMemo } from 'react';
3
+ import { getNetContract, getPublicClient, keccak256HashString, toBytes32 } from '@net-protocol/core';
4
+ import { hexToString, decodeAbiParameters, stringToHex, hexToBytes } from 'viem';
5
+ import pako from 'pako';
6
+ import { readContract } from 'viem/actions';
7
+ import useAsyncEffect from 'use-async-effect';
8
+
9
+ // src/hooks/useStorage.ts
10
+
11
+ // src/abis/storage.json
12
+ var storage_default = [
13
+ {
14
+ type: "function",
15
+ name: "bulkGet",
16
+ inputs: [
17
+ {
18
+ name: "params",
19
+ type: "tuple[]",
20
+ internalType: "struct Storage.BulkGetParams[]",
21
+ components: [
22
+ { name: "key", type: "bytes32", internalType: "bytes32" },
23
+ { name: "operator", type: "address", internalType: "address" }
24
+ ]
25
+ }
26
+ ],
27
+ outputs: [
28
+ {
29
+ name: "results",
30
+ type: "tuple[]",
31
+ internalType: "struct Storage.BulkGetResult[]",
32
+ components: [
33
+ { name: "text", type: "string", internalType: "string" },
34
+ { name: "value", type: "bytes", internalType: "bytes" }
35
+ ]
36
+ }
37
+ ],
38
+ stateMutability: "view"
39
+ },
40
+ {
41
+ type: "function",
42
+ name: "bulkGetTotalWrites",
43
+ inputs: [
44
+ {
45
+ name: "params",
46
+ type: "tuple[]",
47
+ internalType: "struct Storage.BulkGetParams[]",
48
+ components: [
49
+ { name: "key", type: "bytes32", internalType: "bytes32" },
50
+ { name: "operator", type: "address", internalType: "address" }
51
+ ]
52
+ }
53
+ ],
54
+ outputs: [
55
+ { name: "results", type: "uint256[]", internalType: "uint256[]" }
56
+ ],
57
+ stateMutability: "view"
58
+ },
59
+ {
60
+ type: "function",
61
+ name: "bulkGetValueAtIndex",
62
+ inputs: [
63
+ {
64
+ name: "params",
65
+ type: "tuple[]",
66
+ internalType: "struct Storage.BulkGetValueAtIndexParams[]",
67
+ components: [
68
+ { name: "key", type: "bytes32", internalType: "bytes32" },
69
+ {
70
+ name: "operator",
71
+ type: "address",
72
+ internalType: "address"
73
+ },
74
+ { name: "idx", type: "uint256", internalType: "uint256" }
75
+ ]
76
+ }
77
+ ],
78
+ outputs: [
79
+ {
80
+ name: "results",
81
+ type: "tuple[]",
82
+ internalType: "struct Storage.BulkGetResult[]",
83
+ components: [
84
+ { name: "text", type: "string", internalType: "string" },
85
+ { name: "value", type: "bytes", internalType: "bytes" }
86
+ ]
87
+ }
88
+ ],
89
+ stateMutability: "view"
90
+ },
91
+ {
92
+ type: "function",
93
+ name: "bulkPut",
94
+ inputs: [
95
+ {
96
+ name: "params",
97
+ type: "tuple[]",
98
+ internalType: "struct Storage.BulkPutParams[]",
99
+ components: [
100
+ { name: "key", type: "bytes32", internalType: "bytes32" },
101
+ { name: "text", type: "string", internalType: "string" },
102
+ { name: "value", type: "bytes", internalType: "bytes" }
103
+ ]
104
+ }
105
+ ],
106
+ outputs: [],
107
+ stateMutability: "nonpayable"
108
+ },
109
+ {
110
+ type: "function",
111
+ name: "get",
112
+ inputs: [
113
+ { name: "key", type: "bytes32", internalType: "bytes32" },
114
+ { name: "operator", type: "address", internalType: "address" }
115
+ ],
116
+ outputs: [
117
+ { name: "", type: "string", internalType: "string" },
118
+ { name: "", type: "bytes", internalType: "bytes" }
119
+ ],
120
+ stateMutability: "view"
121
+ },
122
+ {
123
+ type: "function",
124
+ name: "getTotalWrites",
125
+ inputs: [
126
+ { name: "key", type: "bytes32", internalType: "bytes32" },
127
+ { name: "operator", type: "address", internalType: "address" }
128
+ ],
129
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
130
+ stateMutability: "view"
131
+ },
132
+ {
133
+ type: "function",
134
+ name: "getValueAtIndex",
135
+ inputs: [
136
+ { name: "key", type: "bytes32", internalType: "bytes32" },
137
+ { name: "operator", type: "address", internalType: "address" },
138
+ { name: "idx", type: "uint256", internalType: "uint256" }
139
+ ],
140
+ outputs: [
141
+ { name: "", type: "string", internalType: "string" },
142
+ { name: "", type: "bytes", internalType: "bytes" }
143
+ ],
144
+ stateMutability: "view"
145
+ },
146
+ {
147
+ type: "function",
148
+ name: "put",
149
+ inputs: [
150
+ { name: "key", type: "bytes32", internalType: "bytes32" },
151
+ { name: "text", type: "string", internalType: "string" },
152
+ { name: "value", type: "bytes", internalType: "bytes" }
153
+ ],
154
+ outputs: [],
155
+ stateMutability: "nonpayable"
156
+ },
157
+ {
158
+ type: "event",
159
+ name: "Stored",
160
+ inputs: [
161
+ {
162
+ name: "key",
163
+ type: "bytes32",
164
+ indexed: true,
165
+ internalType: "bytes32"
166
+ },
167
+ {
168
+ name: "operator",
169
+ type: "address",
170
+ indexed: true,
171
+ internalType: "address"
172
+ }
173
+ ],
174
+ anonymous: false
175
+ }
176
+ ];
177
+
178
+ // src/abis/chunked-storage.json
179
+ var chunked_storage_default = [
180
+ {
181
+ type: "function",
182
+ name: "get",
183
+ inputs: [
184
+ { name: "key", type: "bytes32", internalType: "bytes32" },
185
+ { name: "operator", type: "address", internalType: "address" }
186
+ ],
187
+ outputs: [
188
+ { name: "", type: "string", internalType: "string" },
189
+ { name: "", type: "bytes", internalType: "bytes" }
190
+ ],
191
+ stateMutability: "view"
192
+ },
193
+ {
194
+ type: "function",
195
+ name: "getChunk",
196
+ inputs: [
197
+ { name: "key", type: "bytes32", internalType: "bytes32" },
198
+ { name: "operator", type: "address", internalType: "address" },
199
+ { name: "chunkIndex", type: "uint8", internalType: "uint8" }
200
+ ],
201
+ outputs: [
202
+ { name: "chunkData", type: "bytes", internalType: "bytes" }
203
+ ],
204
+ stateMutability: "view"
205
+ },
206
+ {
207
+ type: "function",
208
+ name: "getChunks",
209
+ inputs: [
210
+ { name: "key", type: "bytes32", internalType: "bytes32" },
211
+ { name: "operator", type: "address", internalType: "address" },
212
+ { name: "startIndex", type: "uint8", internalType: "uint8" },
213
+ { name: "endIndex", type: "uint8", internalType: "uint8" }
214
+ ],
215
+ outputs: [
216
+ { name: "chunks", type: "bytes[]", internalType: "bytes[]" }
217
+ ],
218
+ stateMutability: "view"
219
+ },
220
+ {
221
+ type: "function",
222
+ name: "getMetadata",
223
+ inputs: [
224
+ { name: "key", type: "bytes32", internalType: "bytes32" },
225
+ { name: "operator", type: "address", internalType: "address" }
226
+ ],
227
+ outputs: [
228
+ { name: "chunkCount", type: "uint8", internalType: "uint8" },
229
+ { name: "originalText", type: "string", internalType: "string" }
230
+ ],
231
+ stateMutability: "view"
232
+ },
233
+ {
234
+ type: "function",
235
+ name: "put",
236
+ inputs: [
237
+ { name: "key", type: "bytes32", internalType: "bytes32" },
238
+ { name: "text", type: "string", internalType: "string" },
239
+ { name: "chunks", type: "bytes[]", internalType: "bytes[]" }
240
+ ],
241
+ outputs: [],
242
+ stateMutability: "nonpayable"
243
+ },
244
+ {
245
+ type: "event",
246
+ name: "ChunkedStoragePut",
247
+ inputs: [
248
+ {
249
+ name: "originalKey",
250
+ type: "bytes32",
251
+ indexed: true,
252
+ internalType: "bytes32"
253
+ },
254
+ {
255
+ name: "sender",
256
+ type: "address",
257
+ indexed: true,
258
+ internalType: "address"
259
+ },
260
+ {
261
+ name: "hashedKey",
262
+ type: "bytes32",
263
+ indexed: false,
264
+ internalType: "bytes32"
265
+ }
266
+ ],
267
+ anonymous: false
268
+ },
269
+ { type: "error", name: "DataTooLarge", inputs: [] }
270
+ ];
271
+
272
+ // src/abis/chunked-storage-reader.json
273
+ var chunked_storage_reader_default = [
274
+ {
275
+ type: "function",
276
+ name: "get",
277
+ inputs: [
278
+ { name: "key", type: "bytes32", internalType: "bytes32" },
279
+ { name: "operator", type: "address", internalType: "address" }
280
+ ],
281
+ outputs: [
282
+ { name: "", type: "string", internalType: "string" },
283
+ { name: "", type: "bytes", internalType: "bytes" }
284
+ ],
285
+ stateMutability: "view"
286
+ },
287
+ {
288
+ type: "function",
289
+ name: "getChunk",
290
+ inputs: [
291
+ { name: "key", type: "bytes32", internalType: "bytes32" },
292
+ { name: "operator", type: "address", internalType: "address" },
293
+ { name: "chunkIndex", type: "uint8", internalType: "uint8" }
294
+ ],
295
+ outputs: [
296
+ { name: "chunkData", type: "bytes", internalType: "bytes" }
297
+ ],
298
+ stateMutability: "view"
299
+ },
300
+ {
301
+ type: "function",
302
+ name: "getChunkAtIndex",
303
+ inputs: [
304
+ { name: "key", type: "bytes32", internalType: "bytes32" },
305
+ { name: "operator", type: "address", internalType: "address" },
306
+ { name: "chunkIndex", type: "uint8", internalType: "uint8" },
307
+ { name: "idx", type: "uint256", internalType: "uint256" }
308
+ ],
309
+ outputs: [
310
+ { name: "chunkData", type: "bytes", internalType: "bytes" }
311
+ ],
312
+ stateMutability: "view"
313
+ },
314
+ {
315
+ type: "function",
316
+ name: "getChunks",
317
+ inputs: [
318
+ { name: "key", type: "bytes32", internalType: "bytes32" },
319
+ { name: "operator", type: "address", internalType: "address" },
320
+ { name: "startIndex", type: "uint8", internalType: "uint8" },
321
+ { name: "endIndex", type: "uint8", internalType: "uint8" }
322
+ ],
323
+ outputs: [
324
+ { name: "chunks", type: "bytes[]", internalType: "bytes[]" }
325
+ ],
326
+ stateMutability: "view"
327
+ },
328
+ {
329
+ type: "function",
330
+ name: "getChunksAtIndex",
331
+ inputs: [
332
+ { name: "key", type: "bytes32", internalType: "bytes32" },
333
+ { name: "operator", type: "address", internalType: "address" },
334
+ { name: "startIndex", type: "uint8", internalType: "uint8" },
335
+ { name: "endIndex", type: "uint8", internalType: "uint8" },
336
+ { name: "idx", type: "uint256", internalType: "uint256" }
337
+ ],
338
+ outputs: [
339
+ { name: "chunks", type: "bytes[]", internalType: "bytes[]" }
340
+ ],
341
+ stateMutability: "view"
342
+ },
343
+ {
344
+ type: "function",
345
+ name: "getMetadata",
346
+ inputs: [
347
+ { name: "key", type: "bytes32", internalType: "bytes32" },
348
+ { name: "operator", type: "address", internalType: "address" }
349
+ ],
350
+ outputs: [
351
+ { name: "chunkCount", type: "uint8", internalType: "uint8" },
352
+ { name: "originalText", type: "string", internalType: "string" }
353
+ ],
354
+ stateMutability: "view"
355
+ },
356
+ {
357
+ type: "function",
358
+ name: "getMetadataAtIndex",
359
+ inputs: [
360
+ { name: "key", type: "bytes32", internalType: "bytes32" },
361
+ { name: "operator", type: "address", internalType: "address" },
362
+ { name: "idx", type: "uint256", internalType: "uint256" }
363
+ ],
364
+ outputs: [
365
+ { name: "chunkCount", type: "uint8", internalType: "uint8" },
366
+ { name: "originalText", type: "string", internalType: "string" }
367
+ ],
368
+ stateMutability: "view"
369
+ },
370
+ {
371
+ type: "function",
372
+ name: "getTotalWrites",
373
+ inputs: [
374
+ { name: "key", type: "bytes32", internalType: "bytes32" },
375
+ { name: "operator", type: "address", internalType: "address" }
376
+ ],
377
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
378
+ stateMutability: "view"
379
+ },
380
+ {
381
+ type: "function",
382
+ name: "getValueAtIndex",
383
+ inputs: [
384
+ { name: "key", type: "bytes32", internalType: "bytes32" },
385
+ { name: "operator", type: "address", internalType: "address" },
386
+ { name: "idx", type: "uint256", internalType: "uint256" }
387
+ ],
388
+ outputs: [
389
+ { name: "", type: "string", internalType: "string" },
390
+ { name: "", type: "bytes", internalType: "bytes" }
391
+ ],
392
+ stateMutability: "view"
393
+ }
394
+ ];
395
+
396
+ // src/abis/storage-router.json
397
+ var storage_router_default = [
398
+ {
399
+ type: "function",
400
+ name: "get",
401
+ inputs: [
402
+ { name: "key", type: "bytes32", internalType: "bytes32" },
403
+ { name: "operator", type: "address", internalType: "address" }
404
+ ],
405
+ outputs: [
406
+ { name: "isChunkedStorage", type: "bool", internalType: "bool" },
407
+ { name: "text", type: "string", internalType: "string" },
408
+ { name: "data", type: "bytes", internalType: "bytes" }
409
+ ],
410
+ stateMutability: "view"
411
+ },
412
+ { type: "error", name: "StoredDataNotFound", inputs: [] }
413
+ ];
414
+
415
+ // src/abis/safe-storage-reader.json
416
+ var safe_storage_reader_default = [
417
+ {
418
+ type: "function",
419
+ name: "bulkGet",
420
+ inputs: [
421
+ {
422
+ name: "params",
423
+ type: "tuple[]",
424
+ internalType: "struct IStorage.BulkGetParams[]",
425
+ components: [
426
+ {
427
+ name: "key",
428
+ type: "bytes32",
429
+ internalType: "bytes32"
430
+ },
431
+ {
432
+ name: "operator",
433
+ type: "address",
434
+ internalType: "address"
435
+ }
436
+ ]
437
+ }
438
+ ],
439
+ outputs: [
440
+ {
441
+ name: "results",
442
+ type: "tuple[]",
443
+ internalType: "struct IStorage.BulkGetResult[]",
444
+ components: [
445
+ {
446
+ name: "text",
447
+ type: "string",
448
+ internalType: "string"
449
+ },
450
+ {
451
+ name: "value",
452
+ type: "bytes",
453
+ internalType: "bytes"
454
+ }
455
+ ]
456
+ }
457
+ ],
458
+ stateMutability: "view"
459
+ },
460
+ {
461
+ type: "function",
462
+ name: "bulkGetValueAtIndex",
463
+ inputs: [
464
+ {
465
+ name: "params",
466
+ type: "tuple[]",
467
+ internalType: "struct IStorage.BulkGetValueAtIndexParams[]",
468
+ components: [
469
+ {
470
+ name: "key",
471
+ type: "bytes32",
472
+ internalType: "bytes32"
473
+ },
474
+ {
475
+ name: "operator",
476
+ type: "address",
477
+ internalType: "address"
478
+ },
479
+ {
480
+ name: "idx",
481
+ type: "uint256",
482
+ internalType: "uint256"
483
+ }
484
+ ]
485
+ }
486
+ ],
487
+ outputs: [
488
+ {
489
+ name: "results",
490
+ type: "tuple[]",
491
+ internalType: "struct IStorage.BulkGetResult[]",
492
+ components: [
493
+ {
494
+ name: "text",
495
+ type: "string",
496
+ internalType: "string"
497
+ },
498
+ {
499
+ name: "value",
500
+ type: "bytes",
501
+ internalType: "bytes"
502
+ }
503
+ ]
504
+ }
505
+ ],
506
+ stateMutability: "view"
507
+ },
508
+ {
509
+ type: "function",
510
+ name: "get",
511
+ inputs: [
512
+ {
513
+ name: "key",
514
+ type: "bytes32",
515
+ internalType: "bytes32"
516
+ },
517
+ {
518
+ name: "operator",
519
+ type: "address",
520
+ internalType: "address"
521
+ }
522
+ ],
523
+ outputs: [
524
+ {
525
+ name: "",
526
+ type: "string",
527
+ internalType: "string"
528
+ },
529
+ {
530
+ name: "",
531
+ type: "bytes",
532
+ internalType: "bytes"
533
+ }
534
+ ],
535
+ stateMutability: "view"
536
+ },
537
+ {
538
+ type: "function",
539
+ name: "getValueAtIndex",
540
+ inputs: [
541
+ {
542
+ name: "key",
543
+ type: "bytes32",
544
+ internalType: "bytes32"
545
+ },
546
+ {
547
+ name: "operator",
548
+ type: "address",
549
+ internalType: "address"
550
+ },
551
+ {
552
+ name: "idx",
553
+ type: "uint256",
554
+ internalType: "uint256"
555
+ }
556
+ ],
557
+ outputs: [
558
+ {
559
+ name: "",
560
+ type: "string",
561
+ internalType: "string"
562
+ },
563
+ {
564
+ name: "",
565
+ type: "bytes",
566
+ internalType: "bytes"
567
+ }
568
+ ],
569
+ stateMutability: "view"
570
+ }
571
+ ];
572
+
573
+ // src/constants.ts
574
+ var STORAGE_CONTRACT = {
575
+ abi: storage_default,
576
+ address: "0x00000000db40fcb9f4466330982372e27fd7bbf5"
577
+ };
578
+ var CHUNKED_STORAGE_CONTRACT = {
579
+ abi: chunked_storage_default,
580
+ address: "0x000000A822F09aF21b1951B65223F54ea392E6C6"
581
+ };
582
+ var CHUNKED_STORAGE_READER_CONTRACT = {
583
+ abi: chunked_storage_reader_default,
584
+ address: "0x00000005210a7532787419658f6162f771be62f8"
585
+ };
586
+ var STORAGE_ROUTER_CONTRACT = {
587
+ abi: storage_router_default,
588
+ address: "0x000000C0bbc2Ca04B85E77D18053e7c38bB97939"
589
+ };
590
+ var SAFE_STORAGE_READER_CONTRACT = {
591
+ abi: safe_storage_reader_default,
592
+ address: "0x0000000d03bad401fae4935dc9cbbf8084347214"
593
+ };
594
+
595
+ // src/utils/xmlUtils.ts
596
+ function parseNetReferences(metadata) {
597
+ const regex = /<net\s+k="([^"]+)"\s+v="([^"]+)"(?:\s+i="([^"]+)")?(?:\s+o="([^"]+)")?(?:\s+s="([^"]+)")?\s*\/>/g;
598
+ const references = [];
599
+ let match;
600
+ while ((match = regex.exec(metadata)) !== null) {
601
+ references.push({
602
+ hash: match[1],
603
+ version: match[2],
604
+ index: match[3] ? parseInt(match[3], 10) : void 0,
605
+ operator: match[4]?.toLowerCase(),
606
+ source: match[5]
607
+ });
608
+ }
609
+ return references;
610
+ }
611
+ function containsXmlReferences(data) {
612
+ return /<net\s+k="[^"]+"\s+v="[^"]+"(?:\s+i="[^"]+")?(?:\s+o="[^"]+")?(?:\s+s="[^"]+")?\s*\/>/.test(
613
+ data
614
+ );
615
+ }
616
+ function resolveOperator(reference, defaultOperator) {
617
+ return reference.operator?.toLowerCase() || defaultOperator.toLowerCase();
618
+ }
619
+ function getReferenceKey(reference, defaultOperator) {
620
+ const operator = resolveOperator(reference, defaultOperator);
621
+ const index = reference.index !== void 0 ? `-${reference.index}` : "";
622
+ return `${reference.hash}-${operator}${index}`;
623
+ }
624
+ function assembleChunks(chunks, returnHex) {
625
+ try {
626
+ let assembled = chunks[0] || "0x";
627
+ for (let i = 1; i < chunks.length; i++) {
628
+ const chunk = chunks[i];
629
+ if (chunk && chunk !== "0x") {
630
+ assembled += chunk.slice(2);
631
+ }
632
+ }
633
+ const bytes = hexToBytes(assembled);
634
+ try {
635
+ const decompressed = pako.ungzip(bytes);
636
+ const hexString = Buffer.from(decompressed).toString("utf8");
637
+ if (returnHex) ;
638
+ const result = hexToString(hexString);
639
+ return result;
640
+ } catch (error) {
641
+ return void 0;
642
+ }
643
+ } catch (error) {
644
+ console.error("[assembleChunks] Failed to assemble chunks:", error);
645
+ throw new Error("Failed to decompress chunked data");
646
+ }
647
+ }
648
+ function getStorageKeyBytes(input, keyFormat) {
649
+ if (keyFormat === "bytes32") {
650
+ return input.toLowerCase();
651
+ }
652
+ if (keyFormat === "raw") {
653
+ return input.length > 32 ? keccak256HashString(input.toLowerCase()) : toBytes32(input.toLowerCase());
654
+ }
655
+ if (input.startsWith("0x") && input.length === 66 && // 0x + 64 hex chars = bytes32
656
+ /^0x[0-9a-fA-F]{64}$/.test(input)) {
657
+ return input.toLowerCase();
658
+ }
659
+ return input.length > 32 ? keccak256HashString(input.toLowerCase()) : toBytes32(input.toLowerCase());
660
+ }
661
+
662
+ // src/hooks/useStorage.ts
663
+ var BATCH_SIZE = 2;
664
+ function useStorage({
665
+ chainId,
666
+ key,
667
+ operatorAddress,
668
+ enabled = true,
669
+ index,
670
+ keyFormat,
671
+ useRouter = false,
672
+ outputFormat = "hex"
673
+ }) {
674
+ const isLatestVersion = index === void 0;
675
+ const shouldUseRouter = useRouter === true && isLatestVersion;
676
+ const outputAsString = outputFormat === "string";
677
+ const storageKeyBytes = key ? getStorageKeyBytes(key, keyFormat) : void 0;
678
+ const formatData = (text, dataHex) => {
679
+ return {
680
+ text,
681
+ value: outputAsString ? hexToString(dataHex) : dataHex
682
+ };
683
+ };
684
+ const [routerData, setRouterData] = useState();
685
+ const [routerChunkLoading, setRouterChunkLoading] = useState(false);
686
+ const [routerChunkError, setRouterChunkError] = useState();
687
+ const routerHook = useReadContract({
688
+ abi: STORAGE_ROUTER_CONTRACT.abi,
689
+ address: STORAGE_ROUTER_CONTRACT.address,
690
+ functionName: "get",
691
+ args: storageKeyBytes && operatorAddress ? [storageKeyBytes, operatorAddress] : void 0,
692
+ chainId,
693
+ query: {
694
+ enabled: shouldUseRouter && enabled && !!key && !!operatorAddress
695
+ }
696
+ });
697
+ useEffect(() => {
698
+ async function processRouterResult() {
699
+ if (!routerHook.data || routerHook.isLoading || routerHook.error) {
700
+ return;
701
+ }
702
+ const [isChunkedStorage, text, data] = routerHook.data;
703
+ if (!isChunkedStorage) {
704
+ if (!data || typeof data !== "string") {
705
+ setRouterData(void 0);
706
+ return;
707
+ }
708
+ const formatted = formatData(text, data);
709
+ setRouterData(formatted);
710
+ return;
711
+ }
712
+ setRouterChunkLoading(true);
713
+ setRouterChunkError(void 0);
714
+ try {
715
+ const [chunkCount] = decodeAbiParameters([{ type: "uint8" }], data);
716
+ if (chunkCount === 0) {
717
+ setRouterData(void 0);
718
+ return;
719
+ }
720
+ const client = getPublicClient({ chainId });
721
+ if (!client) {
722
+ throw new Error(`Chain not found for chainId: ${chainId}`);
723
+ }
724
+ const allChunks = [];
725
+ for (let start = 0; start < Number(chunkCount); start += BATCH_SIZE) {
726
+ const end = Math.min(start + BATCH_SIZE, Number(chunkCount));
727
+ const batch = await readContract(client, {
728
+ abi: CHUNKED_STORAGE_CONTRACT.abi,
729
+ address: CHUNKED_STORAGE_CONTRACT.address,
730
+ functionName: "getChunks",
731
+ args: [storageKeyBytes, operatorAddress, start, end]
732
+ });
733
+ allChunks.push(...batch);
734
+ }
735
+ const assembledString = assembleChunks(allChunks);
736
+ if (assembledString === void 0) {
737
+ setRouterData(void 0);
738
+ } else {
739
+ if (outputAsString) {
740
+ setRouterData({ text, value: assembledString });
741
+ } else {
742
+ const hexData = stringToHex(assembledString);
743
+ setRouterData({ text, value: hexData });
744
+ }
745
+ }
746
+ } catch (error) {
747
+ setRouterChunkError(error);
748
+ } finally {
749
+ setRouterChunkLoading(false);
750
+ }
751
+ }
752
+ processRouterResult();
753
+ }, [
754
+ routerHook.data,
755
+ routerHook.isLoading,
756
+ routerHook.error,
757
+ operatorAddress,
758
+ chainId,
759
+ storageKeyBytes,
760
+ outputAsString
761
+ ]);
762
+ const {
763
+ data: latestData,
764
+ isLoading: latestLoading,
765
+ error: latestError
766
+ } = useReadContract({
767
+ abi: STORAGE_CONTRACT.abi,
768
+ address: STORAGE_CONTRACT.address,
769
+ functionName: "get",
770
+ args: key && operatorAddress ? [getStorageKeyBytes(key, keyFormat), operatorAddress] : void 0,
771
+ chainId,
772
+ query: {
773
+ enabled: !shouldUseRouter && enabled && !!operatorAddress && !!key && isLatestVersion
774
+ }
775
+ });
776
+ const [historicalData, setHistoricalData] = useState(
777
+ void 0
778
+ );
779
+ const [historicalLoading, setHistoricalLoading] = useState(false);
780
+ const [historicalError, setHistoricalError] = useState();
781
+ useEffect(() => {
782
+ async function fetchHistoricalVersion() {
783
+ if (isLatestVersion || !key || !operatorAddress || !enabled) {
784
+ return;
785
+ }
786
+ setHistoricalLoading(true);
787
+ setHistoricalError(void 0);
788
+ setHistoricalData(void 0);
789
+ try {
790
+ const client = getPublicClient({ chainId });
791
+ if (!client) {
792
+ throw new Error(`Chain not found for chainId: ${chainId}`);
793
+ }
794
+ const storageKeyBytes2 = getStorageKeyBytes(
795
+ key,
796
+ keyFormat
797
+ );
798
+ try {
799
+ const metadata = await readContract(client, {
800
+ abi: CHUNKED_STORAGE_READER_CONTRACT.abi,
801
+ address: CHUNKED_STORAGE_READER_CONTRACT.address,
802
+ functionName: "getMetadataAtIndex",
803
+ args: [storageKeyBytes2, operatorAddress, index]
804
+ });
805
+ const [chunkCount, text2] = metadata;
806
+ if (chunkCount > 0) {
807
+ const chunks = await readContract(client, {
808
+ abi: CHUNKED_STORAGE_READER_CONTRACT.abi,
809
+ address: CHUNKED_STORAGE_READER_CONTRACT.address,
810
+ functionName: "getChunksAtIndex",
811
+ args: [storageKeyBytes2, operatorAddress, 0, chunkCount, index]
812
+ });
813
+ const assembledData = assembleChunks(chunks);
814
+ if (assembledData !== void 0) {
815
+ const hexData = stringToHex(assembledData);
816
+ setHistoricalData(formatData(text2, hexData));
817
+ setHistoricalLoading(false);
818
+ return;
819
+ }
820
+ }
821
+ } catch (chunkedError) {
822
+ }
823
+ const result = await readContract(client, {
824
+ abi: STORAGE_CONTRACT.abi,
825
+ address: STORAGE_CONTRACT.address,
826
+ functionName: "getValueAtIndex",
827
+ args: [storageKeyBytes2, operatorAddress, index]
828
+ });
829
+ const [text, data] = result;
830
+ if (!data || typeof data !== "string") {
831
+ setHistoricalData(void 0);
832
+ setHistoricalLoading(false);
833
+ return;
834
+ }
835
+ setHistoricalData(formatData(text, data));
836
+ } catch (error) {
837
+ console.error(
838
+ "[useStorage] Failed to fetch historical version:",
839
+ error
840
+ );
841
+ setHistoricalError(error);
842
+ } finally {
843
+ setHistoricalLoading(false);
844
+ }
845
+ }
846
+ fetchHistoricalVersion();
847
+ }, [
848
+ chainId,
849
+ key,
850
+ operatorAddress,
851
+ index,
852
+ enabled,
853
+ isLatestVersion,
854
+ outputAsString
855
+ ]);
856
+ if (!isLatestVersion) {
857
+ return {
858
+ data: historicalData,
859
+ isLoading: historicalLoading,
860
+ error: historicalError
861
+ };
862
+ }
863
+ if (shouldUseRouter) {
864
+ return {
865
+ data: routerData,
866
+ isLoading: routerHook.isLoading || routerChunkLoading,
867
+ error: routerHook.error || routerChunkError
868
+ };
869
+ }
870
+ const formattedDirectData = latestData ? (() => {
871
+ const result = latestData;
872
+ const [text, valueHex] = result;
873
+ if (!valueHex || typeof valueHex !== "string") {
874
+ return void 0;
875
+ }
876
+ return formatData(text, valueHex);
877
+ })() : void 0;
878
+ return {
879
+ data: formattedDirectData,
880
+ isLoading: latestLoading,
881
+ error: latestError
882
+ };
883
+ }
884
+ function useStorageForOperator({
885
+ chainId,
886
+ operatorAddress
887
+ }) {
888
+ const netContract = getNetContract(chainId);
889
+ const { data: totalCount, isLoading: isLoadingCount } = useReadContract({
890
+ abi: netContract.abi,
891
+ address: netContract.address,
892
+ functionName: "getTotalMessagesForAppUserCount",
893
+ args: [STORAGE_CONTRACT.address, operatorAddress],
894
+ chainId
895
+ });
896
+ const totalCountNumber = totalCount ? Number(totalCount) : 0;
897
+ const { data: messages, isLoading: isLoadingMessages } = useReadContract({
898
+ abi: netContract.abi,
899
+ address: netContract.address,
900
+ functionName: "getMessagesInRangeForAppUser",
901
+ args: [0, totalCountNumber, STORAGE_CONTRACT.address, operatorAddress],
902
+ chainId
903
+ });
904
+ return {
905
+ data: messages?.map((msg) => [
906
+ msg.topic,
907
+ msg.text,
908
+ Number(msg.timestamp),
909
+ msg.data
910
+ ]) || [],
911
+ isLoading: isLoadingCount || isLoadingMessages,
912
+ error: void 0
913
+ };
914
+ }
915
+ function useStorageForOperatorAndKey({
916
+ chainId,
917
+ key,
918
+ operatorAddress,
919
+ keyFormat,
920
+ outputFormat = "hex"
921
+ }) {
922
+ const storageKeyBytes = key ? getStorageKeyBytes(key, keyFormat) : void 0;
923
+ const outputAsString = outputFormat === "string";
924
+ const readContractArgs = {
925
+ abi: STORAGE_CONTRACT.abi,
926
+ address: STORAGE_CONTRACT.address,
927
+ functionName: "getForOperatorAndKey",
928
+ args: storageKeyBytes ? [operatorAddress, storageKeyBytes] : void 0,
929
+ chainId,
930
+ query: {
931
+ enabled: !!key && !!operatorAddress
932
+ }
933
+ };
934
+ const { data, isLoading, error } = useReadContract(readContractArgs);
935
+ return {
936
+ data: data ? (() => {
937
+ const [text, valueHex] = data;
938
+ return {
939
+ text,
940
+ value: outputAsString ? hexToString(valueHex) : valueHex
941
+ };
942
+ })() : void 0,
943
+ isLoading,
944
+ error
945
+ };
946
+ }
947
+ function useBulkStorage({
948
+ chainId,
949
+ keys,
950
+ safe = false,
951
+ keyFormat
952
+ }) {
953
+ const contract = safe ? SAFE_STORAGE_READER_CONTRACT : STORAGE_CONTRACT;
954
+ const bulkKeys = keys.map((k) => ({
955
+ key: getStorageKeyBytes(k.key, keyFormat),
956
+ operator: k.operator
957
+ }));
958
+ const readContractArgs = {
959
+ abi: contract.abi,
960
+ address: contract.address,
961
+ functionName: "bulkGet",
962
+ args: [bulkKeys],
963
+ chainId
964
+ };
965
+ const { data, isLoading, error } = useReadContract(readContractArgs);
966
+ return {
967
+ data,
968
+ isLoading,
969
+ error
970
+ };
971
+ }
972
+ function useStorageTotalWrites({
973
+ chainId,
974
+ key,
975
+ operatorAddress,
976
+ enabled = true,
977
+ keyFormat
978
+ }) {
979
+ const storageKeyBytes = key ? getStorageKeyBytes(key, keyFormat) : void 0;
980
+ const {
981
+ data: chunkedTotal,
982
+ isLoading: chunkedLoading,
983
+ error: chunkedError
984
+ } = useReadContract({
985
+ abi: CHUNKED_STORAGE_READER_CONTRACT.abi,
986
+ address: CHUNKED_STORAGE_READER_CONTRACT.address,
987
+ functionName: "getTotalWrites",
988
+ args: storageKeyBytes && operatorAddress ? [storageKeyBytes, operatorAddress] : void 0,
989
+ chainId,
990
+ query: {
991
+ enabled: enabled && !!key && !!operatorAddress
992
+ }
993
+ });
994
+ const {
995
+ data: regularTotal,
996
+ isLoading: regularLoading,
997
+ error: regularError
998
+ } = useReadContract({
999
+ abi: STORAGE_CONTRACT.abi,
1000
+ address: STORAGE_CONTRACT.address,
1001
+ functionName: "getTotalWrites",
1002
+ args: storageKeyBytes && operatorAddress ? [storageKeyBytes, operatorAddress] : void 0,
1003
+ chainId,
1004
+ query: {
1005
+ enabled: enabled && !!key && !!operatorAddress && (chunkedTotal === void 0 || Number(chunkedTotal) === 0)
1006
+ }
1007
+ });
1008
+ const chunkedTotalNumber = chunkedTotal ? Number(chunkedTotal) : 0;
1009
+ const regularTotalNumber = regularTotal ? Number(regularTotal) : 0;
1010
+ const totalWrites = chunkedTotalNumber > 0 ? chunkedTotalNumber : regularTotalNumber;
1011
+ return {
1012
+ data: totalWrites > 0 ? totalWrites : void 0,
1013
+ isLoading: chunkedLoading || regularLoading,
1014
+ error: chunkedTotalNumber === 0 && regularTotalNumber === 0 ? chunkedError || regularError : void 0
1015
+ };
1016
+ }
1017
+ var MAX_XML_DEPTH = 3;
1018
+ var CONCURRENT_XML_FETCHES = 3;
1019
+ function assembleXmlData(metadata, chunks, references) {
1020
+ const tagPositions = [];
1021
+ for (let i = 0; i < references.length; i++) {
1022
+ const ref = references[i];
1023
+ const chunkData = chunks[i];
1024
+ if (!chunkData) continue;
1025
+ const indexAttr = ref.index !== void 0 ? ` i="${ref.index}"` : "";
1026
+ const operatorAttr = ref.operator ? ` o="${ref.operator}"` : "";
1027
+ const sourceAttr = ref.source ? ` s="${ref.source}"` : "";
1028
+ const xmlTag = `<net k="${ref.hash}" v="${ref.version}"${indexAttr}${operatorAttr}${sourceAttr} />`;
1029
+ const tagIndex = metadata.indexOf(xmlTag);
1030
+ if (tagIndex === -1) {
1031
+ continue;
1032
+ }
1033
+ tagPositions.push({
1034
+ ref,
1035
+ chunk: chunkData,
1036
+ start: tagIndex,
1037
+ end: tagIndex + xmlTag.length,
1038
+ tag: xmlTag
1039
+ });
1040
+ }
1041
+ tagPositions.sort((a, b) => b.start - a.start);
1042
+ let result = metadata;
1043
+ for (let i = 0; i < tagPositions.length; i++) {
1044
+ const { ref, chunk, start, end } = tagPositions[i];
1045
+ try {
1046
+ result = result.substring(0, start) + chunk + result.substring(end);
1047
+ } catch (error) {
1048
+ throw error;
1049
+ }
1050
+ }
1051
+ return result;
1052
+ }
1053
+ async function fetchFromDirectStorage(reference, operator, client) {
1054
+ const functionName = reference.index !== void 0 ? "getValueAtIndex" : "get";
1055
+ const args = reference.index !== void 0 ? [reference.hash, operator, reference.index] : [reference.hash, operator];
1056
+ const result = await readContract(client, {
1057
+ address: STORAGE_CONTRACT.address,
1058
+ abi: STORAGE_CONTRACT.abi,
1059
+ functionName,
1060
+ args
1061
+ });
1062
+ const content = hexToString(result[1] || "");
1063
+ return content;
1064
+ }
1065
+ async function fetchFromChunkedStorage(reference, operator, client) {
1066
+ const contract = CHUNKED_STORAGE_READER_CONTRACT;
1067
+ const functionName = reference.index !== void 0 ? "getMetadataAtIndex" : "getMetadata";
1068
+ const chunksFunctionName = reference.index !== void 0 ? "getChunksAtIndex" : "getChunks";
1069
+ const metadataArgs = reference.index !== void 0 ? [reference.hash, operator, reference.index] : [reference.hash, operator];
1070
+ const metadata = await readContract(client, {
1071
+ abi: contract.abi,
1072
+ address: contract.address,
1073
+ functionName,
1074
+ args: metadataArgs
1075
+ });
1076
+ const chunkCount = metadata[0];
1077
+ if (chunkCount === 0) return "";
1078
+ const chunksArgs = reference.index !== void 0 ? [reference.hash, operator, 0, chunkCount, reference.index] : [reference.hash, operator, 0, chunkCount];
1079
+ const chunks = await readContract(client, {
1080
+ abi: contract.abi,
1081
+ address: contract.address,
1082
+ functionName: chunksFunctionName,
1083
+ args: chunksArgs
1084
+ });
1085
+ const assembledResult = assembleChunks(chunks);
1086
+ const content = assembledResult || "";
1087
+ return content;
1088
+ }
1089
+ async function fetchSingleChunk(reference, defaultOperator, inheritedOperator, client) {
1090
+ const effectiveOperator = reference.operator || inheritedOperator || defaultOperator;
1091
+ if (reference.source === "d") {
1092
+ return await fetchFromDirectStorage(reference, effectiveOperator, client);
1093
+ } else {
1094
+ return await fetchFromChunkedStorage(reference, effectiveOperator, client);
1095
+ }
1096
+ }
1097
+ async function resolveXmlRecursive(content, defaultOperator, client, maxDepth, visited = /* @__PURE__ */ new Set(), inheritedOperator) {
1098
+ if (maxDepth <= 0) {
1099
+ return content;
1100
+ }
1101
+ if (!containsXmlReferences(content)) {
1102
+ return content;
1103
+ }
1104
+ const references = parseNetReferences(content);
1105
+ if (references.length === 0) {
1106
+ return content;
1107
+ }
1108
+ const resolvedChunks = [];
1109
+ for (let batchStart = 0; batchStart < references.length; batchStart += CONCURRENT_XML_FETCHES) {
1110
+ const batchEnd = Math.min(
1111
+ batchStart + CONCURRENT_XML_FETCHES,
1112
+ references.length
1113
+ );
1114
+ const batch = references.slice(batchStart, batchEnd);
1115
+ const batchResults = await Promise.all(
1116
+ batch.map(async (ref, batchIndex) => {
1117
+ const index = batchStart + batchIndex;
1118
+ const effectiveOperator = ref.operator || inheritedOperator || defaultOperator;
1119
+ const refKey = getReferenceKey(
1120
+ { ...ref, operator: effectiveOperator },
1121
+ defaultOperator
1122
+ );
1123
+ if (visited.has(refKey)) {
1124
+ console.warn(
1125
+ `[resolveXmlRecursive] Circular reference detected: ${refKey}`
1126
+ );
1127
+ return `[Circular: ${refKey}]`;
1128
+ }
1129
+ const newVisited = new Set(visited);
1130
+ newVisited.add(refKey);
1131
+ try {
1132
+ const chunkContent = await fetchSingleChunk(
1133
+ ref,
1134
+ defaultOperator,
1135
+ inheritedOperator,
1136
+ client
1137
+ );
1138
+ const resolvedContent = await resolveXmlRecursive(
1139
+ chunkContent,
1140
+ defaultOperator,
1141
+ client,
1142
+ maxDepth - 1,
1143
+ newVisited,
1144
+ effectiveOperator
1145
+ // Pass the effective operator to children
1146
+ );
1147
+ return resolvedContent;
1148
+ } catch (error) {
1149
+ console.error(
1150
+ `[resolveXmlRecursive] Failed to fetch/resolve chunk ${index}:`,
1151
+ error
1152
+ );
1153
+ return "";
1154
+ }
1155
+ })
1156
+ );
1157
+ resolvedChunks.push(...batchResults);
1158
+ }
1159
+ const assembled = assembleXmlData(content, resolvedChunks, references);
1160
+ return assembled;
1161
+ }
1162
+ function useXmlStorage({
1163
+ chainId,
1164
+ key,
1165
+ operatorAddress,
1166
+ skipXmlParsing = false,
1167
+ enabled = true,
1168
+ content,
1169
+ index,
1170
+ keyFormat,
1171
+ useRouter,
1172
+ outputFormat = "hex"
1173
+ }) {
1174
+ const isPreviewMode = !!content;
1175
+ const outputAsString = outputFormat === "string";
1176
+ const {
1177
+ data: metadata,
1178
+ isLoading: metadataLoading,
1179
+ error: metadataError
1180
+ } = useStorage({
1181
+ chainId,
1182
+ key: key || "",
1183
+ operatorAddress,
1184
+ enabled: enabled && !isPreviewMode,
1185
+ index,
1186
+ // Pass index to useStorage for historical versions
1187
+ keyFormat,
1188
+ // Pass keyFormat through
1189
+ useRouter,
1190
+ // Pass useRouter through to enable router path
1191
+ outputFormat: "string"
1192
+ // Always get plain string from useStorage, then convert based on our outputFormat
1193
+ });
1194
+ const metadataString = useMemo(() => {
1195
+ if (skipXmlParsing) return "";
1196
+ if (isPreviewMode) return content || "";
1197
+ if (!metadata?.value) return "";
1198
+ return metadata.value;
1199
+ }, [skipXmlParsing, isPreviewMode, content, metadata]);
1200
+ useMemo(() => {
1201
+ if (!metadataString) return [];
1202
+ return parseNetReferences(metadataString);
1203
+ }, [metadataString]);
1204
+ const [chunks, setChunks] = useState([]);
1205
+ const [chunksLoading, setChunksLoading] = useState(false);
1206
+ const [chunksError, setChunksError] = useState();
1207
+ useAsyncEffect(async () => {
1208
+ if (skipXmlParsing || !metadataString) {
1209
+ setChunks([]);
1210
+ setChunksLoading(false);
1211
+ return;
1212
+ }
1213
+ if (!containsXmlReferences(metadataString)) {
1214
+ setChunks([]);
1215
+ setChunksLoading(false);
1216
+ return;
1217
+ }
1218
+ setChunksLoading(true);
1219
+ setChunksError(void 0);
1220
+ try {
1221
+ const client = getPublicClient({ chainId });
1222
+ if (!client) {
1223
+ throw new Error(`Chain not found for chainId: ${chainId}`);
1224
+ }
1225
+ const resolved = await resolveXmlRecursive(
1226
+ metadataString,
1227
+ operatorAddress,
1228
+ client,
1229
+ MAX_XML_DEPTH,
1230
+ /* @__PURE__ */ new Set()
1231
+ );
1232
+ setChunks([resolved]);
1233
+ } catch (error) {
1234
+ console.error("[useXmlStorage] Error in recursive resolution:", error);
1235
+ setChunksError(error);
1236
+ setChunks([]);
1237
+ } finally {
1238
+ setChunksLoading(false);
1239
+ }
1240
+ }, [metadataString, operatorAddress, chainId, skipXmlParsing]);
1241
+ const assembledData = useMemo(() => {
1242
+ if (skipXmlParsing || !metadataString || !chunks.length) return void 0;
1243
+ return chunks[0];
1244
+ }, [metadataString, chunks, skipXmlParsing]);
1245
+ const isXml = useMemo(() => {
1246
+ if (skipXmlParsing || !metadataString) return false;
1247
+ return containsXmlReferences(metadataString);
1248
+ }, [metadataString, skipXmlParsing]);
1249
+ const formatValue = (value) => {
1250
+ if (!value) return "";
1251
+ return outputAsString ? value : stringToHex(value);
1252
+ };
1253
+ if (skipXmlParsing) {
1254
+ return {
1255
+ text: metadata?.text || "",
1256
+ value: isPreviewMode ? content || "" : formatValue(metadata?.value),
1257
+ isLoading: metadataLoading,
1258
+ error: metadataError,
1259
+ isXml: false
1260
+ };
1261
+ }
1262
+ return {
1263
+ text: metadata?.text || "",
1264
+ value: isXml ? formatValue(assembledData) : isPreviewMode ? content || "" : formatValue(metadata?.value),
1265
+ isLoading: metadataLoading || isXml && chunksLoading,
1266
+ error: metadataError || chunksError,
1267
+ isXml
1268
+ };
1269
+ }
1270
+ var BATCH_SIZE2 = 2;
1271
+ function useStorageFromRouter({
1272
+ chainId,
1273
+ storageKey,
1274
+ operatorAddress,
1275
+ enabled = true
1276
+ }) {
1277
+ const [assembledData, setAssembledData] = useState();
1278
+ const [isChunkLoading, setIsChunkLoading] = useState(false);
1279
+ const [chunkError, setChunkError] = useState();
1280
+ const {
1281
+ data: routerResult,
1282
+ isLoading: routerLoading,
1283
+ error: routerError
1284
+ } = useReadContract({
1285
+ abi: STORAGE_ROUTER_CONTRACT.abi,
1286
+ address: STORAGE_ROUTER_CONTRACT.address,
1287
+ functionName: "get",
1288
+ args: [storageKey, operatorAddress],
1289
+ chainId,
1290
+ query: {
1291
+ enabled: enabled && !!operatorAddress
1292
+ }
1293
+ });
1294
+ useEffect(() => {
1295
+ async function processResult() {
1296
+ if (!routerResult || routerLoading || routerError) {
1297
+ return;
1298
+ }
1299
+ const [isChunkedStorage, text, data] = routerResult;
1300
+ if (!isChunkedStorage) {
1301
+ setAssembledData({ text, value: data });
1302
+ return;
1303
+ }
1304
+ setIsChunkLoading(true);
1305
+ setChunkError(void 0);
1306
+ try {
1307
+ const [chunkCount] = decodeAbiParameters([{ type: "uint8" }], data);
1308
+ if (chunkCount === 0) {
1309
+ setAssembledData(void 0);
1310
+ return;
1311
+ }
1312
+ const allChunks = await fetchChunksInBatches(
1313
+ Number(chunkCount),
1314
+ operatorAddress,
1315
+ chainId,
1316
+ storageKey
1317
+ );
1318
+ const assembledString = assembleChunks(allChunks);
1319
+ if (assembledString === void 0) {
1320
+ setAssembledData(void 0);
1321
+ } else {
1322
+ const hexData = stringToHex(assembledString);
1323
+ setAssembledData({ text, value: hexData });
1324
+ }
1325
+ } catch (error) {
1326
+ setChunkError(error);
1327
+ } finally {
1328
+ setIsChunkLoading(false);
1329
+ }
1330
+ }
1331
+ processResult();
1332
+ }, [
1333
+ routerResult,
1334
+ routerLoading,
1335
+ routerError,
1336
+ operatorAddress,
1337
+ chainId,
1338
+ storageKey
1339
+ ]);
1340
+ return {
1341
+ data: assembledData,
1342
+ isLoading: routerLoading || isChunkLoading,
1343
+ error: routerError || chunkError
1344
+ };
1345
+ }
1346
+ async function fetchChunksInBatches(chunkCount, operatorAddress, chainId, storageKey) {
1347
+ const client = getPublicClient({ chainId });
1348
+ if (!client) {
1349
+ throw new Error(`Chain not found for chainId: ${chainId}`);
1350
+ }
1351
+ const allChunks = [];
1352
+ for (let start = 0; start < chunkCount; start += BATCH_SIZE2) {
1353
+ const end = Math.min(start + BATCH_SIZE2, chunkCount);
1354
+ const batch = await readContract(client, {
1355
+ abi: CHUNKED_STORAGE_CONTRACT.abi,
1356
+ address: CHUNKED_STORAGE_CONTRACT.address,
1357
+ functionName: "getChunks",
1358
+ args: [storageKey, operatorAddress, start, end]
1359
+ });
1360
+ allChunks.push(...batch);
1361
+ }
1362
+ return allChunks;
1363
+ }
1364
+
1365
+ export { useBulkStorage, useStorage, useStorageForOperator, useStorageForOperatorAndKey, useStorageFromRouter, useStorageTotalWrites, useXmlStorage };
1366
+ //# sourceMappingURL=react.mjs.map
1367
+ //# sourceMappingURL=react.mjs.map