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