envio
Version:
A latency and sync speed optimized, developer friendly blockchain data indexer.
267 lines (245 loc) • 12.5 kB
JavaScript
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var $$BigInt = require("../bindings/BigInt.res.js");
var Address = require("../Address.res.js");
var EvmTypes = require("../EvmTypes.res.js");
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
var blockFieldOptionsSchema = S$RescriptSchema.$$enum([
"number",
"hash",
"parent_hash",
"nonce",
"sha3_uncles",
"logs_bloom",
"transactions_root",
"state_root",
"receipts_root",
"miner",
"difficulty",
"total_difficulty",
"extra_data",
"size",
"gas_limit",
"gas_used",
"timestamp",
"uncles",
"base_fee_per_gas"
]);
var blockFieldSelectionSchema = S$RescriptSchema.array(blockFieldOptionsSchema);
var transactionFieldOptionsSchema = S$RescriptSchema.$$enum([
"block_hash",
"block_number",
"from",
"gas",
"gas_price",
"hash",
"input",
"nonce",
"to",
"transaction_index",
"value",
"v",
"r",
"s",
"max_priority_fee_per_gas",
"max_fee_per_gas",
"chain_id",
"cumulative_gas_used",
"effective_gas_price",
"gas_used",
"contract_address",
"logs_bloom",
"type",
"root",
"status",
"sighash"
]);
var transactionFieldSelectionSchema = S$RescriptSchema.array(transactionFieldOptionsSchema);
var logFieldOptionsSchema = S$RescriptSchema.$$enum([
"removed",
"log_index",
"transaction_index",
"transaction_hash",
"block_hash",
"block_number",
"address",
"data",
"topic0",
"topic1",
"topic2",
"topic3"
]);
var logFieldSelectionSchema = S$RescriptSchema.array(logFieldOptionsSchema);
var fieldSelectionSchema = S$RescriptSchema.object(function (s) {
return {
block: s.f("block", S$RescriptSchema.option(blockFieldSelectionSchema)),
transaction: s.f("transaction", S$RescriptSchema.option(transactionFieldSelectionSchema)),
log: s.f("log", S$RescriptSchema.option(logFieldSelectionSchema))
};
});
var logParamsSchema = S$RescriptSchema.object(function (s) {
return {
address: s.f("address", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
topics: s.f("topics", S$RescriptSchema.array(S$RescriptSchema.array(EvmTypes.Hex.schema)))
};
});
var transactionParamsSchema = S$RescriptSchema.object(function (s) {
return {
from: s.f("from", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
to: s.f("to", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
sighash: s.f("sighash", S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.string)))
};
});
var postQueryBodySchema = S$RescriptSchema.object(function (s) {
return {
fromBlock: s.f("from_block", S$RescriptSchema.$$int),
toBlockExclusive: s.f("to_block", S$RescriptSchema.option(S$RescriptSchema.$$int)),
logs: s.f("logs", S$RescriptSchema.option(S$RescriptSchema.array(logParamsSchema))),
transactions: s.f("transactions", S$RescriptSchema.option(S$RescriptSchema.array(transactionParamsSchema))),
fieldSelection: s.f("field_selection", fieldSelectionSchema),
maxNumLogs: s.f("max_num_logs", S$RescriptSchema.option(S$RescriptSchema.$$int)),
includeAllBlocks: s.f("include_all_blocks", S$RescriptSchema.option(S$RescriptSchema.bool))
};
});
var QueryTypes = {
blockFieldOptionsSchema: blockFieldOptionsSchema,
blockFieldSelectionSchema: blockFieldSelectionSchema,
transactionFieldOptionsSchema: transactionFieldOptionsSchema,
transactionFieldSelectionSchema: transactionFieldSelectionSchema,
logFieldOptionsSchema: logFieldOptionsSchema,
logFieldSelectionSchema: logFieldSelectionSchema,
fieldSelectionSchema: fieldSelectionSchema,
logParamsSchema: logParamsSchema,
transactionParamsSchema: transactionParamsSchema,
postQueryBodySchema: postQueryBodySchema
};
var blockDataSchema = S$RescriptSchema.object(function (s) {
return {
number: s.f("number", S$RescriptSchema.option(S$RescriptSchema.$$int)),
hash: s.f("hash", S$RescriptSchema.option(S$RescriptSchema.string)),
parentHash: s.f("parent_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
nonce: s.f("nonce", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
sha3Uncles: s.f("sha3_uncles", S$RescriptSchema.option(S$RescriptSchema.string)),
logsBloom: s.f("logs_bloom", S$RescriptSchema.option(S$RescriptSchema.string)),
transactionsRoot: s.f("transactions_root", S$RescriptSchema.option(S$RescriptSchema.string)),
stateRoot: s.f("state_root", S$RescriptSchema.option(S$RescriptSchema.string)),
receiptsRoot: s.f("receipts_root", S$RescriptSchema.option(S$RescriptSchema.string)),
miner: s.f("miner", S$RescriptSchema.option(S$RescriptSchema.string)),
difficulty: s.f("difficulty", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
totalDifficulty: s.f("total_difficulty", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
extraData: s.f("extra_data", S$RescriptSchema.option(S$RescriptSchema.string)),
size: s.f("size", S$RescriptSchema.option($$BigInt.schema)),
gasLimit: s.f("gas_limit", S$RescriptSchema.option($$BigInt.schema)),
gasUsed: s.f("gas_used", S$RescriptSchema.option($$BigInt.schema)),
timestamp: s.f("timestamp", S$RescriptSchema.option($$BigInt.schema)),
uncles: s.f("unclus", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
baseFeePerGas: s.f("base_fee_per_gas", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema)))
};
});
var transactionDataSchema = S$RescriptSchema.object(function (s) {
return {
blockHash: s.f("block_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
blockNumber: s.f("block_number", S$RescriptSchema.option(S$RescriptSchema.$$int)),
from: s.f("from", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
gas: s.f("gas", S$RescriptSchema.option($$BigInt.schema)),
gasPrice: s.f("gas_price", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
hash: s.f("hash", S$RescriptSchema.option(S$RescriptSchema.string)),
input: s.f("input", S$RescriptSchema.option(S$RescriptSchema.string)),
nonce: s.f("nonce", S$RescriptSchema.option(S$RescriptSchema.$$int)),
to: s.f("to", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
transactionIndex: s.f("transaction_index", S$RescriptSchema.option(S$RescriptSchema.$$int)),
value: s.f("value", S$RescriptSchema.option($$BigInt.schema)),
v: s.f("v", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
r: s.f("r", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
s: s.f("s", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
maxPriorityFeePerGas: s.f("max_priority_fee_per_gas", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
maxFeePerGas: s.f("max_fee_per_gas", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
chainId: s.f("chain_id", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
cumulativeGasUsed: s.f("cumulative_gas_used", S$RescriptSchema.option($$BigInt.schema)),
effectiveGasPrice: s.f("effective_gas_price", S$RescriptSchema.option($$BigInt.schema)),
gasUsed: s.f("gas_used", S$RescriptSchema.option($$BigInt.schema)),
contractAddress: s.f("contract_address", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
logsBoom: s.f("logs_bloom", S$RescriptSchema.option(S$RescriptSchema.string)),
type_: s.f("type", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
root: s.f("root", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
status: s.f("status", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
sighash: s.f("sighash", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string)))
};
});
var logDataSchema = S$RescriptSchema.object(function (s) {
return {
removed: s.f("removed", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.bool))),
index: s.f("log_index", S$RescriptSchema.option(S$RescriptSchema.$$int)),
transactionIndex: s.f("transaction_index", S$RescriptSchema.option(S$RescriptSchema.$$int)),
transactionHash: s.f("transaction_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
blockHash: s.f("block_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
blockNumber: s.f("block_number", S$RescriptSchema.option(S$RescriptSchema.$$int)),
address: s.f("address", S$RescriptSchema.option(S$RescriptSchema.string)),
data: s.f("data", S$RescriptSchema.option(S$RescriptSchema.string)),
topic0: s.f("topic0", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema))),
topic1: s.f("topic1", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema))),
topic2: s.f("topic2", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema))),
topic3: s.f("topic3", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema)))
};
});
var dataSchema = S$RescriptSchema.object(function (s) {
return {
blocks: s.f("blocks", S$RescriptSchema.option(S$RescriptSchema.array(blockDataSchema))),
transactions: s.f("transactions", S$RescriptSchema.option(S$RescriptSchema.array(transactionDataSchema))),
logs: s.f("logs", S$RescriptSchema.option(S$RescriptSchema.array(logDataSchema)))
};
});
var queryResponseSchema = S$RescriptSchema.object(function (s) {
return {
data: s.f("data", S$RescriptSchema.array(dataSchema)),
archiveHeight: s.f("archive_height", S$RescriptSchema.$$int),
nextBlock: s.f("next_block", S$RescriptSchema.$$int),
totalTime: s.f("total_execution_time", S$RescriptSchema.$$int)
};
});
var ResponseTypes = {
blockDataSchema: blockDataSchema,
transactionDataSchema: transactionDataSchema,
logDataSchema: logDataSchema,
dataSchema: dataSchema,
queryResponseSchema: queryResponseSchema
};
function queryRoute() {
return {
method: "POST",
path: "/query",
input: (function (s) {
return {
query: s.body(postQueryBodySchema),
token: s.auth("Bearer")
};
}),
responses: [(function (s) {
return s.data(queryResponseSchema);
})]
};
}
function heightRoute() {
return {
method: "GET",
path: "/height",
input: (function (s) {
return s.auth("Bearer");
}),
responses: [(function (s) {
return s.data(S$RescriptSchema.union([
S$RescriptSchema.object(function (s) {
return s.f("height", S$RescriptSchema.$$int);
}),
S$RescriptSchema.shape(S$RescriptSchema.string, (function (s) {
return s;
}))
]));
})]
};
}
exports.QueryTypes = QueryTypes;
exports.ResponseTypes = ResponseTypes;
exports.queryRoute = queryRoute;
exports.heightRoute = heightRoute;
/* blockFieldOptionsSchema Not a pure module */