@xyo-network/react-chain-blockchain 1.2.8 → 1.3.0

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.
Files changed (29) hide show
  1. package/dist/browser/index.mjs +308 -313
  2. package/dist/browser/index.mjs.map +1 -1
  3. package/dist/types/components/block/helpers/buildBlockChainRenderComponent.d.ts +0 -1
  4. package/dist/types/components/block/helpers/buildBlockChainRenderComponent.d.ts.map +1 -1
  5. package/dist/types/components/block/helpers/index.d.ts +0 -1
  6. package/dist/types/components/block/helpers/index.d.ts.map +1 -1
  7. package/dist/types/components/block/hooks/index.d.ts +0 -1
  8. package/dist/types/components/block/hooks/index.d.ts.map +1 -1
  9. package/dist/types/helpers/index.d.ts +2 -0
  10. package/dist/types/helpers/index.d.ts.map +1 -0
  11. package/dist/types/{components/block/helpers/tsxFromBlock.d.ts → helpers/txsFromBlock.d.ts} +2 -2
  12. package/dist/types/helpers/txsFromBlock.d.ts.map +1 -0
  13. package/dist/types/hooks/index.d.ts +1 -0
  14. package/dist/types/hooks/index.d.ts.map +1 -1
  15. package/dist/types/{components/block/hooks → hooks}/useTxsFromBlock.d.ts +1 -1
  16. package/dist/types/hooks/useTxsFromBlock.d.ts.map +1 -0
  17. package/package.json +17 -17
  18. package/src/components/block/helpers/buildBlockChainRenderComponent.tsx +1 -8
  19. package/src/components/block/helpers/index.ts +0 -1
  20. package/src/components/block/helpers/payloadCountsFromBlock.ts +1 -1
  21. package/src/components/block/hooks/index.ts +0 -1
  22. package/src/components/block/table/cell/TransactionCount.tsx +1 -1
  23. package/src/components/transactions/TransactionsQuickTipButton.tsx +1 -1
  24. package/src/helpers/index.ts +1 -0
  25. package/src/{components/block/helpers/tsxFromBlock.ts → helpers/txsFromBlock.ts} +2 -1
  26. package/src/hooks/index.ts +1 -0
  27. package/src/{components/block/hooks → hooks}/useTxsFromBlock.ts +2 -2
  28. package/dist/types/components/block/helpers/tsxFromBlock.d.ts.map +0 -1
  29. package/dist/types/components/block/hooks/useTxsFromBlock.d.ts.map +0 -1
