envio 3.3.0-alpha.1 → 3.3.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/evm.schema.json +10 -0
- package/index.d.ts +45 -25
- package/package.json +7 -7
- package/src/Address.res +5 -2
- package/src/Address.res.mjs +3 -1
- package/src/Api.res +1 -1
- package/src/Api.res.mjs +1 -1
- package/src/Batch.res +0 -6
- package/src/Batch.res.mjs +1 -12
- package/src/BatchProcessing.res +7 -12
- package/src/BatchProcessing.res.mjs +8 -7
- package/src/Bin.res +3 -0
- package/src/Bin.res.mjs +4 -0
- package/src/ChainFetching.res +43 -9
- package/src/ChainFetching.res.mjs +34 -15
- package/src/ChainMetadata.res +1 -11
- package/src/ChainMetadata.res.mjs +1 -10
- package/src/ChainState.res +605 -151
- package/src/ChainState.res.mjs +427 -104
- package/src/ChainState.resi +72 -4
- package/src/Config.res +61 -33
- package/src/Config.res.mjs +50 -10
- package/src/ContractRegisterContext.res +2 -12
- package/src/ContractRegisterContext.res.mjs +3 -5
- package/src/Core.res +14 -3
- package/src/CrossChainState.res +113 -89
- package/src/CrossChainState.res.mjs +64 -60
- package/src/CrossChainState.resi +1 -1
- package/src/Ecosystem.res +5 -6
- package/src/Ecosystem.res.mjs +3 -3
- package/src/Envio.res +17 -11
- package/src/EnvioGlobal.res +53 -0
- package/src/EnvioGlobal.res.mjs +31 -0
- package/src/EventConfigBuilder.res +177 -88
- package/src/EventConfigBuilder.res.mjs +99 -42
- package/src/EventProcessing.res +74 -28
- package/src/EventProcessing.res.mjs +55 -29
- package/src/ExitOnCaughtUp.res +10 -2
- package/src/ExitOnCaughtUp.res.mjs +10 -1
- package/src/FetchState.res +544 -356
- package/src/FetchState.res.mjs +412 -471
- package/src/HandlerLoader.res +8 -104
- package/src/HandlerLoader.res.mjs +2 -81
- package/src/HandlerRegister.res +518 -144
- package/src/HandlerRegister.res.mjs +285 -133
- package/src/HandlerRegister.resi +24 -8
- package/src/IndexerState.res +10 -3
- package/src/IndexerState.res.mjs +11 -4
- package/src/IndexerState.resi +2 -1
- package/src/IndexingAddresses.res +108 -0
- package/src/IndexingAddresses.res.mjs +101 -0
- package/src/IndexingAddresses.resi +34 -0
- package/src/Internal.res +155 -46
- package/src/Internal.res.mjs +30 -2
- package/src/LoadLayer.res +5 -5
- package/src/LoadLayer.res.mjs +6 -6
- package/src/LogSelection.res +102 -165
- package/src/LogSelection.res.mjs +101 -116
- package/src/Main.res +71 -236
- package/src/Main.res.mjs +60 -145
- package/src/Metrics.res +74 -0
- package/src/Metrics.res.mjs +75 -0
- package/src/PgStorage.res +4 -4
- package/src/PgStorage.res.mjs +5 -5
- package/src/Prometheus.res +10 -63
- package/src/Prometheus.res.mjs +124 -171
- package/src/PruneStaleHistory.res +2 -2
- package/src/PruneStaleHistory.res.mjs +3 -3
- package/src/RawEvent.res +7 -2
- package/src/RawEvent.res.mjs +4 -4
- package/src/Rollback.res +3 -3
- package/src/Rollback.res.mjs +4 -4
- package/src/RollbackCommit.res +4 -1
- package/src/RollbackCommit.res.mjs +3 -2
- package/src/SimulateDeadInputTracker.res +85 -0
- package/src/SimulateDeadInputTracker.res.mjs +73 -0
- package/src/SimulateDeadInputTracker.resi +12 -0
- package/src/SimulateItems.res +91 -23
- package/src/SimulateItems.res.mjs +55 -32
- package/src/TestIndexer.res +54 -40
- package/src/TestIndexer.res.mjs +37 -30
- package/src/bindings/Performance.res +7 -0
- package/src/bindings/Performance.res.mjs +21 -0
- package/src/bindings/Performance.resi +7 -0
- package/src/bindings/Viem.res +0 -41
- package/src/bindings/Viem.res.mjs +1 -43
- package/src/sources/BlockStore.res +46 -0
- package/src/sources/BlockStore.res.mjs +24 -0
- package/src/sources/EventRouter.res +36 -33
- package/src/sources/EventRouter.res.mjs +13 -14
- package/src/sources/Evm.res +83 -72
- package/src/sources/Evm.res.mjs +53 -69
- package/src/sources/EvmChain.res +18 -20
- package/src/sources/EvmChain.res.mjs +15 -15
- package/src/sources/EvmRpcClient.res +74 -5
- package/src/sources/EvmRpcClient.res.mjs +13 -4
- package/src/sources/FieldMask.res +39 -0
- package/src/sources/FieldMask.res.mjs +42 -0
- package/src/sources/Fuel.res +9 -6
- package/src/sources/Fuel.res.mjs +5 -10
- package/src/sources/HyperFuelSource.res +46 -50
- package/src/sources/HyperFuelSource.res.mjs +64 -54
- package/src/sources/HyperSync.res +39 -7
- package/src/sources/HyperSync.res.mjs +57 -37
- package/src/sources/HyperSync.resi +12 -2
- package/src/sources/HyperSyncClient.res +22 -111
- package/src/sources/HyperSyncClient.res.mjs +2 -30
- package/src/sources/HyperSyncHeightStream.res +1 -8
- package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
- package/src/sources/HyperSyncSource.res +94 -107
- package/src/sources/HyperSyncSource.res.mjs +82 -86
- package/src/sources/Rpc.res +15 -47
- package/src/sources/Rpc.res.mjs +25 -56
- package/src/sources/RpcSource.res +320 -467
- package/src/sources/RpcSource.res.mjs +268 -385
- package/src/sources/RpcWebSocketHeightStream.res +0 -5
- package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
- package/src/sources/SimulateSource.res +10 -4
- package/src/sources/SimulateSource.res.mjs +16 -6
- package/src/sources/Source.res +34 -6
- package/src/sources/SourceManager.res +77 -19
- package/src/sources/SourceManager.res.mjs +63 -21
- package/src/sources/SourceManager.resi +10 -0
- package/src/sources/Svm.res +31 -16
- package/src/sources/Svm.res.mjs +36 -13
- package/src/sources/SvmHyperSyncClient.res +5 -32
- package/src/sources/SvmHyperSyncSource.res +159 -134
- package/src/sources/SvmHyperSyncSource.res.mjs +164 -129
- package/src/sources/TransactionStore.res +49 -0
- package/src/sources/TransactionStore.res.mjs +30 -0
- package/src/tui/Tui.res +13 -16
- package/src/tui/Tui.res.mjs +12 -14
- package/svm.schema.json +49 -37
- package/src/bindings/Hrtime.res +0 -58
- package/src/bindings/Hrtime.res.mjs +0 -90
- package/src/bindings/Hrtime.resi +0 -30
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Utils from "../Utils.res.mjs";
|
|
4
|
-
import * as Hrtime from "../bindings/Hrtime.res.mjs";
|
|
5
4
|
import * as Source from "./Source.res.mjs";
|
|
6
5
|
import * as Logging from "../Logging.res.mjs";
|
|
7
6
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
8
|
-
import * as Prometheus from "../Prometheus.res.mjs";
|
|
9
7
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
8
|
+
import * as Performance from "../bindings/Performance.res.mjs";
|
|
10
9
|
import * as LogSelection from "../LogSelection.res.mjs";
|
|
11
10
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
12
11
|
import * as ErrorHandling from "../ErrorHandling.res.mjs";
|
|
@@ -17,34 +16,33 @@ import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js
|
|
|
17
16
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
18
17
|
import * as HyperSyncHeightStream from "./HyperSyncHeightStream.res.mjs";
|
|
19
18
|
|
|
20
|
-
function getSelectionConfig(selection
|
|
19
|
+
function getSelectionConfig(selection) {
|
|
21
20
|
let capitalizedBlockFields = new Set();
|
|
22
21
|
let capitalizedTransactionFields = new Set();
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
let dynamicWildcardEventFiltersByContract = {};
|
|
22
|
+
let topicSelectionsByContract = {};
|
|
23
|
+
let wildcardTopicSelectionsByContract = {};
|
|
26
24
|
let noAddressesTopicSelections = [];
|
|
27
25
|
let contractNames = new Set();
|
|
28
|
-
selection.
|
|
29
|
-
let
|
|
30
|
-
|
|
26
|
+
selection.onEventRegistrations.forEach(reg => {
|
|
27
|
+
let eventConfig = reg.eventConfig;
|
|
28
|
+
let contractName = eventConfig.contractName;
|
|
29
|
+
let resolvedWhere = reg.resolvedWhere;
|
|
30
|
+
Array.from(eventConfig.selectedBlockFields).forEach(name => {
|
|
31
31
|
capitalizedBlockFields.add(Utils.$$String.capitalize(name));
|
|
32
32
|
});
|
|
33
|
-
Array.from(
|
|
34
|
-
|
|
33
|
+
Array.from(eventConfig.selectedTransactionFields).forEach(name => {
|
|
34
|
+
if (name !== "transactionIndex") {
|
|
35
|
+
capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
35
38
|
});
|
|
36
|
-
|
|
37
|
-
if (param.dependsOnAddresses) {
|
|
39
|
+
if (reg.dependsOnAddresses) {
|
|
38
40
|
contractNames.add(contractName);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
41
|
+
return Utils.Dict.pushMany(reg.isWildcard ? wildcardTopicSelectionsByContract : topicSelectionsByContract, contractName, resolvedWhere.topicSelections);
|
|
42
|
+
} else {
|
|
43
|
+
noAddressesTopicSelections.push(...LogSelection.materializeTopicSelections(resolvedWhere.topicSelections, []));
|
|
44
|
+
return;
|
|
44
45
|
}
|
|
45
|
-
let tmp;
|
|
46
|
-
tmp = eventFilters.TAG === "Static" ? eventFilters._0 : eventFilters._0([]);
|
|
47
|
-
noAddressesTopicSelections.push(...tmp);
|
|
48
46
|
});
|
|
49
47
|
let fieldSelection_block = Array.from(capitalizedBlockFields);
|
|
50
48
|
let fieldSelection_transaction = Array.from(capitalizedTransactionFields);
|
|
@@ -76,17 +74,13 @@ function getSelectionConfig(selection, chain) {
|
|
|
76
74
|
if (addresses.length === 0) {
|
|
77
75
|
return;
|
|
78
76
|
}
|
|
79
|
-
let topicSelections =
|
|
77
|
+
let topicSelections = topicSelectionsByContract[contractName];
|
|
80
78
|
if (topicSelections !== undefined) {
|
|
81
|
-
logSelections.push(LogSelection.make(addresses, topicSelections));
|
|
82
|
-
}
|
|
83
|
-
let fns = dynamicEventFiltersByContract[contractName];
|
|
84
|
-
if (fns !== undefined) {
|
|
85
|
-
logSelections.push(LogSelection.make(addresses, fns.flatMap(fn => fn(addresses))));
|
|
79
|
+
logSelections.push(LogSelection.make(addresses, LogSelection.materializeTopicSelections(topicSelections, addresses)));
|
|
86
80
|
}
|
|
87
|
-
let
|
|
88
|
-
if (
|
|
89
|
-
logSelections.push(LogSelection.make([],
|
|
81
|
+
let topicSelections$1 = wildcardTopicSelectionsByContract[contractName];
|
|
82
|
+
if (topicSelections$1 !== undefined) {
|
|
83
|
+
logSelections.push(LogSelection.make([], LogSelection.materializeTopicSelections(topicSelections$1, addresses)));
|
|
90
84
|
return;
|
|
91
85
|
}
|
|
92
86
|
});
|
|
@@ -98,8 +92,8 @@ function getSelectionConfig(selection, chain) {
|
|
|
98
92
|
};
|
|
99
93
|
}
|
|
100
94
|
|
|
101
|
-
function memoGetSelectionConfig(
|
|
102
|
-
return Utils.$$WeakMap.memoize(
|
|
95
|
+
function memoGetSelectionConfig() {
|
|
96
|
+
return Utils.$$WeakMap.memoize(getSelectionConfig);
|
|
103
97
|
}
|
|
104
98
|
|
|
105
99
|
function isUnauthorizedError(message) {
|
|
@@ -112,7 +106,7 @@ function make(param) {
|
|
|
112
106
|
let endpointUrl = param.endpointUrl;
|
|
113
107
|
let chain = param.chain;
|
|
114
108
|
let name = "HyperSync";
|
|
115
|
-
let getSelectionConfig =
|
|
109
|
+
let getSelectionConfig$1 = Utils.$$WeakMap.memoize(getSelectionConfig);
|
|
116
110
|
let apiToken$1 = apiToken !== undefined ? apiToken : Stdlib_JsError.throwWithMessage(`An Envio API token is required for using HyperSync as a data-source.
|
|
117
111
|
Set the ENVIO_API_TOKEN environment variable in your .env file.
|
|
118
112
|
Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
@@ -124,32 +118,28 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
124
118
|
client = ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate the hypersync client, please double check your ABI", exn);
|
|
125
119
|
}
|
|
126
120
|
let UndefinedValue = /* @__PURE__ */Primitive_exceptions.create("UndefinedValue");
|
|
127
|
-
let makeEventBatchQueueItem = (item, params,
|
|
128
|
-
let block = item.block;
|
|
121
|
+
let makeEventBatchQueueItem = (item, params, onEventRegistration) => {
|
|
129
122
|
let logIndex = item.logIndex;
|
|
130
123
|
return {
|
|
131
124
|
kind: 0,
|
|
132
|
-
|
|
133
|
-
timestamp: block.timestamp,
|
|
125
|
+
onEventRegistration: onEventRegistration,
|
|
134
126
|
chain: chain,
|
|
135
|
-
blockNumber:
|
|
136
|
-
blockHash: block.hash,
|
|
127
|
+
blockNumber: item.blockNumber,
|
|
137
128
|
logIndex: logIndex,
|
|
129
|
+
transactionIndex: item.transactionIndex,
|
|
138
130
|
payload: {
|
|
139
|
-
contractName: eventConfig.contractName,
|
|
140
|
-
eventName: eventConfig.name,
|
|
131
|
+
contractName: onEventRegistration.eventConfig.contractName,
|
|
132
|
+
eventName: onEventRegistration.eventConfig.name,
|
|
141
133
|
params: params,
|
|
142
134
|
chainId: chain,
|
|
143
135
|
srcAddress: item.srcAddress,
|
|
144
|
-
logIndex: logIndex
|
|
145
|
-
transaction: item.transaction,
|
|
146
|
-
block: block
|
|
136
|
+
logIndex: logIndex
|
|
147
137
|
}
|
|
148
138
|
};
|
|
149
139
|
};
|
|
150
|
-
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName,
|
|
151
|
-
let totalTimeRef =
|
|
152
|
-
let selectionConfig = getSelectionConfig(selection);
|
|
140
|
+
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, contractNameByAddress, knownHeight, param, selection, itemsTarget, retry, logger) => {
|
|
141
|
+
let totalTimeRef = Performance.now();
|
|
142
|
+
let selectionConfig = getSelectionConfig$1(selection);
|
|
153
143
|
let logSelections;
|
|
154
144
|
try {
|
|
155
145
|
logSelections = selectionConfig.getLogSelectionOrThrow(addressesByContractName);
|
|
@@ -157,11 +147,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
157
147
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
158
148
|
logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
|
|
159
149
|
}
|
|
160
|
-
let startFetchingBatchTimeRef =
|
|
161
|
-
Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
|
|
150
|
+
let startFetchingBatchTimeRef = Performance.now();
|
|
162
151
|
let pageUnsafe;
|
|
163
152
|
try {
|
|
164
|
-
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection);
|
|
153
|
+
pageUnsafe = await HyperSync.GetLogs.query(client, fromBlock, toBlock, logSelections, selectionConfig.fieldSelection, itemsTarget);
|
|
165
154
|
} catch (raw_error) {
|
|
166
155
|
let error = Primitive_exceptions.internalToException(raw_error);
|
|
167
156
|
if (error.RE_EXN_ID === HyperSync.GetLogs.$$Error) {
|
|
@@ -209,30 +198,38 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
209
198
|
Error: new Error()
|
|
210
199
|
};
|
|
211
200
|
}
|
|
212
|
-
let pageFetchTime =
|
|
201
|
+
let pageFetchTime = Performance.secondsSince(startFetchingBatchTimeRef);
|
|
202
|
+
let requestStats = [{
|
|
203
|
+
method: "getLogs",
|
|
204
|
+
seconds: pageFetchTime
|
|
205
|
+
}];
|
|
213
206
|
let knownHeight$1 = pageUnsafe.archiveHeight;
|
|
214
207
|
let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
|
|
215
|
-
let parsingTimeRef =
|
|
208
|
+
let parsingTimeRef = Performance.now();
|
|
216
209
|
let parsedQueueItems = [];
|
|
210
|
+
let blocksByNumber = new Map();
|
|
211
|
+
pageUnsafe.blocks.forEach(block => {
|
|
212
|
+
blocksByNumber.set(block.number, block);
|
|
213
|
+
});
|
|
217
214
|
pageUnsafe.items.forEach(item => {
|
|
218
|
-
let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress,
|
|
215
|
+
let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress, contractNameByAddress);
|
|
219
216
|
if (maybeEventConfig === undefined) {
|
|
220
217
|
return;
|
|
221
218
|
}
|
|
222
|
-
let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.contractName]);
|
|
219
|
+
let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.eventConfig.contractName]);
|
|
223
220
|
if (params !== undefined) {
|
|
224
221
|
parsedQueueItems.push(makeEventBatchQueueItem(item, Primitive_option.valFromOption(params), maybeEventConfig));
|
|
225
222
|
return;
|
|
226
223
|
} else {
|
|
227
224
|
let logIndex = item.logIndex;
|
|
228
|
-
let blockNumber = item.
|
|
225
|
+
let blockNumber = item.blockNumber;
|
|
229
226
|
let exn = {
|
|
230
227
|
RE_EXN_ID: UndefinedValue
|
|
231
228
|
};
|
|
232
229
|
if (maybeEventConfig.isWildcard) {
|
|
233
230
|
return;
|
|
234
231
|
}
|
|
235
|
-
let msg = `Event ` + maybeEventConfig.name + ` was unexpectedly parsed as undefined`;
|
|
232
|
+
let msg = `Event ` + maybeEventConfig.eventConfig.name + ` was unexpectedly parsed as undefined`;
|
|
236
233
|
let logger$1 = Logging.createChildFrom(logger, {
|
|
237
234
|
chainId: chain,
|
|
238
235
|
blockNumber: blockNumber,
|
|
@@ -242,19 +239,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
242
239
|
return ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
|
|
243
240
|
}
|
|
244
241
|
});
|
|
245
|
-
let parsingTimeElapsed =
|
|
242
|
+
let parsingTimeElapsed = Performance.secondsSince(parsingTimeRef);
|
|
246
243
|
let blockHashes = [];
|
|
247
|
-
pageUnsafe.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
blockHashes.push({
|
|
253
|
-
blockHash: match$1,
|
|
254
|
-
blockNumber: match
|
|
255
|
-
});
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
244
|
+
pageUnsafe.blocks.forEach(block => {
|
|
245
|
+
blockHashes.push({
|
|
246
|
+
blockHash: block.hash,
|
|
247
|
+
blockNumber: block.number
|
|
248
|
+
});
|
|
258
249
|
});
|
|
259
250
|
let match = pageUnsafe.rollbackGuard;
|
|
260
251
|
if (match !== undefined) {
|
|
@@ -272,15 +263,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
272
263
|
if (match$1 !== undefined) {
|
|
273
264
|
latestFetchedBlockTimestamp = match$1.timestamp;
|
|
274
265
|
} else {
|
|
275
|
-
let
|
|
276
|
-
|
|
277
|
-
let block = match$2.block;
|
|
278
|
-
latestFetchedBlockTimestamp = block.number === heighestBlockQueried ? block.timestamp : 0;
|
|
279
|
-
} else {
|
|
280
|
-
latestFetchedBlockTimestamp = 0;
|
|
281
|
-
}
|
|
266
|
+
let item = pageUnsafe.items[pageUnsafe.items.length - 1 | 0];
|
|
267
|
+
latestFetchedBlockTimestamp = item !== undefined && item.blockNumber === heighestBlockQueried ? blocksByNumber.get(item.blockNumber).timestamp : 0;
|
|
282
268
|
}
|
|
283
|
-
let totalTimeElapsed =
|
|
269
|
+
let totalTimeElapsed = Performance.secondsSince(totalTimeRef);
|
|
284
270
|
let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
|
|
285
271
|
let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
|
|
286
272
|
let stats = {
|
|
@@ -292,13 +278,19 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
292
278
|
knownHeight: knownHeight$1,
|
|
293
279
|
blockHashes: blockHashes,
|
|
294
280
|
parsedQueueItems: parsedQueueItems,
|
|
281
|
+
transactionStore: Primitive_option.some(pageUnsafe.transactionStore),
|
|
282
|
+
blockStore: Primitive_option.some(pageUnsafe.blockStore),
|
|
295
283
|
fromBlockQueried: fromBlock,
|
|
296
284
|
latestFetchedBlockNumber: heighestBlockQueried,
|
|
297
285
|
latestFetchedBlockTimestamp: latestFetchedBlockTimestamp,
|
|
298
|
-
stats: stats
|
|
286
|
+
stats: stats,
|
|
287
|
+
requestStats: requestStats
|
|
299
288
|
};
|
|
300
289
|
};
|
|
301
|
-
let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(
|
|
290
|
+
let getBlockHashes = (blockNumbers, logger) => HyperSync.queryBlockDataMulti(client, blockNumbers, name, chain, logger).then(param => ({
|
|
291
|
+
result: HyperSync.mapExn(param[0]),
|
|
292
|
+
requestStats: param[1]
|
|
293
|
+
}));
|
|
302
294
|
return {
|
|
303
295
|
name: name,
|
|
304
296
|
sourceFor: "Sync",
|
|
@@ -307,10 +299,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
307
299
|
pollingInterval: 100,
|
|
308
300
|
getBlockHashes: getBlockHashes,
|
|
309
301
|
getHeightOrThrow: async () => {
|
|
310
|
-
let timerRef =
|
|
311
|
-
let
|
|
302
|
+
let timerRef = Performance.now();
|
|
303
|
+
let height;
|
|
312
304
|
try {
|
|
313
|
-
|
|
305
|
+
height = await client.getHeight();
|
|
314
306
|
} catch (raw_e) {
|
|
315
307
|
let e = Primitive_exceptions.internalToException(raw_e);
|
|
316
308
|
if (e.RE_EXN_ID === "JsExn") {
|
|
@@ -320,7 +312,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
320
312
|
if (message.includes("401 Unauthorized")) {
|
|
321
313
|
Logging.error(`Your ENVIO_API_TOKEN was rejected by HyperSync (401 Unauthorized). The indexer will not be able to fetch events. Update the token and try again using 'envio start' or 'envio dev'. For more info: https://docs.envio.dev/docs/HyperSync/api-tokens`);
|
|
322
314
|
await new Promise((param, param$1) => {});
|
|
323
|
-
|
|
315
|
+
height = 0;
|
|
324
316
|
} else {
|
|
325
317
|
throw {
|
|
326
318
|
RE_EXN_ID: "JsExn",
|
|
@@ -339,10 +331,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
339
331
|
throw e;
|
|
340
332
|
}
|
|
341
333
|
}
|
|
342
|
-
let seconds =
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
334
|
+
let seconds = Performance.secondsSince(timerRef);
|
|
335
|
+
return {
|
|
336
|
+
height: height,
|
|
337
|
+
requestStats: [{
|
|
338
|
+
method: "getHeight",
|
|
339
|
+
seconds: seconds
|
|
340
|
+
}]
|
|
341
|
+
};
|
|
346
342
|
},
|
|
347
343
|
getItemsOrThrow: getItemsOrThrow,
|
|
348
344
|
createHeightSubscription: onHeight => HyperSyncHeightStream.subscribe(endpointUrl, apiToken$1, chain, onHeight)
|
package/src/sources/Rpc.res
CHANGED
|
@@ -38,7 +38,21 @@ let jsonRpcFetcher: Rest.ApiFetcher.t = async args => {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
let makeClient =
|
|
41
|
+
let makeClient = (url, ~headers=?) => {
|
|
42
|
+
let fetcher: Rest.ApiFetcher.t = switch headers {
|
|
43
|
+
| None => jsonRpcFetcher
|
|
44
|
+
| Some(customHeaders) =>
|
|
45
|
+
async args => {
|
|
46
|
+
let headers = switch args.headers {
|
|
47
|
+
| Some(headers) => headers
|
|
48
|
+
| None => Dict.make()
|
|
49
|
+
}
|
|
50
|
+
customHeaders->Dict.forEachWithKey((value, key) => headers->Dict.set(key, value->Obj.magic))
|
|
51
|
+
await jsonRpcFetcher({...args, headers: Some(headers)})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
Rest.client(url, ~fetcher)
|
|
55
|
+
}
|
|
42
56
|
|
|
43
57
|
type hex = string
|
|
44
58
|
let makeHexSchema = fromStr =>
|
|
@@ -70,13 +84,7 @@ let decimalFloatSchema: S.schema<float> = S.string->S.transform(s => {
|
|
|
70
84
|
module GetLogs = {
|
|
71
85
|
@unboxed
|
|
72
86
|
type topicFilter = Single(hex) | Multiple(array<hex>) | @as(null) Null
|
|
73
|
-
let topicFilterSchema = S.union([
|
|
74
|
-
S.literal(Null),
|
|
75
|
-
S.schema(s => Multiple(s.matches(S.array(S.string)))),
|
|
76
|
-
S.schema(s => Single(s.matches(S.string))),
|
|
77
|
-
])
|
|
78
87
|
type topicQuery = array<topicFilter>
|
|
79
|
-
let topicQuerySchema = S.array(topicFilterSchema)
|
|
80
88
|
|
|
81
89
|
let makeTopicQuery = (~topic0=[], ~topic1=[], ~topic2=[], ~topic3=[]) => {
|
|
82
90
|
let topics = [topic0, topic1, topic2, topic3]
|
|
@@ -106,51 +114,15 @@ module GetLogs = {
|
|
|
106
114
|
let mapTopicQuery = ({topic0, topic1, topic2, topic3}: Internal.topicSelection): topicQuery =>
|
|
107
115
|
makeTopicQuery(~topic0, ~topic1, ~topic2, ~topic3)
|
|
108
116
|
|
|
109
|
-
type param = {
|
|
110
|
-
fromBlock: int,
|
|
111
|
-
toBlock: int,
|
|
112
|
-
address?: array<Address.t>,
|
|
113
|
-
topics: topicQuery,
|
|
114
|
-
// blockHash?: string,
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let paramsSchema = S.object((s): param => {
|
|
118
|
-
fromBlock: s.field("fromBlock", hexIntSchema),
|
|
119
|
-
toBlock: s.field("toBlock", hexIntSchema),
|
|
120
|
-
address: ?s.field("address", S.option(S.array(Address.schema))),
|
|
121
|
-
topics: s.field("topics", topicQuerySchema),
|
|
122
|
-
// blockHash: ?s.field("blockHash", S.option(S.string)),
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
let fullParamsSchema = S.tuple1(paramsSchema)
|
|
126
|
-
|
|
127
117
|
type log = {
|
|
128
118
|
address: Address.t,
|
|
129
119
|
topics: array<hex>,
|
|
130
|
-
data: hex,
|
|
131
120
|
blockNumber: int,
|
|
132
121
|
transactionHash: hex,
|
|
133
122
|
transactionIndex: int,
|
|
134
123
|
blockHash: hex,
|
|
135
124
|
logIndex: int,
|
|
136
|
-
removed: bool,
|
|
137
125
|
}
|
|
138
|
-
|
|
139
|
-
let logSchema = S.object((s): log => {
|
|
140
|
-
address: s.field("address", Address.schema),
|
|
141
|
-
topics: s.field("topics", S.array(S.string)),
|
|
142
|
-
data: s.field("data", S.string),
|
|
143
|
-
blockNumber: s.field("blockNumber", hexIntSchema),
|
|
144
|
-
transactionHash: s.field("transactionHash", S.string),
|
|
145
|
-
transactionIndex: s.field("transactionIndex", hexIntSchema),
|
|
146
|
-
blockHash: s.field("blockHash", S.string),
|
|
147
|
-
logIndex: s.field("logIndex", hexIntSchema),
|
|
148
|
-
removed: s.field("removed", S.bool),
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
let resultSchema = S.array(logSchema)
|
|
152
|
-
|
|
153
|
-
let route = makeRpcRoute("eth_getLogs", fullParamsSchema, resultSchema)
|
|
154
126
|
}
|
|
155
127
|
|
|
156
128
|
module GetBlockByNumber = {
|
|
@@ -230,10 +202,6 @@ module GetTransactionReceipt = {
|
|
|
230
202
|
)
|
|
231
203
|
}
|
|
232
204
|
|
|
233
|
-
let getLogs = async (~client: Rest.client, ~param: GetLogs.param) => {
|
|
234
|
-
await GetLogs.route->Rest.fetch(param, ~client)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
205
|
let getBlock = async (~client: Rest.client, ~blockNumber: int) => {
|
|
238
206
|
await GetBlockByNumber.route->Rest.fetch(
|
|
239
207
|
{"blockNumber": blockNumber, "includeTransactions": false},
|
package/src/sources/Rpc.res.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import * as Rest from "../vendored/Rest.res.mjs";
|
|
|
4
4
|
import * as Viem from "viem";
|
|
5
5
|
import * as Utils from "../Utils.res.mjs";
|
|
6
6
|
import * as Address from "../Address.res.mjs";
|
|
7
|
+
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
7
8
|
import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.js";
|
|
8
9
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
9
10
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
@@ -48,8 +49,21 @@ async function jsonRpcFetcher(args) {
|
|
|
48
49
|
return response;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
function makeClient(url) {
|
|
52
|
-
|
|
52
|
+
function makeClient(url, headers) {
|
|
53
|
+
let fetcher = headers !== undefined ? async args => {
|
|
54
|
+
let headers$1 = args.headers;
|
|
55
|
+
let headers$2 = headers$1 !== undefined ? headers$1 : ({});
|
|
56
|
+
Stdlib_Dict.forEachWithKey(headers, (value, key) => {
|
|
57
|
+
headers$2[key] = value;
|
|
58
|
+
});
|
|
59
|
+
return await jsonRpcFetcher({
|
|
60
|
+
body: args.body,
|
|
61
|
+
headers: headers$2,
|
|
62
|
+
method: args.method,
|
|
63
|
+
path: args.path
|
|
64
|
+
});
|
|
65
|
+
} : jsonRpcFetcher;
|
|
66
|
+
return Rest.client(url, fetcher);
|
|
53
67
|
}
|
|
54
68
|
|
|
55
69
|
function makeHexSchema(fromStr) {
|
|
@@ -81,14 +95,6 @@ let decimalFloatSchema = S$RescriptSchema.transform(S$RescriptSchema.string, s =
|
|
|
81
95
|
}
|
|
82
96
|
}));
|
|
83
97
|
|
|
84
|
-
let topicFilterSchema = S$RescriptSchema.union([
|
|
85
|
-
S$RescriptSchema.literal(null),
|
|
86
|
-
S$RescriptSchema.schema(s => (s.m(S$RescriptSchema.array(S$RescriptSchema.string)))),
|
|
87
|
-
S$RescriptSchema.schema(s => (s.m(S$RescriptSchema.string)))
|
|
88
|
-
]);
|
|
89
|
-
|
|
90
|
-
let topicQuerySchema = S$RescriptSchema.array(topicFilterSchema);
|
|
91
|
-
|
|
92
98
|
function makeTopicQuery(topic0Opt, topic1Opt, topic2Opt, topic3Opt) {
|
|
93
99
|
let topic0 = topic0Opt !== undefined ? topic0Opt : [];
|
|
94
100
|
let topic1 = topic1Opt !== undefined ? topic1Opt : [];
|
|
@@ -130,41 +136,9 @@ function mapTopicQuery(param) {
|
|
|
130
136
|
return makeTopicQuery(param.topic0, param.topic1, param.topic2, param.topic3);
|
|
131
137
|
}
|
|
132
138
|
|
|
133
|
-
let paramsSchema = S$RescriptSchema.object(s => ({
|
|
134
|
-
fromBlock: s.f("fromBlock", hexIntSchema),
|
|
135
|
-
toBlock: s.f("toBlock", hexIntSchema),
|
|
136
|
-
address: s.f("address", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
|
|
137
|
-
topics: s.f("topics", topicQuerySchema)
|
|
138
|
-
}));
|
|
139
|
-
|
|
140
|
-
let fullParamsSchema = S$RescriptSchema.tuple1(paramsSchema);
|
|
141
|
-
|
|
142
|
-
let logSchema = S$RescriptSchema.object(s => ({
|
|
143
|
-
address: s.f("address", Address.schema),
|
|
144
|
-
topics: s.f("topics", S$RescriptSchema.array(S$RescriptSchema.string)),
|
|
145
|
-
data: s.f("data", S$RescriptSchema.string),
|
|
146
|
-
blockNumber: s.f("blockNumber", hexIntSchema),
|
|
147
|
-
transactionHash: s.f("transactionHash", S$RescriptSchema.string),
|
|
148
|
-
transactionIndex: s.f("transactionIndex", hexIntSchema),
|
|
149
|
-
blockHash: s.f("blockHash", S$RescriptSchema.string),
|
|
150
|
-
logIndex: s.f("logIndex", hexIntSchema),
|
|
151
|
-
removed: s.f("removed", S$RescriptSchema.bool)
|
|
152
|
-
}));
|
|
153
|
-
|
|
154
|
-
let resultSchema = S$RescriptSchema.array(logSchema);
|
|
155
|
-
|
|
156
|
-
let route = makeRpcRoute("eth_getLogs", fullParamsSchema, resultSchema);
|
|
157
|
-
|
|
158
139
|
let GetLogs = {
|
|
159
|
-
topicFilterSchema: topicFilterSchema,
|
|
160
|
-
topicQuerySchema: topicQuerySchema,
|
|
161
140
|
makeTopicQuery: makeTopicQuery,
|
|
162
|
-
mapTopicQuery: mapTopicQuery
|
|
163
|
-
paramsSchema: paramsSchema,
|
|
164
|
-
fullParamsSchema: fullParamsSchema,
|
|
165
|
-
logSchema: logSchema,
|
|
166
|
-
resultSchema: resultSchema,
|
|
167
|
-
route: route
|
|
141
|
+
mapTopicQuery: mapTopicQuery
|
|
168
142
|
};
|
|
169
143
|
|
|
170
144
|
let blockSchema = S$RescriptSchema.object(s => ({
|
|
@@ -190,22 +164,22 @@ let blockSchema = S$RescriptSchema.object(s => ({
|
|
|
190
164
|
uncles: s.f("uncles", S$RescriptSchema.$$null(S$RescriptSchema.array(S$RescriptSchema.string)))
|
|
191
165
|
}));
|
|
192
166
|
|
|
193
|
-
let paramsSchema
|
|
167
|
+
let paramsSchema = S$RescriptSchema.tuple(s => ({
|
|
194
168
|
blockNumber: s.item(0, hexIntSchema),
|
|
195
169
|
includeTransactions: s.item(1, S$RescriptSchema.bool)
|
|
196
170
|
}));
|
|
197
171
|
|
|
198
|
-
let resultSchema
|
|
172
|
+
let resultSchema = S$RescriptSchema.$$null(blockSchema);
|
|
199
173
|
|
|
200
|
-
let route
|
|
174
|
+
let route = makeRpcRoute("eth_getBlockByNumber", paramsSchema, resultSchema);
|
|
201
175
|
|
|
202
|
-
let rawRoute = makeRpcRoute("eth_getBlockByNumber", paramsSchema
|
|
176
|
+
let rawRoute = makeRpcRoute("eth_getBlockByNumber", paramsSchema, S$RescriptSchema.$$null(S$RescriptSchema.json(false)));
|
|
203
177
|
|
|
204
178
|
let GetBlockByNumber = {
|
|
205
179
|
blockSchema: blockSchema,
|
|
206
|
-
paramsSchema: paramsSchema
|
|
207
|
-
resultSchema: resultSchema
|
|
208
|
-
route: route
|
|
180
|
+
paramsSchema: paramsSchema,
|
|
181
|
+
resultSchema: resultSchema,
|
|
182
|
+
route: route,
|
|
209
183
|
rawRoute: rawRoute
|
|
210
184
|
};
|
|
211
185
|
|
|
@@ -221,12 +195,8 @@ let GetTransactionReceipt = {
|
|
|
221
195
|
rawRoute: rawRoute$2
|
|
222
196
|
};
|
|
223
197
|
|
|
224
|
-
async function getLogs(client, param) {
|
|
225
|
-
return await Rest.fetch(route, param, client);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
198
|
async function getBlock(client, blockNumber) {
|
|
229
|
-
return await Rest.fetch(route
|
|
199
|
+
return await Rest.fetch(route, {
|
|
230
200
|
blockNumber: blockNumber,
|
|
231
201
|
includeTransactions: false
|
|
232
202
|
}, client);
|
|
@@ -252,7 +222,6 @@ export {
|
|
|
252
222
|
GetBlockByNumber,
|
|
253
223
|
GetTransactionByHash,
|
|
254
224
|
GetTransactionReceipt,
|
|
255
|
-
getLogs,
|
|
256
225
|
getBlock,
|
|
257
226
|
getRawBlock,
|
|
258
227
|
}
|