envio
Version:
A latency and sync speed optimized, developer friendly blockchain data indexer.
76 lines (70 loc) • 3 kB
JavaScript
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Env from "../Env.res.mjs";
import * as RpcSource from "./RpcSource.res.mjs";
import * as EventRouter from "./EventRouter.res.mjs";
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
import * as HyperSyncSource from "./HyperSyncSource.res.mjs";
function getSyncConfig(param) {
let queryTimeoutMillis = Stdlib_Option.getOr(param.queryTimeoutMillis, 20000);
return {
initialBlockInterval: Stdlib_Option.getOr(Env.Configurable.SyncConfig.initialBlockInterval, Stdlib_Option.getOr(param.initialBlockInterval, 10000)),
backoffMultiplicative: Stdlib_Option.getOr(Env.Configurable.SyncConfig.backoffMultiplicative, Stdlib_Option.getOr(param.backoffMultiplicative, 0.8)),
accelerationAdditive: Stdlib_Option.getOr(Env.Configurable.SyncConfig.accelerationAdditive, Stdlib_Option.getOr(param.accelerationAdditive, 500)),
intervalCeiling: Stdlib_Option.getOr(Env.Configurable.SyncConfig.intervalCeiling, Stdlib_Option.getOr(param.intervalCeiling, 10000)),
backoffMillis: Stdlib_Option.getOr(param.backoffMillis, 5000),
queryTimeoutMillis: queryTimeoutMillis,
fallbackStallTimeout: Stdlib_Option.getOr(param.fallbackStallTimeout, queryTimeoutMillis / 2 | 0),
pollingInterval: Stdlib_Option.getOr(param.pollingInterval, 1000)
};
}
function collectEventParams(contracts) {
let result = [];
contracts.forEach(contract => {
contract.events.forEach(event => {
result.push({
sighash: event.sighash,
topicCount: event.topicCount,
eventName: event.name,
contractName: contract.name,
params: event.paramsMetadata
});
});
});
return result;
}
function makeSources(chain, contracts, hyperSync, rpcs, lowercaseAddresses) {
let eventRouter = EventRouter.fromEvmEventModsOrThrow(contracts.flatMap(contract => contract.events), chain);
let allEventParams = collectEventParams(contracts);
let sources = hyperSync !== undefined ? [HyperSyncSource.make({
chain: chain,
endpointUrl: hyperSync,
allEventParams: allEventParams,
eventRouter: eventRouter,
apiToken: Env.envioApiToken,
clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis,
lowercaseAddresses: lowercaseAddresses,
serializationFormat: Env.hypersyncClientSerializationFormat,
enableQueryCaching: Env.hypersyncClientEnableQueryCaching,
logLevel: Env.hypersyncLogLevel
})] : [];
rpcs.forEach(param => {
let source = RpcSource.make({
sourceFor: param.sourceFor,
syncConfig: getSyncConfig(Stdlib_Option.getOr(param.syncConfig, {})),
url: param.url,
chain: chain,
eventRouter: eventRouter,
allEventParams: allEventParams,
lowercaseAddresses: lowercaseAddresses,
ws: param.ws
});
sources.push(source);
});
return sources;
}
export {
getSyncConfig,
collectEventParams,
makeSources,
}
/* Env Not a pure module */