UNPKG

envio

Version:

A latency and sync speed optimized, developer friendly blockchain data indexer.

80 lines (68 loc) 2.86 kB
// Generated by ReScript, PLEASE EDIT WITH CARE import * as Rpc from "./Rpc.res.mjs"; import * as Rest from "../vendored/Rest.res.mjs"; import * as Utils from "../Utils.res.mjs"; import * as Hrtime from "../bindings/Hrtime.res.mjs"; import * as Prometheus from "../Prometheus.res.mjs"; import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js"; import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs"; let cleanUpRawEventFieldsInPlace = (fields => { delete fields.hash delete fields.height delete fields.time }); let ecosystem_blockFields = ["slot"]; let ecosystem_transactionFields = []; let ecosystem_onBlockFilterSchema = S$RescriptSchema.object(s => s.f("slot", S$RescriptSchema.option(S$RescriptSchema.unknown))); let ecosystem_onEventBlockFilterSchema = S$RescriptSchema.object(param => {}); let ecosystem = { name: "svm", blockFields: ecosystem_blockFields, transactionFields: ecosystem_transactionFields, blockNumberName: "height", blockTimestampName: "time", blockHashName: "hash", cleanUpRawEventFieldsInPlace: cleanUpRawEventFieldsInPlace, onBlockMethodName: "onSlot", onBlockFilterSchema: ecosystem_onBlockFilterSchema, onEventBlockFilterSchema: ecosystem_onEventBlockFilterSchema }; let route = Rpc.makeRpcRoute("getSlot", S$RescriptSchema.tuple(s => { s.tag(0, { commitment: "finalized" }); }), S$RescriptSchema.int); let GetFinalizedSlot = { route: route }; function makeRPCSource(chain, rpc, sourceForOpt) { let sourceFor = sourceForOpt !== undefined ? sourceForOpt : "Sync"; let client = Rest.client(rpc, undefined); let host = Utils.Url.getHostFromUrl(rpc); let urlHost = host !== undefined ? host : Stdlib_JsError.throwWithMessage(`The RPC url for chain ` + chain.toString() + ` is in incorrect format. The RPC url needs to start with either http:// or https://`); let name = `RPC (` + urlHost + `)`; return { name: name, sourceFor: sourceFor, chain: chain, poweredByHyperSync: false, pollingInterval: 10000, getBlockHashes: (param, param$1) => Stdlib_JsError.throwWithMessage("Svm does not support getting block hashes"), getHeightOrThrow: async () => { let timerRef = Hrtime.makeTimer(); let height = await Rest.fetch(route, undefined, client); let seconds = Hrtime.toSecondsFloat(Hrtime.timeSince(timerRef)); Prometheus.SourceRequestCount.increment(name, chain, "getSlot"); Prometheus.SourceRequestCount.addSeconds(name, chain, "getSlot", seconds); return height; }, getItemsOrThrow: (param, param$1, param$2, param$3, param$4, param$5, param$6, param$7, param$8) => Stdlib_JsError.throwWithMessage("Svm does not support getting items") }; } export { cleanUpRawEventFieldsInPlace, ecosystem, GetFinalizedSlot, makeRPCSource, } /* ecosystem Not a pure module */