@@ -335,12 +335,285 @@ import { Alert as Alert2, AlertTitle, Collapse, Snackbar, Typography as Typograp
335
335
  import { ErrorRender as ErrorRender2 } from "@xylabs/react-error";
336
336
  import { FlexGrowCol as FlexGrowCol2, FlexGrowRow, FlexRow } from "@xylabs/react-flexbox";
337
337
  import { QuickTipButton } from "@xylabs/react-quick-tip-button";
338
- import React8, { Fragment, useMemo as useMemo5, useState as useState6 } from "react";
338
+ import React8, { Fragment, useMemo as useMemo6, useState as useState7 } from "react";
339
+
340
+ // src/hooks/chain-iterator/ChainIteratorStore.ts
341
+ import { assertEx } from "@xylabs/assert";
342
+ import { hydrateBlock } from "@xyo-network/chain-protocol";
343
+ import { XyoChainBlockNumberIterator } from "@xyo-network/chain-services";
344
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
345
+ var ChainIteratorStore = class _ChainIteratorStore {
346
+ static {
347
+ __name(this, "ChainIteratorStore");
348
+ }
349
+ _chainIterator;
350
+ _externalListeners = [];
351
+ _internalUnsubscribes = [];
352
+ _values;
353
+ get chainIterator() {
354
+ return assertEx(this._chainIterator, () => "ChainIteratorStore has not been initialized");
355
+ }
356
+ get values() {
357
+ return assertEx(this._values, () => "ChainIteratorStore values have not been initialized");
358
+ }
359
+ static async create(params) {
360
+ const instance = new _ChainIteratorStore();
361
+ const chainIterator = await XyoChainBlockNumberIterator.create(params);
362
+ instance._chainIterator = chainIterator;
363
+ const head = await chainIterator.head();
364
+ const hydratedHead = await hydrateBlock(params.chainArchivist, await PayloadBuilder2.hash(head));
365
+ instance._values = {
366
+ chainIterator,
367
+ head: hydratedHead
368
+ };
369
+ const headUpdatedListener = /* @__PURE__ */ __name(async ({ blocks }) => {
370
+ const hydratedBlock = await hydrateBlock(params.chainArchivist, await PayloadBuilder2.hash(blocks?.[0]));
371
+ instance._values = {
372
+ chainIterator,
373
+ head: hydratedBlock
374
+ };
375
+ instance.emitChange();
376
+ }, "headUpdatedListener");
377
+ const unsubscribe = chainIterator.on("headUpdated", headUpdatedListener);
378
+ const weakRefListener = new WeakRef(unsubscribe);
379
+ instance._internalUnsubscribes.push(weakRefListener);
380
+ return instance;
381
+ }
382
+ cleanup() {
383
+ for (const unsubscribeRef of this._internalUnsubscribes) {
384
+ const unsubscribe = unsubscribeRef.deref();
385
+ unsubscribe?.();
386
+ }
387
+ }
388
+ getSnapshot() {
389
+ return this.values;
390
+ }
391
+ subscribe(onStoreChange) {
392
+ this._externalListeners.push(onStoreChange);
393
+ return () => {
394
+ this._externalListeners = this._externalListeners.filter((l) => l !== onStoreChange);
395
+ };
396
+ }
397
+ emitChange() {
398
+ for (const listener of this._externalListeners) {
399
+ listener();
400
+ }
401
+ }
402
+ };
403
+
404
+ // src/hooks/chain-iterator/useChainIteratorParams.ts
405
+ import { assertEx as assertEx2 } from "@xylabs/assert";
406
+ import { usePromise } from "@xylabs/react-promise";
407
+ import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
408
+ import { isBlockBoundWitness } from "@xyo-network/xl1-model";
409
+ var resolveDefinedHead = /* @__PURE__ */ __name(async (head, chainArchivist) => {
410
+ const [headPayload] = await chainArchivist.get([
411
+ head
412
+ ]);
413
+ if (headPayload === void 0) {
414
+ const [currentHead] = await new BoundWitnessBuilder().build();
415
+ return currentHead;
416
+ } else {
417
+ return assertEx2(isBlockBoundWitness(headPayload) ? headPayload : void 0, () => `Expected a block bound witness: ${JSON.stringify(headPayload)}`);
418
+ }
419
+ }, "resolveDefinedHead");
420
+ var useChainIteratorParams = /* @__PURE__ */ __name(({ chainArchivist, chainInformation, head }) => {
421
+ return usePromise(async () => {
422
+ if (chainArchivist && chainInformation && head) {
423
+ const [result] = await chainArchivist.get([
424
+ head
425
+ ]);
426
+ const foundResult = assertEx2(result, () => `Head not found: ${head}`);
427
+ const resolvedHead = assertEx2(isBlockBoundWitness(foundResult) ? foundResult : void 0, () => `Head is not a boundwitness: ${JSON.stringify(foundResult)}`);
428
+ return {
429
+ chainArchivist,
430
+ chainInformation,
431
+ head: resolvedHead
432
+ };
433
+ }
434
+ }, [
435
+ chainArchivist,
436
+ chainInformation,
437
+ head
438
+ ]);
439
+ }, "useChainIteratorParams");
440
+
441
+ // src/hooks/chain-iterator/useChainIteratorStore.ts
442
+ import { usePromise as usePromise2 } from "@xylabs/react-promise";
443
+ import { useEffect as useEffect2, useMemo as useMemo5, useRef, useSyncExternalStore } from "react";
444
+
445
+ // src/hooks/chain-iterator/useChainIteratorUpdatingHead.ts
446
+ import { toHex as toHex2 } from "@xylabs/hex";
447
+ import { findMostRecentBlock } from "@xyo-network/chain-protocol";
448
+ import { useEffect, useState as useState6 } from "react";
449
+ var useChainIteratorUpdatingHead = /* @__PURE__ */ __name(({ chainIterator, interval = 500, maxBlocks, chainArchivist }) => {
450
+ const [error, setError] = useState6();
451
+ useEffect(() => {
452
+ let pollArchivistTimeout;
453
+ const pollingFunction = /* @__PURE__ */ __name(async () => {
454
+ if (chainIterator && chainArchivist) {
455
+ try {
456
+ const currentHead = await chainIterator.head();
457
+ const mostRecentBlock = await findMostRecentBlock(chainArchivist);
458
+ if (currentHead && mostRecentBlock) {
459
+ const currentBlockNumber = currentHead?.block ?? -1;
460
+ const nextBlockNumber = mostRecentBlock.block;
461
+ if (nextBlockNumber > currentBlockNumber) {
462
+ console.debug("Found more recent head:", toHex2(nextBlockNumber));
463
+ console.debug("Updating head:", `${toHex2(nextBlockNumber)}`);
464
+ await chainIterator.updateHead(mostRecentBlock);
465
+ console.debug("Updated head:", `${toHex2(nextBlockNumber)}`);
466
+ }
467
+ }
468
+ } catch (e) {
469
+ setError(e);
470
+ console.error(e);
471
+ }
472
+ }
473
+ pollArchivistTimeout = setTimeout(() => void pollingFunction(), interval);
474
+ }, "pollingFunction");
475
+ void pollingFunction();
476
+ return () => clearInterval(pollArchivistTimeout);
477
+ }, [
478
+ interval,
479
+ chainIterator,
480
+ chainArchivist,
481
+ maxBlocks
482
+ ]);
483
+ return error;
484
+ }, "useChainIteratorUpdatingHead");
485
+
486
+ // src/hooks/chain-iterator/useChainIteratorStore.ts
487
+ var stub = {};
488
+ var useChainIteratorStore = /* @__PURE__ */ __name((chainIteratorParams) => {
489
+ const [chainIteratorStore] = usePromise2(async () => {
490
+ return chainIteratorParams ? await ChainIteratorStore.create(chainIteratorParams) : void 0;
491
+ }, [
492
+ chainIteratorParams
493
+ ]);
494
+ const { chainIterator } = chainIteratorStore || {};
495
+ const chainArchivist = chainIteratorParams?.chainArchivist;
496
+ const error = useChainIteratorUpdatingHead({
497
+ chainIterator,
498
+ chainArchivist
499
+ });
500
+ useEffect2(() => {
501
+ return () => {
502
+ if (chainIteratorStore) {
503
+ chainIteratorStore.cleanup();
504
+ }
505
+ };
506
+ }, [
507
+ chainIteratorStore
508
+ ]);
509
+ const cachedSnapshot = useRef({});
510
+ const { getSnapShot, subscribe } = useMemo5(() => {
511
+ if (chainIteratorStore) {
512
+ return {
513
+ getSnapShot: /* @__PURE__ */ __name(() => {
514
+ const snapshot = chainIteratorStore.getSnapshot();
515
+ const newValues = {
516
+ ...snapshot,
517
+ error
518
+ };
519
+ const noCachedValue = cachedSnapshot.current.chainIterator === void 0;
520
+ const cachedBlock = cachedSnapshot.current?.head?.[0]?.block;
521
+ const newBlock = cachedBlock !== newValues.head?.[0]?.block;
522
+ if (noCachedValue || newBlock) {
523
+ cachedSnapshot.current = newValues;
524
+ return newValues;
525
+ }
526
+ return cachedSnapshot.current;
527
+ }, "getSnapShot"),
528
+ subscribe: chainIteratorStore.subscribe.bind(chainIteratorStore)
529
+ };
530
+ }
531
+ return {
532
+ getSnapShot: /* @__PURE__ */ __name(() => stub, "getSnapShot"),
533
+ subscribe: /* @__PURE__ */ __name(() => () => {
534
+ }, "subscribe")
535
+ };
536
+ }, [
537
+ chainIteratorStore
538
+ ]);
539
+ return useSyncExternalStore(subscribe, getSnapShot);
540
+ }, "useChainIteratorStore");
541
+
542
+ // src/hooks/useIterateChain.ts
543
+ import { assertEx as assertEx3 } from "@xylabs/assert";
544
+ import { usePromise as usePromise3 } from "@xylabs/react-promise";
545
+ import { hydrateBlock as hydrateBlock2 } from "@xyo-network/chain-protocol";
546
+ import { XyoChainBlockNumberIterator as XyoChainBlockNumberIterator2 } from "@xyo-network/chain-services";
547
+ import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
548
+ import { isBlockBoundWitness as isBlockBoundWitness2 } from "@xyo-network/xl1-model";
549
+ var getHydratedBlock = /* @__PURE__ */ __name(async (chainArchivist, head) => {
550
+ const headHash = await PayloadBuilder3.hash(head);
551
+ return await hydrateBlock2(chainArchivist, headHash);
552
+ }, "getHydratedBlock");
553
+ var iterateChain = /* @__PURE__ */ __name(async (chainIteratorParams, maxDepth) => {
554
+ const { chainArchivist, head } = chainIteratorParams ?? {};
555
+ if (chainArchivist && head) {
556
+ const headPayload = assertEx3(isBlockBoundWitness2(head) ? head : null, () => "Head is not a Block Bound Witness");
557
+ const headBlockBoundWitness = assertEx3(isBlockBoundWitness2(headPayload) ? headPayload : null, () => "Invalid head block");
558
+ const chainIterator = await XyoChainBlockNumberIterator2.create({
559
+ head: headBlockBoundWitness,
560
+ chainArchivist
561
+ });
562
+ const chainHead = await chainIterator.head();
563
+ let block = await getHydratedBlock(chainArchivist, chainHead);
564
+ const blocks = [
565
+ block
566
+ ];
567
+ let depth = 1;
568
+ while (block) {
569
+ const [, next] = await chainIterator.previous(block[0].block, 2);
570
+ if (!next) break;
571
+ const nextHydratedBlock = await getHydratedBlock(chainArchivist, next);
572
+ blocks.push(nextHydratedBlock);
573
+ block = nextHydratedBlock;
574
+ depth++;
575
+ if (maxDepth && depth >= maxDepth || block?.[0].block === 0) break;
576
+ }
577
+ return blocks;
578
+ }
579
+ }, "iterateChain");
580
+ var useIterateChain = /* @__PURE__ */ __name((chainIteratorParams, maxDepth) => {
581
+ return usePromise3(async () => {
582
+ return await iterateChain(chainIteratorParams, maxDepth);
583
+ }, [
584
+ chainIteratorParams,
585
+ maxDepth
586
+ ]);
587
+ }, "useIterateChain");
588
+
589
+ // src/hooks/useTxsFromBlock.ts
590
+ import { usePromise as usePromise4 } from "@xylabs/react-promise";
591
+
592
+ // src/helpers/txsFromBlock.ts
593
+ import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
594
+ import { isTransactionBoundWitness } from "@xyo-network/xl1-model";
595
+ var txsFromBlock = /* @__PURE__ */ __name(async (block) => {
596
+ const transactionPayloads = block[1].filter((payload) => isTransactionBoundWitness(payload));
597
+ return await PayloadBuilder4.hashPairs(transactionPayloads);
598
+ }, "txsFromBlock");
599
+
600
+ // src/hooks/useTxsFromBlock.ts
601
+ var useTxsFromBlock = /* @__PURE__ */ __name((block) => {
602
+ return usePromise4(async () => {
603
+ if (block) {
604
+ return await txsFromBlock(block);
605
+ }
606
+ }, [
607
+ block
608
+ ]);
609
+ }, "useTxsFromBlock");
610
+
611
+ // src/components/transactions/TransactionsQuickTipButton.tsx
339
612
  var TransactionsQuickTipButton = /* @__PURE__ */ __name(({ block, ...props }) => {
340
613
  const [transactions, transactionsError] = useTxsFromBlock(block);
341
- const [copied, setCopied] = useState6(false);
342
- const [showError, setShowError] = useState6(false);
343
- useMemo5(() => transactionsError ? setShowError(true) : setShowError(false), [
614
+ const [copied, setCopied] = useState7(false);
615
+ const [showError, setShowError] = useState7(false);
616
+ useMemo6(() => transactionsError ? setShowError(true) : setShowError(false), [
344
617
  transactionsError
345
618
  ]);
346
619
  const onCopy = /* @__PURE__ */ __name(async (transactionHash) => {
@@ -392,10 +665,10 @@ var TransactionsQuickTipButton = /* @__PURE__ */ __name(({ block, ...props }) =>
392
665
  }, "TransactionsQuickTipButton");
393
666
 
394
667
  // src/components/block/hooks/useAnchorElement.ts
395
- import { useRef, useState as useState7 } from "react";
668
+ import { useRef as useRef2, useState as useState8 } from "react";
396
669
  var useAnchorElement = /* @__PURE__ */ __name(() => {
397
- const [anchorEl, setAnchorEl] = useState7(null);
398
- const anchorRef = useRef(null);
670
+ const [anchorEl, setAnchorEl] = useState8(null);
671
+ const anchorRef = useRef2(null);
399
672
  const open = Boolean(anchorEl);
400
673
  const handleClick = /* @__PURE__ */ __name((event) => {
401
674
  setAnchorEl(event.currentTarget);
@@ -419,9 +692,9 @@ var useBlockHeadingEvents = /* @__PURE__ */ __name((...args) => {
419
692
  }, "useBlockHeadingEvents");
420
693
 
421
694
  // src/components/block/hooks/useBlockProducer.ts
422
- import { useMemo as useMemo6 } from "react";
695
+ import { useMemo as useMemo7 } from "react";
423
696
  var useBlockProducer = /* @__PURE__ */ __name((block) => {
424
- return useMemo6(() => {
697
+ return useMemo7(() => {
425
698
  if (block) {
426
699
  const producer = block[0].addresses[0];
427
700
  return producer;
@@ -432,7 +705,7 @@ var useBlockProducer = /* @__PURE__ */ __name((block) => {
432
705
  }, "useBlockProducer");
433
706
 
434
707
  // src/components/block/hooks/useDynamicBlockComponents.ts
435
- import { useState as useState8 } from "react";
708
+ import { useState as useState9 } from "react";
436
709
 
437
710
  // src/components/block/helpers/blockProducer.ts
438
711
  var blockProducer = /* @__PURE__ */ __name((block) => {
@@ -441,16 +714,6 @@ var blockProducer = /* @__PURE__ */ __name((block) => {
441
714
 
442
715
  // src/components/block/helpers/buildBlockChainRenderComponent.tsx
443
716
  import React9 from "react";
444
-
445
- // src/components/block/helpers/tsxFromBlock.ts
446
- import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
447
- import { isTransactionBoundWitness } from "@xyo-network/xl1-model";
448
- var txsFromBlock = /* @__PURE__ */ __name(async (block) => {
449
- const transactionPayloads = block[1].filter((payload) => isTransactionBoundWitness(payload));
450
- return await PayloadBuilder2.hashPairs(transactionPayloads);
451
- }, "txsFromBlock");
452
-
453
- // src/components/block/helpers/buildBlockChainRenderComponent.tsx
454
717
  var buildBlockChainRenderComponent = /* @__PURE__ */ __name(async (BlockComponent, blockComponentProps) => {
455
718
  const { block, ...remainingProps } = blockComponentProps;
456
719
  const blockTxs = await txsFromBlock(block);
@@ -466,9 +729,6 @@ var buildBlockChainRenderComponent = /* @__PURE__ */ __name(async (BlockComponen
466
729
  };
467
730
  return item;
468
731
  }, "buildBlockChainRenderComponent");
469
- var buildBlockHeadingComponent = /* @__PURE__ */ __name(async (blockComponentProps) => {
470
- return await buildBlockChainRenderComponent(BlockHeadingFlexbox, blockComponentProps);
471
- }, "buildBlockHeadingComponent");
472
732
 
473
733
  // src/components/block/helpers/payloadCountsFromBlock.ts
474
734
  import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
@@ -478,7 +738,7 @@ var payloadCountsFromBlock = /* @__PURE__ */ __name(([block, payloads]) => {
478
738
  const transactionPayloads = payloads.filter((payload) => isTransactionBoundWitness2(payload));
479
739
  let privPayloadsCount = 0;
480
740
  for (let tx of transactionPayloads) {
481
- privPayloadsCount += tx.payload_hashes.length - tx.$opCodes.filter((opCode) => !opCode.startsWith("elevate|")).length;
741
+ privPayloadsCount += tx.payload_hashes.length - tx.script.filter((operation) => !operation.startsWith("elevate|")).length;
482
742
  }
483
743
  return [
484
744
  privPayloads.length,
@@ -489,7 +749,7 @@ var payloadCountsFromBlock = /* @__PURE__ */ __name(([block, payloads]) => {
489
749
  // src/components/block/hooks/useDynamicBlockComponents.ts
490
750
  var useDynamicBlockComponents = /* @__PURE__ */ __name((BlockComponent, params, maxBlocks) => {
491
751
  const { chainArchivist } = params ?? {};
492
- const [blockChainRenderComponents, setBlockChainRenderComponents] = useState8([]);
752
+ const [blockChainRenderComponents, setBlockChainRenderComponents] = useState9([]);
493
753
  const { onBlock } = useChainAnalyzersContext();
494
754
  const onAddBlock = /* @__PURE__ */ __name(async (block) => {
495
755
  if (!block || !chainArchivist) return;
@@ -518,9 +778,9 @@ var useDynamicBlockComponents = /* @__PURE__ */ __name((BlockComponent, params,
518
778
  }, "useDynamicBlockComponents");
519
779
 
520
780
  // src/components/block/hooks/usePayloadCountsFromBlock.ts
521
- import { useMemo as useMemo7 } from "react";
781
+ import { useMemo as useMemo8 } from "react";
522
782
  var usePayloadCountsFromBlock = /* @__PURE__ */ __name((block) => {
523
- return useMemo7(() => {
783
+ return useMemo8(() => {
524
784
  if (block) {
525
785
  return [
526
786
  ...payloadCountsFromBlock(block),
@@ -538,10 +798,10 @@ var usePayloadCountsFromBlock = /* @__PURE__ */ __name((block) => {
538
798
  }, "usePayloadCountsFromBlock");
539
799
 
540
800
  // src/components/block/hooks/useStaticBlockComponents.ts
541
- import { usePromise } from "@xylabs/react-promise";
801
+ import { usePromise as usePromise5 } from "@xylabs/react-promise";
542
802
  var useStaticBlockComponents = /* @__PURE__ */ __name((BlockComponent, params, blocks) => {
543
803
  const { onBlock } = useChainAnalyzersContext();
544
- const [blockComponents, blockComponentsError] = usePromise(async () => {
804
+ const [blockComponents, blockComponentsError] = usePromise5(async () => {
545
805
  const resolvedBlockWithStorage = blocks ?? [];
546
806
  if (!params?.chainArchivist) return [];
547
807
  const { chainArchivist } = params;
@@ -566,18 +826,6 @@ var useStaticBlockComponents = /* @__PURE__ */ __name((BlockComponent, params, b
566
826
  };
567
827
  }, "useStaticBlockComponents");
568
828
 
569
- // src/components/block/hooks/useTxsFromBlock.ts
570
- import { usePromise as usePromise2 } from "@xylabs/react-promise";
571
- var useTxsFromBlock = /* @__PURE__ */ __name((block) => {
572
- return usePromise2(async () => {
573
- if (block) {
574
- return await txsFromBlock(block);
575
- }
576
- }, [
577
- block
578
- ]);
579
- }, "useTxsFromBlock");
580
-
581
829
  // src/components/block/LinkedDivider.tsx
582
830
  import { Divider, Stack } from "@mui/material";
583
831
  import React10 from "react";
@@ -638,11 +886,11 @@ var BlockMenuExpanded = /* @__PURE__ */ __name(({ block }) => {
638
886
  import { Chip as Chip2 } from "@mui/material";
639
887
  import { EthAddress } from "@xylabs/eth-address";
640
888
  import { BlockiesAvatar } from "@xyo-network/react-chain-blockies";
641
- import React12, { useMemo as useMemo8 } from "react";
889
+ import React12, { useMemo as useMemo9 } from "react";
642
890
  var BlockProducerChip = /* @__PURE__ */ __name(({ block, ...props }) => {
643
891
  const blockProducer2 = block?.[0].addresses[0];
644
892
  const shortedBlockProducer = blockProducer2 ? EthAddress.parse(blockProducer2)?.toShortString(3) : null;
645
- const avatar = useMemo8(() => blockProducer2 === "" ? void 0 : /* @__PURE__ */ React12.createElement(BlockiesAvatar, {
893
+ const avatar = useMemo9(() => blockProducer2 === "" ? void 0 : /* @__PURE__ */ React12.createElement(BlockiesAvatar, {
646
894
  blockiesOptions: {
647
895
  seed: blockProducer2
648
896
  }
@@ -801,9 +1049,9 @@ import { ellipsize } from "@xylabs/eth-address";
801
1049
  import { FlexRow as FlexRow3 } from "@xylabs/react-flexbox";
802
1050
  import { JsonViewerEx } from "@xyo-network/react-payload-raw-info";
803
1051
  import { usePayloadRootHash as usePayloadRootHash2 } from "@xyo-network/react-shared";
804
- import React17, { useState as useState9 } from "react";
1052
+ import React17, { useState as useState10 } from "react";
805
1053
  var BlockJsonViewTableCell = /* @__PURE__ */ __name(({ block, ...props }) => {
806
- const [open, setOpen] = useState9(false);
1054
+ const [open, setOpen] = useState10(false);
807
1055
  const onClose = /* @__PURE__ */ __name(() => setOpen(false), "onClose");
808
1056
  const hash = usePayloadRootHash2(block?.[0]);
809
1057
  const title = hash ? `JSON for ${ellipsize(hash, 5)}` : "JSON";
@@ -995,16 +1243,16 @@ BlockchainTableEx.displayName = "BlockchainTableEx";
995
1243
 
996
1244
  // src/components/block/table/row/TableRow.tsx
997
1245
  import { TableRow as TableRow2 } from "@mui/material";
998
- import React24, { useMemo as useMemo9 } from "react";
1246
+ import React24, { useMemo as useMemo10 } from "react";
999
1247
  var BlockChainTableRow = /* @__PURE__ */ __name(({ block, defaultExpanded, linked, sx, ...props }) => {
1000
- const linkedTableCellProps = useMemo9(() => ({
1248
+ const linkedTableCellProps = useMemo10(() => ({
1001
1249
  block,
1002
1250
  linked
1003
1251
  }), [
1004
1252
  block,
1005
1253
  linked
1006
1254
  ]);
1007
- const defaultTableCellProps = useMemo9(() => ({
1255
+ const defaultTableCellProps = useMemo10(() => ({
1008
1256
  block
1009
1257
  }), [
1010
1258
  block
@@ -1036,14 +1284,14 @@ import React29, { memo } from "react";
1036
1284
  // src/components/chain/stats/Dialog.tsx
1037
1285
  import { QueryStats } from "@mui/icons-material";
1038
1286
  import { Dialog as Dialog3, DialogContent as DialogContent3, DialogTitle as DialogTitle3, IconButton as IconButton3 } from "@mui/material";
1039
- import React27, { useState as useState10 } from "react";
1287
+ import React27, { useState as useState11 } from "react";
1040
1288
 
1041
1289
  // src/components/chain/stats/producer/ProducerFlexbox.tsx
1042
1290
  import { ListItem, styled, Typography as Typography4 } from "@mui/material";
1043
1291
  import { ErrorRender as ErrorRender3 } from "@xylabs/react-error";
1044
1292
  import { FlexCol as FlexCol3 } from "@xylabs/react-flexbox";
1045
1293
  import { isChainSummaryProducers } from "@xyo-network/chain-protocol";
1046
- import React26, { useMemo as useMemo10 } from "react";
1294
+ import React26, { useMemo as useMemo11 } from "react";
1047
1295
 
1048
1296
  // src/components/chain/stats/producer/Table.tsx
1049
1297
  import { Table, TableBody as TableBody2, TableCell as TableCell9, TableHead as TableHead2, TableRow as TableRow3, useTheme } from "@mui/material";
@@ -1066,7 +1314,7 @@ var ChainProducerStatsTable = /* @__PURE__ */ __name(({ producers, ...props }) =
1066
1314
 
1067
1315
  // src/components/chain/stats/producer/ProducerFlexbox.tsx
1068
1316
  var BlockProducerStatsFlexbox = /* @__PURE__ */ __name(({ payload, ...props }) => {
1069
- const [producer, producerError] = useMemo10(() => {
1317
+ const [producer, producerError] = useMemo11(() => {
1070
1318
  if (payload) {
1071
1319
  return isChainSummaryProducers(payload) ? [
1072
1320
  payload
@@ -1080,7 +1328,7 @@ var BlockProducerStatsFlexbox = /* @__PURE__ */ __name(({ payload, ...props }) =
1080
1328
  }, [
1081
1329
  payload
1082
1330
  ]);
1083
- const producersArray = useMemo10(() => Object.values(producer?.producers ?? {}), [
1331
+ const producersArray = useMemo11(() => Object.values(producer?.producers ?? {}), [
1084
1332
  producer
1085
1333
  ]);
1086
1334
  return /* @__PURE__ */ React26.createElement(FlexCol3, {
@@ -1111,7 +1359,7 @@ var ChainAnalyzerStatsDialog = /* @__PURE__ */ __name((props) => {
1111
1359
  })))));
1112
1360
  }, "ChainAnalyzerStatsDialog");
1113
1361
  var ChainAnalyzerStatsDialogFromContext = /* @__PURE__ */ __name((props) => {
1114
- const [open, setOpen] = useState10(false);
1362
+ const [open, setOpen] = useState11(false);
1115
1363
  const handleClose = /* @__PURE__ */ __name(() => setOpen(false), "handleClose");
1116
1364
  return /* @__PURE__ */ React27.createElement(React27.Fragment, null, /* @__PURE__ */ React27.createElement(IconButton3, {
1117
1365
  onClick: /* @__PURE__ */ __name(() => setOpen(true), "onClick")
@@ -1246,11 +1494,11 @@ var TransactionsDialog = /* @__PURE__ */ __name((props) => {
1246
1494
  }, "TransactionsDialog");
1247
1495
 
1248
1496
  // src/components/chain/hooks/useOnBlock.ts
1249
- import { useEffect, useRef as useRef2 } from "react";
1497
+ import { useEffect as useEffect3, useRef as useRef3 } from "react";
1250
1498
  var useOnBlock = /* @__PURE__ */ __name((initialHeadNumber, onAddBlock, liveHead, pollingState) => {
1251
- const blocksWhilePaused = useRef2([]);
1252
- const lastLiveHead = useRef2(liveHead);
1253
- useEffect(() => {
1499
+ const blocksWhilePaused = useRef3([]);
1500
+ const lastLiveHead = useRef3(liveHead);
1501
+ useEffect3(() => {
1254
1502
  const lastLiveHeadBlock = lastLiveHead.current?.[0];
1255
1503
  const blocksWhilePausedBlock = lastLiveHead.current?.[0];
1256
1504
  const liveHeadBlock = liveHead?.[0];
@@ -1290,10 +1538,10 @@ var BlockChainPagination = /* @__PURE__ */ __name(({ count = 0, onPageChange, pa
1290
1538
  }, "BlockChainPagination");
1291
1539
 
1292
1540
  // src/components/chain/pagination/hooks/usePagination.tsx
1293
- import { useMemo as useMemo11, useState as useState11 } from "react";
1541
+ import { useMemo as useMemo12, useState as useState12 } from "react";
1294
1542
  var useChainPagination = /* @__PURE__ */ __name((pageSize, blockComponents) => {
1295
- const [page, setPage] = useState11(0);
1296
- const paginatedBlockComponents = useMemo11(() => {
1543
+ const [page, setPage] = useState12(0);
1544
+ const paginatedBlockComponents = useMemo12(() => {
1297
1545
  const startIndex = page * pageSize;
1298
1546
  const endIndex = startIndex + pageSize;
1299
1547
  return blockComponents?.slice(startIndex, endIndex);
@@ -1351,257 +1599,6 @@ var BlockListAnimated = /* @__PURE__ */ __name(({ blockChainRenderComponents })
1351
1599
 
1352
1600
  // src/components/chain/render/dynamic/hooks/useDynamicBlockRenderComponents.ts
1353
1601
  import { useMemo as useMemo13 } from "react";
1354
-
1355
- // src/hooks/chain-iterator/ChainIteratorStore.ts
1356
- import { assertEx } from "@xylabs/assert";
1357
- import { hydrateBlock } from "@xyo-network/chain-protocol";
1358
- import { XyoChainBlockNumberIterator } from "@xyo-network/chain-services";
1359
- import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
1360
- var ChainIteratorStore = class _ChainIteratorStore {
1361
- static {
1362
- __name(this, "ChainIteratorStore");
1363
- }
1364
- _chainIterator;
1365
- _externalListeners = [];
1366
- _internalUnsubscribes = [];
1367
- _values;
1368
- get chainIterator() {
1369
- return assertEx(this._chainIterator, () => "ChainIteratorStore has not been initialized");
1370
- }
1371
- get values() {
1372
- return assertEx(this._values, () => "ChainIteratorStore values have not been initialized");
1373
- }
1374
- static async create(params) {
1375
- const instance = new _ChainIteratorStore();
1376
- const chainIterator = await XyoChainBlockNumberIterator.create(params);
1377
- instance._chainIterator = chainIterator;
1378
- const head = await chainIterator.head();
1379
- const hydratedHead = await hydrateBlock(params.chainArchivist, await PayloadBuilder3.hash(head));
1380
- instance._values = {
1381
- chainIterator,
1382
- head: hydratedHead
1383
- };
1384
- const headUpdatedListener = /* @__PURE__ */ __name(async ({ blocks }) => {
1385
- const hydratedBlock = await hydrateBlock(params.chainArchivist, await PayloadBuilder3.hash(blocks?.[0]));
1386
- instance._values = {
1387
- chainIterator,
1388
- head: hydratedBlock
1389
- };
1390
- instance.emitChange();
1391
- }, "headUpdatedListener");
1392
- const unsubscribe = chainIterator.on("headUpdated", headUpdatedListener);
1393
- const weakRefListener = new WeakRef(unsubscribe);
1394
- instance._internalUnsubscribes.push(weakRefListener);
1395
- return instance;
1396
- }
1397
- cleanup() {
1398
- for (const unsubscribeRef of this._internalUnsubscribes) {
1399
- const unsubscribe = unsubscribeRef.deref();
1400
- unsubscribe?.();
1401
- }
1402
- }
1403
- getSnapshot() {
1404
- return this.values;
1405
- }
1406
- subscribe(onStoreChange) {
1407
- this._externalListeners.push(onStoreChange);
1408
- return () => {
1409
- this._externalListeners = this._externalListeners.filter((l) => l !== onStoreChange);
1410
- };
1411
- }
1412
- emitChange() {
1413
- for (const listener of this._externalListeners) {
1414
- listener();
1415
- }
1416
- }
1417
- };
1418
-
1419
- // src/hooks/chain-iterator/useChainIteratorParams.ts
1420
- import { assertEx as assertEx2 } from "@xylabs/assert";
1421
- import { usePromise as usePromise3 } from "@xylabs/react-promise";
1422
- import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
1423
- import { isBlockBoundWitness } from "@xyo-network/xl1-model";
1424
- var resolveDefinedHead = /* @__PURE__ */ __name(async (head, chainArchivist) => {
1425
- const [headPayload] = await chainArchivist.get([
1426
- head
1427
- ]);
1428
- if (headPayload === void 0) {
1429
- const [currentHead] = await new BoundWitnessBuilder().build();
1430
- return currentHead;
1431
- } else {
1432
- return assertEx2(isBlockBoundWitness(headPayload) ? headPayload : void 0, () => `Expected a block bound witness: ${JSON.stringify(headPayload)}`);
1433
- }
1434
- }, "resolveDefinedHead");
1435
- var useChainIteratorParams = /* @__PURE__ */ __name(({ chainArchivist, chainInformation, head }) => {
1436
- return usePromise3(async () => {
1437
- if (chainArchivist && chainInformation && head) {
1438
- const [result] = await chainArchivist.get([
1439
- head
1440
- ]);
1441
- const foundResult = assertEx2(result, () => `Head not found: ${head}`);
1442
- const resolvedHead = assertEx2(isBlockBoundWitness(foundResult) ? foundResult : void 0, () => `Head is not a boundwitness: ${JSON.stringify(foundResult)}`);
1443
- return {
1444
- chainArchivist,
1445
- chainInformation,
1446
- head: resolvedHead
1447
- };
1448
- }
1449
- }, [
1450
- chainArchivist,
1451
- chainInformation,
1452
- head
1453
- ]);
1454
- }, "useChainIteratorParams");
1455
-
1456
- // src/hooks/chain-iterator/useChainIteratorStore.ts
1457
- import { usePromise as usePromise4 } from "@xylabs/react-promise";
1458
- import { useEffect as useEffect3, useMemo as useMemo12, useRef as useRef3, useSyncExternalStore } from "react";
1459
-
1460
- // src/hooks/chain-iterator/useChainIteratorUpdatingHead.ts
1461
- import { toHex as toHex2 } from "@xylabs/hex";
1462
- import { findMostRecentBlock } from "@xyo-network/chain-protocol";
1463
- import { useEffect as useEffect2, useState as useState12 } from "react";
1464
- var useChainIteratorUpdatingHead = /* @__PURE__ */ __name(({ chainIterator, interval = 500, maxBlocks, chainArchivist }) => {
1465
- const [error, setError] = useState12();
1466
- useEffect2(() => {
1467
- let pollArchivistTimeout;
1468
- const pollingFunction = /* @__PURE__ */ __name(async () => {
1469
- if (chainIterator && chainArchivist) {
1470
- try {
1471
- const currentHead = await chainIterator.head();
1472
- const mostRecentBlock = await findMostRecentBlock(chainArchivist);
1473
- if (currentHead && mostRecentBlock) {
1474
- const currentBlockNumber = currentHead?.block ?? -1;
1475
- const nextBlockNumber = mostRecentBlock.block;
1476
- if (nextBlockNumber > currentBlockNumber) {
1477
- console.debug("Found more recent head:", toHex2(nextBlockNumber));
1478
- console.debug("Updating head:", `${toHex2(nextBlockNumber)}`);
1479
- await chainIterator.updateHead(mostRecentBlock);
1480
- console.debug("Updated head:", `${toHex2(nextBlockNumber)}`);
1481
- }
1482
- }
1483
- } catch (e) {
1484
- setError(e);
1485
- console.error(e);
1486
- }
1487
- }
1488
- pollArchivistTimeout = setTimeout(() => void pollingFunction(), interval);
1489
- }, "pollingFunction");
1490
- void pollingFunction();
1491
- return () => clearInterval(pollArchivistTimeout);
1492
- }, [
1493
- interval,
1494
- chainIterator,
1495
- chainArchivist,
1496
- maxBlocks
1497
- ]);
1498
- return error;
1499
- }, "useChainIteratorUpdatingHead");
1500
-
1501
- // src/hooks/chain-iterator/useChainIteratorStore.ts
1502
- var stub = {};
1503
- var useChainIteratorStore = /* @__PURE__ */ __name((chainIteratorParams) => {
1504
- const [chainIteratorStore] = usePromise4(async () => {
1505
- return chainIteratorParams ? await ChainIteratorStore.create(chainIteratorParams) : void 0;
1506
- }, [
1507
- chainIteratorParams
1508
- ]);
1509
- const { chainIterator } = chainIteratorStore || {};
1510
- const chainArchivist = chainIteratorParams?.chainArchivist;
1511
- const error = useChainIteratorUpdatingHead({
1512
- chainIterator,
1513
- chainArchivist
1514
- });
1515
- useEffect3(() => {
1516
- return () => {
1517
- if (chainIteratorStore) {
1518
- chainIteratorStore.cleanup();
1519
- }
1520
- };
1521
- }, [
1522
- chainIteratorStore
1523
- ]);
1524
- const cachedSnapshot = useRef3({});
1525
- const { getSnapShot, subscribe } = useMemo12(() => {
1526
- if (chainIteratorStore) {
1527
- return {
1528
- getSnapShot: /* @__PURE__ */ __name(() => {
1529
- const snapshot = chainIteratorStore.getSnapshot();
1530
- const newValues = {
1531
- ...snapshot,
1532
- error
1533
- };
1534
- const noCachedValue = cachedSnapshot.current.chainIterator === void 0;
1535
- const cachedBlock = cachedSnapshot.current?.head?.[0]?.block;
1536
- const newBlock = cachedBlock !== newValues.head?.[0]?.block;
1537
- if (noCachedValue || newBlock) {
1538
- cachedSnapshot.current = newValues;
1539
- return newValues;
1540
- }
1541
- return cachedSnapshot.current;
1542
- }, "getSnapShot"),
1543
- subscribe: chainIteratorStore.subscribe.bind(chainIteratorStore)
1544
- };
1545
- }
1546
- return {
1547
- getSnapShot: /* @__PURE__ */ __name(() => stub, "getSnapShot"),
1548
- subscribe: /* @__PURE__ */ __name(() => () => {
1549
- }, "subscribe")
1550
- };
1551
- }, [
1552
- chainIteratorStore
1553
- ]);
1554
- return useSyncExternalStore(subscribe, getSnapShot);
1555
- }, "useChainIteratorStore");
1556
-
1557
- // src/hooks/useIterateChain.ts
1558
- import { assertEx as assertEx3 } from "@xylabs/assert";
1559
- import { usePromise as usePromise5 } from "@xylabs/react-promise";
1560
- import { hydrateBlock as hydrateBlock2 } from "@xyo-network/chain-protocol";
1561
- import { XyoChainBlockNumberIterator as XyoChainBlockNumberIterator2 } from "@xyo-network/chain-services";
1562
- import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
1563
- import { isBlockBoundWitness as isBlockBoundWitness2 } from "@xyo-network/xl1-model";
1564
- var getHydratedBlock = /* @__PURE__ */ __name(async (chainArchivist, head) => {
1565
- const headHash = await PayloadBuilder4.hash(head);
1566
- return await hydrateBlock2(chainArchivist, headHash);
1567
- }, "getHydratedBlock");
1568
- var iterateChain = /* @__PURE__ */ __name(async (chainIteratorParams, maxDepth) => {
1569
- const { chainArchivist, head } = chainIteratorParams ?? {};
1570
- if (chainArchivist && head) {
1571
- const headPayload = assertEx3(isBlockBoundWitness2(head) ? head : null, () => "Head is not a Block Bound Witness");
1572
- const headBlockBoundWitness = assertEx3(isBlockBoundWitness2(headPayload) ? headPayload : null, () => "Invalid head block");
1573
- const chainIterator = await XyoChainBlockNumberIterator2.create({
1574
- head: headBlockBoundWitness,
1575
- chainArchivist
1576
- });
1577
- const chainHead = await chainIterator.head();
1578
- let block = await getHydratedBlock(chainArchivist, chainHead);
1579
- const blocks = [
1580
- block
1581
- ];
1582
- let depth = 1;
1583
- while (block) {
1584
- const [, next] = await chainIterator.previous(block[0].block, 2);
1585
- if (!next) break;
1586
- const nextHydratedBlock = await getHydratedBlock(chainArchivist, next);
1587
- blocks.push(nextHydratedBlock);
1588
- block = nextHydratedBlock;
1589
- depth++;
1590
- if (maxDepth && depth >= maxDepth || block?.[0].block === 0) break;
1591
- }
1592
- return blocks;
1593
- }
1594
- }, "iterateChain");
1595
- var useIterateChain = /* @__PURE__ */ __name((chainIteratorParams, maxDepth) => {
1596
- return usePromise5(async () => {
1597
- return await iterateChain(chainIteratorParams, maxDepth);
1598
- }, [
1599
- chainIteratorParams,
1600
- maxDepth
1601
- ]);
1602
- }, "useIterateChain");
1603
-
1604
- // src/components/chain/render/dynamic/hooks/useDynamicBlockRenderComponents.ts
1605
1602
  var useDynamicBlockRenderComponents = /* @__PURE__ */ __name((BlockComponent, blockChainRenderProps) => {
1606
1603
  const { maxBlocks } = blockChainRenderProps ?? {};
1607
1604
  const chainIteratorParams = useMemo13(() => blockChainRenderProps ?? {}, [
@@ -2334,12 +2331,10 @@ export {
2334
2331
  XyoAddressTextField,
2335
2332
  blockProducer,
2336
2333
  buildBlockChainRenderComponent,
2337
- buildBlockHeadingComponent,
2338
2334
  buildRandomBlockChain,
2339
2335
  buildRandomBlockChainBlocksOnly,
2340
2336
  payloadCountsFromBlock,
2341
2337
  resolveDefinedHead,
2342
- txsFromBlock,
2343
2338
  useAnchorElement,
2344
2339
  useBlockHeadingEvents,
2345
2340
  useBlockProducer,