envio
Version:
A latency and sync speed optimized, developer friendly blockchain data indexer.
65 lines (59 loc) • 1.51 kB
JavaScript
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Rpc from "./Rpc.res.mjs";
import * as Core from "../Core.res.mjs";
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
function getJsonRpcError(exn) {
if (exn.RE_EXN_ID !== "JsExn") {
return;
}
let msg = Stdlib_JsExn.message(exn._1);
if (msg === undefined) {
return;
}
let obj;
try {
obj = Stdlib_JSON.Decode.object(JSON.parse(msg));
} catch (exn$1) {
return;
}
if (obj === undefined) {
return;
}
let match = obj["kind"];
let match$1 = obj["code"];
let match$2 = obj["message"];
if (match === "JsonRpcError" && typeof match$1 === "number" && typeof match$2 === "string") {
return {
code: match$1 | 0,
message: match$2
};
}
}
function coerceErrorOrThrow(exn) {
let rpcError = getJsonRpcError(exn);
if (rpcError !== undefined) {
throw {
RE_EXN_ID: Rpc.JsonRpcError,
_1: rpcError,
Error: new Error()
};
}
throw exn;
}
function make(url, httpReqTimeoutMillis) {
let client = Core.getAddon().EvmRpcClient.new({
url: url,
httpReqTimeoutMillis: httpReqTimeoutMillis
});
return {
getHeight: () => Stdlib_Promise.$$catch(client.getHeight(), coerceErrorOrThrow)
};
}
export {
getJsonRpcError,
coerceErrorOrThrow,
make,
}
/* Rpc Not a pure module */