envio 3.0.0-alpha.0 → 3.0.0-alpha.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/README.md +2 -2
- package/evm.schema.json +53 -57
- package/fuel.schema.json +35 -31
- package/index.d.ts +446 -1
- package/index.js +4 -0
- package/package.json +23 -11
- package/rescript.json +4 -1
- package/src/Batch.res.mjs +1 -1
- package/src/Benchmark.res +394 -0
- package/src/Benchmark.res.mjs +398 -0
- package/src/ChainFetcher.res +526 -0
- package/src/ChainFetcher.res.mjs +343 -0
- package/src/ChainManager.res +182 -0
- package/src/ChainManager.res.mjs +150 -0
- package/src/Config.res +367 -27
- package/src/Config.res.mjs +338 -28
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +25 -0
- package/src/Ecosystem.res.mjs +29 -0
- package/src/Env.res +252 -0
- package/src/Env.res.mjs +271 -0
- package/src/Envio.gen.ts +9 -1
- package/src/Envio.res +12 -9
- package/src/EventProcessing.res +476 -0
- package/src/EventProcessing.res.mjs +341 -0
- package/src/EventRegister.res +4 -15
- package/src/EventRegister.res.mjs +3 -9
- package/src/EventRegister.resi +2 -8
- package/src/FetchState.res +54 -29
- package/src/FetchState.res.mjs +62 -35
- package/src/GlobalState.res +1163 -0
- package/src/GlobalState.res.mjs +1196 -0
- package/src/GlobalStateManager.res +68 -0
- package/src/GlobalStateManager.res.mjs +75 -0
- package/src/GlobalStateManager.resi +7 -0
- package/src/HandlerLoader.res +89 -0
- package/src/HandlerLoader.res.mjs +79 -0
- package/src/Internal.gen.ts +3 -14
- package/src/Internal.res +45 -13
- package/src/LoadLayer.res +444 -0
- package/src/LoadLayer.res.mjs +296 -0
- package/src/LoadLayer.resi +32 -0
- package/src/LogSelection.res +33 -27
- package/src/LogSelection.res.mjs +6 -0
- package/src/Logging.res +11 -4
- package/src/Logging.res.mjs +14 -6
- package/src/Main.res +351 -0
- package/src/Main.res.mjs +312 -0
- package/src/Persistence.res +1 -2
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +28 -34
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +27 -27
- package/src/Prometheus.res +8 -8
- package/src/Prometheus.res.mjs +10 -10
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/TestIndexer.res +536 -0
- package/src/TestIndexer.res.mjs +412 -0
- package/src/TestIndexerProxyStorage.res +210 -0
- package/src/TestIndexerProxyStorage.res.mjs +157 -0
- package/src/Types.ts +1 -1
- package/src/UserContext.res +355 -0
- package/src/UserContext.res.mjs +236 -0
- package/src/Utils.res +28 -0
- package/src/Utils.res.mjs +18 -0
- package/src/bindings/ClickHouse.res +31 -1
- package/src/bindings/ClickHouse.res.mjs +27 -1
- package/src/bindings/DateFns.res +71 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/Ethers.res +27 -67
- package/src/bindings/Ethers.res.mjs +18 -70
- package/src/bindings/EventSource.res +13 -0
- package/src/bindings/EventSource.res.mjs +2 -0
- package/src/bindings/NodeJs.res +44 -3
- package/src/bindings/NodeJs.res.mjs +11 -3
- package/src/bindings/Pino.res +21 -7
- package/src/bindings/Pino.res.mjs +11 -5
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +3 -0
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/RescriptMocha.res +123 -0
- package/src/bindings/RescriptMocha.res.mjs +18 -0
- package/src/bindings/Vitest.res +134 -0
- package/src/bindings/Vitest.res.mjs +9 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/db/InternalTable.res +2 -0
- package/src/db/InternalTable.res.mjs +1 -1
- package/src/sources/Evm.res +87 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +90 -0
- package/src/sources/EvmChain.res.mjs +57 -0
- package/src/sources/Fuel.res +19 -34
- package/src/sources/Fuel.res.mjs +34 -16
- package/src/sources/FuelSDK.res +38 -0
- package/src/sources/FuelSDK.res.mjs +29 -0
- package/src/sources/HyperFuel.res +2 -2
- package/src/sources/HyperFuel.resi +1 -1
- package/src/sources/HyperFuelClient.res +2 -2
- package/src/sources/HyperFuelSource.res +8 -8
- package/src/sources/HyperFuelSource.res.mjs +5 -5
- package/src/sources/HyperSyncHeightStream.res +97 -0
- package/src/sources/HyperSyncHeightStream.res.mjs +94 -0
- package/src/sources/HyperSyncSource.res +64 -172
- package/src/sources/HyperSyncSource.res.mjs +73 -155
- package/src/sources/Rpc.res +43 -0
- package/src/sources/Rpc.res.mjs +31 -0
- package/src/sources/RpcSource.res +32 -130
- package/src/sources/RpcSource.res.mjs +47 -121
- package/src/sources/Source.res +3 -2
- package/src/sources/SourceManager.res +183 -108
- package/src/sources/SourceManager.res.mjs +162 -99
- package/src/sources/SourceManager.resi +4 -5
- package/src/sources/Svm.res +59 -0
- package/src/sources/Svm.res.mjs +79 -0
- package/src/tui/Tui.res +266 -0
- package/src/tui/Tui.res.mjs +342 -0
- package/src/tui/bindings/Ink.res +376 -0
- package/src/tui/bindings/Ink.res.mjs +75 -0
- package/src/tui/bindings/Style.res +123 -0
- package/src/tui/bindings/Style.res.mjs +2 -0
- package/src/tui/components/BufferedProgressBar.res +40 -0
- package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
- package/src/tui/components/CustomHooks.res +122 -0
- package/src/tui/components/CustomHooks.res.mjs +179 -0
- package/src/tui/components/Messages.res +41 -0
- package/src/tui/components/Messages.res.mjs +75 -0
- package/src/tui/components/SyncETA.res +193 -0
- package/src/tui/components/SyncETA.res.mjs +269 -0
- package/src/tui/components/TuiData.res +46 -0
- package/src/tui/components/TuiData.res.mjs +29 -0
- package/src/Platform.res +0 -140
- package/src/Platform.res.mjs +0 -170
- package/src/bindings/Ethers.gen.ts +0 -14
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
|
@@ -4,7 +4,6 @@ import * as Rpc from "./Rpc.res.mjs";
|
|
|
4
4
|
import * as Caml from "rescript/lib/es6/caml.js";
|
|
5
5
|
import * as Rest from "../vendored/Rest.res.mjs";
|
|
6
6
|
import * as Time from "../Time.res.mjs";
|
|
7
|
-
import * as Viem from "../bindings/Viem.res.mjs";
|
|
8
7
|
import * as Utils from "../Utils.res.mjs";
|
|
9
8
|
import * as Ethers from "../bindings/Ethers.res.mjs";
|
|
10
9
|
import * as Hrtime from "../bindings/Hrtime.res.mjs";
|
|
@@ -506,7 +505,6 @@ function sanitizeUrl(url) {
|
|
|
506
505
|
|
|
507
506
|
function make(param) {
|
|
508
507
|
var lowercaseAddresses = param.lowercaseAddresses;
|
|
509
|
-
var shouldUseHypersyncClientDecoder = param.shouldUseHypersyncClientDecoder;
|
|
510
508
|
var allEventSignatures = param.allEventSignatures;
|
|
511
509
|
var eventRouter = param.eventRouter;
|
|
512
510
|
var chain = param.chain;
|
|
@@ -518,9 +516,10 @@ function make(param) {
|
|
|
518
516
|
var provider = Ethers.JsonRpcProvider.make(url, chain);
|
|
519
517
|
var getSelectionConfig = memoGetSelectionConfig(chain);
|
|
520
518
|
var mutSuggestedBlockIntervals = {};
|
|
519
|
+
var client = Rest.client(url, undefined);
|
|
521
520
|
var makeTransactionLoader = function () {
|
|
522
521
|
return LazyLoader.make((function (transactionHash) {
|
|
523
|
-
return
|
|
522
|
+
return Rest.$$fetch(Rpc.GetTransactionByHash.route, transactionHash, client);
|
|
524
523
|
}), (function (am, exn) {
|
|
525
524
|
Logging.error({
|
|
526
525
|
err: Utils.prettifyExn(exn),
|
|
@@ -559,13 +558,14 @@ function make(param) {
|
|
|
559
558
|
var getEventBlockOrThrow = makeThrowingGetEventBlock(function (blockNumber) {
|
|
560
559
|
return LazyLoader.get(blockLoader.contents, blockNumber);
|
|
561
560
|
});
|
|
562
|
-
var getEventTransactionOrThrow = makeThrowingGetEventTransaction(Ethers.JsonRpcProvider.makeGetTransactionFields((function (
|
|
563
|
-
|
|
561
|
+
var getEventTransactionOrThrow = makeThrowingGetEventTransaction(Ethers.JsonRpcProvider.makeGetTransactionFields((async function (transactionHash) {
|
|
562
|
+
var tx = await LazyLoader.get(transactionLoader.contents, transactionHash);
|
|
563
|
+
if (tx !== undefined) {
|
|
564
|
+
return tx;
|
|
565
|
+
} else {
|
|
566
|
+
return Js_exn.raiseError("Transaction not found for hash: " + transactionHash);
|
|
567
|
+
}
|
|
564
568
|
}), lowercaseAddresses));
|
|
565
|
-
var contractNameAbiMapping = {};
|
|
566
|
-
Belt_Array.forEach(param.contracts, (function (contract) {
|
|
567
|
-
contractNameAbiMapping[contract.name] = contract.abi;
|
|
568
|
-
}));
|
|
569
569
|
var convertEthersLogToHyperSyncEvent = function (log) {
|
|
570
570
|
var hyperSyncLog_removed = Belt_Option.getWithDefault(log.removed, false);
|
|
571
571
|
var hyperSyncLog_logIndex = log.index;
|
|
@@ -604,11 +604,11 @@ function make(param) {
|
|
|
604
604
|
return HyperSyncClient.Decoder.fromSignatures(allEventSignatures);
|
|
605
605
|
}
|
|
606
606
|
};
|
|
607
|
-
var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts,
|
|
607
|
+
var getItemsOrThrow = async function (fromBlock, toBlock, addressesByContractName, indexingContracts, knownHeight, partitionId, selection, param, param$1) {
|
|
608
608
|
var startFetchingBatchTimeRef = Hrtime.makeTimer();
|
|
609
609
|
var maxSuggestedBlockInterval = mutSuggestedBlockIntervals[maxSuggestedBlockIntervalKey];
|
|
610
610
|
var suggestedBlockInterval = maxSuggestedBlockInterval !== undefined ? maxSuggestedBlockInterval : Belt_Option.getWithDefault(mutSuggestedBlockIntervals[partitionId], syncConfig.initialBlockInterval);
|
|
611
|
-
var toBlock$1 = toBlock !== undefined && toBlock <
|
|
611
|
+
var toBlock$1 = toBlock !== undefined && toBlock < knownHeight ? toBlock : knownHeight;
|
|
612
612
|
var suggestedToBlock = Caml.int_max(Caml.int_min((fromBlock + suggestedBlockInterval | 0) - 1 | 0, toBlock$1), fromBlock);
|
|
613
613
|
var firstBlockParentPromise = fromBlock > 0 ? LazyLoader.get(blockLoader.contents, fromBlock - 1 | 0).then(function (res) {
|
|
614
614
|
return res;
|
|
@@ -624,88 +624,34 @@ function make(param) {
|
|
|
624
624
|
if (executedBlockInterval >= suggestedBlockInterval && !Utils.Dict.has(mutSuggestedBlockIntervals, maxSuggestedBlockIntervalKey)) {
|
|
625
625
|
mutSuggestedBlockIntervals[partitionId] = Caml.int_min(executedBlockInterval + syncConfig.accelerationAdditive | 0, syncConfig.intervalCeiling);
|
|
626
626
|
}
|
|
627
|
-
var
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
var eventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), routedAddress, log.blockNumber, indexingContracts);
|
|
656
|
-
if (eventConfig !== undefined && !(maybeDecodedEvent === null || maybeDecodedEvent === undefined)) {
|
|
657
|
-
return Caml_option.some((async function () {
|
|
658
|
-
var match;
|
|
659
|
-
try {
|
|
660
|
-
match = await Promise.all([
|
|
661
|
-
getEventBlockOrThrow(log),
|
|
662
|
-
getEventTransactionOrThrow(log, eventConfig.transactionSchema)
|
|
663
|
-
]);
|
|
664
|
-
}
|
|
665
|
-
catch (raw_exn){
|
|
666
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
667
|
-
throw {
|
|
668
|
-
RE_EXN_ID: Source.GetItemsError,
|
|
669
|
-
_1: {
|
|
670
|
-
TAG: "FailedGettingFieldSelection",
|
|
671
|
-
exn: exn,
|
|
672
|
-
blockNumber: log.blockNumber,
|
|
673
|
-
logIndex: log.index,
|
|
674
|
-
message: "Failed getting selected fields. Please double-check your RPC provider returns correct data."
|
|
675
|
-
},
|
|
676
|
-
Error: new Error()
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
var block = match[0];
|
|
680
|
-
return {
|
|
681
|
-
kind: 0,
|
|
682
|
-
eventConfig: eventConfig,
|
|
683
|
-
timestamp: block.timestamp,
|
|
684
|
-
chain: chain,
|
|
685
|
-
blockNumber: block.number,
|
|
686
|
-
logIndex: log.index,
|
|
687
|
-
event: {
|
|
688
|
-
params: eventConfig.convertHyperSyncEventArgs(maybeDecodedEvent),
|
|
689
|
-
chainId: chain,
|
|
690
|
-
srcAddress: routedAddress,
|
|
691
|
-
logIndex: log.index,
|
|
692
|
-
transaction: match[1],
|
|
693
|
-
block: block
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
})());
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
})));
|
|
700
|
-
} else {
|
|
701
|
-
parsedQueueItems = await Promise.all(Belt_Array.keepMap(logs, (function (log) {
|
|
702
|
-
var topic0 = log.topics[0];
|
|
703
|
-
var eventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), log.address, log.blockNumber, indexingContracts);
|
|
704
|
-
if (eventConfig === undefined) {
|
|
705
|
-
return ;
|
|
706
|
-
}
|
|
707
|
-
var blockNumber = log.blockNumber;
|
|
708
|
-
var logIndex = log.index;
|
|
627
|
+
var hyperSyncEvents = Belt_Array.map(logs, convertEthersLogToHyperSyncEvent);
|
|
628
|
+
var parsedEvents;
|
|
629
|
+
try {
|
|
630
|
+
parsedEvents = await getHscDecoder().decodeEvents(hyperSyncEvents);
|
|
631
|
+
}
|
|
632
|
+
catch (raw_exn){
|
|
633
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
634
|
+
throw {
|
|
635
|
+
RE_EXN_ID: Source.GetItemsError,
|
|
636
|
+
_1: {
|
|
637
|
+
TAG: "FailedGettingItems",
|
|
638
|
+
exn: exn,
|
|
639
|
+
attemptedToBlock: toBlock$1,
|
|
640
|
+
retry: {
|
|
641
|
+
TAG: "ImpossibleForTheQuery",
|
|
642
|
+
message: "Failed to parse events using hypersync client decoder. Please double-check your ABI."
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
Error: new Error()
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
var parsedQueueItems = await Promise.all(Belt_Array.keepMap(Belt_Array.zip(logs, parsedEvents), (function (param) {
|
|
649
|
+
var maybeDecodedEvent = param[1];
|
|
650
|
+
var log = param[0];
|
|
651
|
+
var topic0 = Belt_Option.getWithDefault(Belt_Array.get(log.topics, 0), "0x0");
|
|
652
|
+
var routedAddress = lowercaseAddresses ? Address.Evm.fromAddressLowercaseOrThrow(log.address) : log.address;
|
|
653
|
+
var eventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), routedAddress, log.blockNumber, indexingContracts);
|
|
654
|
+
if (eventConfig !== undefined && !(maybeDecodedEvent === null || maybeDecodedEvent === undefined)) {
|
|
709
655
|
return Caml_option.some((async function () {
|
|
710
656
|
var match;
|
|
711
657
|
try {
|
|
@@ -721,34 +667,14 @@ function make(param) {
|
|
|
721
667
|
_1: {
|
|
722
668
|
TAG: "FailedGettingFieldSelection",
|
|
723
669
|
exn: exn,
|
|
724
|
-
blockNumber: blockNumber,
|
|
725
|
-
logIndex:
|
|
670
|
+
blockNumber: log.blockNumber,
|
|
671
|
+
logIndex: log.index,
|
|
726
672
|
message: "Failed getting selected fields. Please double-check your RPC provider returns correct data."
|
|
727
673
|
},
|
|
728
674
|
Error: new Error()
|
|
729
675
|
};
|
|
730
676
|
}
|
|
731
677
|
var block = match[0];
|
|
732
|
-
var decodedEvent;
|
|
733
|
-
try {
|
|
734
|
-
decodedEvent = Viem.parseLogOrThrow(contractNameAbiMapping, eventConfig.contractName, log.topics, log.data);
|
|
735
|
-
}
|
|
736
|
-
catch (raw_exn$1){
|
|
737
|
-
var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
|
|
738
|
-
throw {
|
|
739
|
-
RE_EXN_ID: Source.GetItemsError,
|
|
740
|
-
_1: {
|
|
741
|
-
TAG: "FailedGettingItems",
|
|
742
|
-
exn: exn$1,
|
|
743
|
-
attemptedToBlock: toBlock$1,
|
|
744
|
-
retry: {
|
|
745
|
-
TAG: "ImpossibleForTheQuery",
|
|
746
|
-
message: "Failed to parse event with viem, please double-check your ABI. Block number: " + String(blockNumber) + ", log index: " + String(logIndex)
|
|
747
|
-
}
|
|
748
|
-
},
|
|
749
|
-
Error: new Error()
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
678
|
return {
|
|
753
679
|
kind: 0,
|
|
754
680
|
eventConfig: eventConfig,
|
|
@@ -757,17 +683,18 @@ function make(param) {
|
|
|
757
683
|
blockNumber: block.number,
|
|
758
684
|
logIndex: log.index,
|
|
759
685
|
event: {
|
|
760
|
-
params:
|
|
686
|
+
params: eventConfig.convertHyperSyncEventArgs(maybeDecodedEvent),
|
|
761
687
|
chainId: chain,
|
|
762
|
-
srcAddress:
|
|
688
|
+
srcAddress: routedAddress,
|
|
763
689
|
logIndex: log.index,
|
|
764
690
|
transaction: match[1],
|
|
765
691
|
block: block
|
|
766
692
|
}
|
|
767
693
|
};
|
|
768
694
|
})());
|
|
769
|
-
}
|
|
770
|
-
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
})));
|
|
771
698
|
var optFirstBlockParent = await firstBlockParentPromise;
|
|
772
699
|
var totalTimeElapsed = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(startFetchingBatchTimeRef)));
|
|
773
700
|
var reorgGuard_rangeLastBlock = {
|
|
@@ -785,7 +712,7 @@ function make(param) {
|
|
|
785
712
|
prevRangeLastBlock: reorgGuard_prevRangeLastBlock
|
|
786
713
|
};
|
|
787
714
|
return {
|
|
788
|
-
|
|
715
|
+
knownHeight: knownHeight,
|
|
789
716
|
reorgGuard: reorgGuard,
|
|
790
717
|
parsedQueueItems: parsedQueueItems,
|
|
791
718
|
fromBlockQueried: fromBlock,
|
|
@@ -819,7 +746,6 @@ function make(param) {
|
|
|
819
746
|
});
|
|
820
747
|
}));
|
|
821
748
|
};
|
|
822
|
-
var client = Rest.client(url, undefined);
|
|
823
749
|
return {
|
|
824
750
|
name: name,
|
|
825
751
|
sourceFor: param.sourceFor,
|
package/src/sources/Source.res
CHANGED
|
@@ -11,7 +11,7 @@ type blockRangeFetchStats = {
|
|
|
11
11
|
Thes response returned from a block range fetch
|
|
12
12
|
*/
|
|
13
13
|
type blockRangeFetchResponse = {
|
|
14
|
-
|
|
14
|
+
knownHeight: int,
|
|
15
15
|
reorgGuard: ReorgDetection.reorgGuard,
|
|
16
16
|
parsedQueueItems: array<Internal.item>,
|
|
17
17
|
fromBlockQueried: int,
|
|
@@ -50,10 +50,11 @@ type t = {
|
|
|
50
50
|
~toBlock: option<int>,
|
|
51
51
|
~addressesByContractName: dict<array<Address.t>>,
|
|
52
52
|
~indexingContracts: dict<Internal.indexingContract>,
|
|
53
|
-
~
|
|
53
|
+
~knownHeight: int,
|
|
54
54
|
~partitionId: string,
|
|
55
55
|
~selection: FetchState.selection,
|
|
56
56
|
~retry: int,
|
|
57
57
|
~logger: Pino.t,
|
|
58
58
|
) => promise<blockRangeFetchResponse>,
|
|
59
|
+
createHeightSubscription?: (~onHeight: int => unit) => unit => unit,
|
|
59
60
|
}
|