envio 2.22.0 → 2.22.1
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/package.json +7 -6
- package/src/Address.res.js +30 -0
- package/src/ChainMap.res.js +77 -0
- package/src/Envio.res.js +16 -0
- package/src/ErrorHandling.res.js +56 -0
- package/src/EventUtils.res.js +75 -0
- package/src/EvmTypes.res.js +16 -0
- package/src/FetchState.res.js +969 -0
- package/src/Hasura.res.js +245 -0
- package/src/Internal.res.js +50 -0
- package/src/LazyLoader.res.js +117 -0
- package/src/LoadManager.res.js +124 -0
- package/src/LogSelection.res.js +203 -0
- package/src/Logging.res.js +247 -0
- package/src/Persistence.res.js +90 -0
- package/src/PgStorage.res.js +125 -0
- package/src/Prometheus.res.js +750 -0
- package/src/ReorgDetection.res.js +223 -0
- package/src/Throttler.res.js +60 -0
- package/src/Time.res.js +41 -0
- package/src/TopicFilter.res.js +86 -0
- package/src/Utils.res.js +527 -0
- package/src/bindings/BigDecimal.res.js +41 -0
- package/src/bindings/BigInt.res.js +138 -0
- package/src/bindings/Ethers.res.js +109 -0
- package/src/bindings/Express.res.js +2 -0
- package/src/bindings/Hrtime.res.js +66 -0
- package/src/bindings/NodeJs.res.js +29 -0
- package/src/bindings/Pino.res.js +95 -0
- package/src/bindings/Postgres.res.js +16 -0
- package/src/bindings/PromClient.res.js +17 -0
- package/src/bindings/Promise.res.js +25 -0
- package/src/bindings/SDSL.res.js +8 -0
- package/src/bindings/Viem.res.js +45 -0
- package/src/db/EntityHistory.res.js +307 -0
- package/src/db/Schema.res.js +54 -0
- package/src/db/Table.res.js +365 -0
- package/src/sources/Fuel.res.js +28 -0
- package/src/sources/HyperFuel.res.js +193 -0
- package/src/sources/HyperFuelClient.res.js +19 -0
- package/src/sources/HyperSync.res.js +301 -0
- package/src/sources/HyperSyncClient.res.js +99 -0
- package/src/sources/HyperSyncJsonApi.res.js +259 -0
- package/src/sources/Rpc.res.js +198 -0
- package/src/sources/Source.res.js +9 -0
- package/src/sources/SourceManager.res.js +366 -0
- package/src/vendored/Rest.res.js +574 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Rest = require("../vendored/Rest.res.js");
|
|
5
|
+
var Time = require("../Time.res.js");
|
|
6
|
+
var Utils = require("../Utils.res.js");
|
|
7
|
+
var $$BigInt = require("../bindings/BigInt.res.js");
|
|
8
|
+
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
9
|
+
var Logging = require("../Logging.res.js");
|
|
10
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
11
|
+
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
12
|
+
var Belt_Result = require("rescript/lib/js/belt_Result.js");
|
|
13
|
+
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
14
|
+
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
|
|
15
|
+
var HyperSyncClient = require("./HyperSyncClient.res.js");
|
|
16
|
+
var HyperSyncJsonApi = require("./HyperSyncJsonApi.res.js");
|
|
17
|
+
|
|
18
|
+
var fieldNames = [
|
|
19
|
+
"address",
|
|
20
|
+
"data",
|
|
21
|
+
"topics",
|
|
22
|
+
"logIndex"
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
var HyperSyncQueryError = /* @__PURE__ */Caml_exceptions.create("HyperSync.HyperSyncQueryError");
|
|
26
|
+
|
|
27
|
+
function queryErrorToMsq(e) {
|
|
28
|
+
var match = e._0;
|
|
29
|
+
return match.queryName + " query failed due to unexpected missing params on response:\n " + match.missingParams.join(", ");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function mapExn(queryResponse) {
|
|
33
|
+
if (queryResponse.TAG === "Ok") {
|
|
34
|
+
return {
|
|
35
|
+
TAG: "Ok",
|
|
36
|
+
_0: queryResponse._0
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
return {
|
|
40
|
+
TAG: "Error",
|
|
41
|
+
_0: {
|
|
42
|
+
RE_EXN_ID: HyperSyncQueryError,
|
|
43
|
+
_1: queryResponse._0
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var $$Error = /* @__PURE__ */Caml_exceptions.create("HyperSync.GetLogs.Error");
|
|
50
|
+
|
|
51
|
+
function makeRequestBody(fromBlock, toBlockInclusive, addressesWithTopics, fieldSelection) {
|
|
52
|
+
return {
|
|
53
|
+
fromBlock: fromBlock,
|
|
54
|
+
toBlock: toBlockInclusive !== undefined ? toBlockInclusive + 1 | 0 : undefined,
|
|
55
|
+
logs: addressesWithTopics,
|
|
56
|
+
fieldSelection: fieldSelection
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function addMissingParams(acc, fieldNames, returnedObj, prefix) {
|
|
61
|
+
Belt_Array.forEach(fieldNames, (function (fieldName) {
|
|
62
|
+
var match = returnedObj[fieldName];
|
|
63
|
+
if (match !== undefined) {
|
|
64
|
+
return ;
|
|
65
|
+
} else {
|
|
66
|
+
acc.push(prefix + "." + fieldName);
|
|
67
|
+
return ;
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function query(client, fromBlock, toBlock, logSelections, fieldSelection, nonOptionalBlockFieldNames, nonOptionalTransactionFieldNames) {
|
|
73
|
+
var addressesWithTopics = Belt_Array.flatMap(logSelections, (function (param) {
|
|
74
|
+
var addresses = param.addresses;
|
|
75
|
+
return Belt_Array.map(param.topicSelections, (function (param) {
|
|
76
|
+
var topics = HyperSyncClient.QueryTypes.makeTopicSelection(param.topic0, param.topic1, param.topic2, param.topic3);
|
|
77
|
+
return HyperSyncClient.QueryTypes.makeLogSelection(addresses, topics);
|
|
78
|
+
}));
|
|
79
|
+
}));
|
|
80
|
+
var query$1 = makeRequestBody(fromBlock, toBlock, addressesWithTopics, fieldSelection);
|
|
81
|
+
var res = await client.getEvents(query$1);
|
|
82
|
+
if (res.nextBlock <= fromBlock) {
|
|
83
|
+
throw {
|
|
84
|
+
RE_EXN_ID: $$Error,
|
|
85
|
+
_1: "WrongInstance",
|
|
86
|
+
Error: new Error()
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var items = Belt_Array.map(res.data, (function (item) {
|
|
90
|
+
var missingParams = [];
|
|
91
|
+
addMissingParams(missingParams, fieldNames, item.log, "log");
|
|
92
|
+
addMissingParams(missingParams, nonOptionalBlockFieldNames, item.block, "block");
|
|
93
|
+
addMissingParams(missingParams, nonOptionalTransactionFieldNames, item.transaction, "transaction");
|
|
94
|
+
if (missingParams.length !== 0) {
|
|
95
|
+
throw {
|
|
96
|
+
RE_EXN_ID: $$Error,
|
|
97
|
+
_1: {
|
|
98
|
+
TAG: "UnexpectedMissingParams",
|
|
99
|
+
missingParams: missingParams
|
|
100
|
+
},
|
|
101
|
+
Error: new Error()
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
var logUnsanitized = item.log;
|
|
105
|
+
var topics = Belt_Array.keepMap(item.log.topics, (function (prim) {
|
|
106
|
+
if (prim == null) {
|
|
107
|
+
return ;
|
|
108
|
+
} else {
|
|
109
|
+
return Caml_option.some(prim);
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
var address = item.log.address;
|
|
113
|
+
var log_data = logUnsanitized.data;
|
|
114
|
+
var log_logIndex = logUnsanitized.logIndex;
|
|
115
|
+
var log = {
|
|
116
|
+
address: address,
|
|
117
|
+
data: log_data,
|
|
118
|
+
topics: topics,
|
|
119
|
+
logIndex: log_logIndex
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
log: log,
|
|
123
|
+
block: item.block,
|
|
124
|
+
transaction: item.transaction
|
|
125
|
+
};
|
|
126
|
+
}));
|
|
127
|
+
return {
|
|
128
|
+
items: items,
|
|
129
|
+
nextBlock: res.nextBlock,
|
|
130
|
+
archiveHeight: Belt_Option.getWithDefault(res.archiveHeight, 0),
|
|
131
|
+
rollbackGuard: res.rollbackGuard,
|
|
132
|
+
events: res.data
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function makeRequestBody$1(fromBlock, toBlock) {
|
|
137
|
+
return {
|
|
138
|
+
fromBlock: fromBlock,
|
|
139
|
+
toBlockExclusive: toBlock + 1 | 0,
|
|
140
|
+
fieldSelection: {
|
|
141
|
+
block: [
|
|
142
|
+
"number",
|
|
143
|
+
"hash",
|
|
144
|
+
"timestamp"
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
includeAllBlocks: true
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function convertResponse(res) {
|
|
152
|
+
return Utils.$$Array.transposeResults(Belt_Array.flatMap(res.data, (function (item) {
|
|
153
|
+
return Belt_Option.mapWithDefault(item.blocks, [], (function (blocks) {
|
|
154
|
+
return Belt_Array.map(blocks, (function (block) {
|
|
155
|
+
var blockNumber = block.number;
|
|
156
|
+
if (blockNumber !== undefined) {
|
|
157
|
+
var blockHash = block.hash;
|
|
158
|
+
if (blockHash !== undefined) {
|
|
159
|
+
var timestamp = block.timestamp;
|
|
160
|
+
if (timestamp !== undefined) {
|
|
161
|
+
var blockTimestamp = Belt_Option.getExn($$BigInt.toInt(timestamp));
|
|
162
|
+
return {
|
|
163
|
+
TAG: "Ok",
|
|
164
|
+
_0: {
|
|
165
|
+
blockHash: blockHash,
|
|
166
|
+
blockNumber: blockNumber,
|
|
167
|
+
blockTimestamp: blockTimestamp
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
var missingParams = Belt_Array.keepMap([
|
|
176
|
+
Utils.$$Option.mapNone(block.number, "block.number"),
|
|
177
|
+
Utils.$$Option.mapNone(block.timestamp, "block.timestamp"),
|
|
178
|
+
Utils.$$Option.mapNone(block.hash, "block.hash")
|
|
179
|
+
], (function (p) {
|
|
180
|
+
return p;
|
|
181
|
+
}));
|
|
182
|
+
return {
|
|
183
|
+
TAG: "Error",
|
|
184
|
+
_0: {
|
|
185
|
+
TAG: "UnexpectedMissingParams",
|
|
186
|
+
_0: {
|
|
187
|
+
queryName: "query block data HyperSync",
|
|
188
|
+
missingParams: missingParams
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}));
|
|
193
|
+
}));
|
|
194
|
+
})));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function queryBlockData(serverUrl, apiToken, fromBlock, toBlock, logger) {
|
|
198
|
+
var body = makeRequestBody$1(fromBlock, toBlock);
|
|
199
|
+
var logger$1 = Logging.createChildFrom(logger, {
|
|
200
|
+
logType: "HyperSync get block hash query",
|
|
201
|
+
fromBlock: fromBlock,
|
|
202
|
+
toBlock: toBlock
|
|
203
|
+
});
|
|
204
|
+
var maybeSuccessfulRes;
|
|
205
|
+
var exit = 0;
|
|
206
|
+
var res;
|
|
207
|
+
try {
|
|
208
|
+
res = await Time.retryAsyncWithExponentialBackOff(undefined, undefined, undefined, undefined, logger$1, (function () {
|
|
209
|
+
return Rest.$$fetch(HyperSyncJsonApi.queryRoute, {
|
|
210
|
+
query: body,
|
|
211
|
+
token: apiToken
|
|
212
|
+
}, Rest.client(serverUrl, undefined));
|
|
213
|
+
}));
|
|
214
|
+
exit = 1;
|
|
215
|
+
}
|
|
216
|
+
catch (exn){
|
|
217
|
+
maybeSuccessfulRes = undefined;
|
|
218
|
+
}
|
|
219
|
+
if (exit === 1) {
|
|
220
|
+
maybeSuccessfulRes = res.nextBlock <= fromBlock ? undefined : res;
|
|
221
|
+
}
|
|
222
|
+
if (maybeSuccessfulRes !== undefined) {
|
|
223
|
+
var err = convertResponse(maybeSuccessfulRes);
|
|
224
|
+
if (err.TAG !== "Ok") {
|
|
225
|
+
return err;
|
|
226
|
+
}
|
|
227
|
+
if (maybeSuccessfulRes.nextBlock > toBlock) {
|
|
228
|
+
return err;
|
|
229
|
+
}
|
|
230
|
+
var datas = err._0;
|
|
231
|
+
var restRes = await queryBlockData(serverUrl, apiToken, maybeSuccessfulRes.nextBlock, toBlock, logger$1);
|
|
232
|
+
return Belt_Result.map(restRes, (function (rest) {
|
|
233
|
+
return Belt_Array.concat(datas, rest);
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
var logger$2 = Logging.createChild({
|
|
237
|
+
url: serverUrl
|
|
238
|
+
});
|
|
239
|
+
Logging.childInfo(logger$2, "Block #" + String(fromBlock) + " not found in HyperSync. HyperSync has multiple instances and it's possible that they drift independently slightly from the head. Indexing should continue correctly after retrying the query in " + String(100) + "ms.");
|
|
240
|
+
await Time.resolvePromiseAfterDelay(100);
|
|
241
|
+
return await queryBlockData(serverUrl, apiToken, fromBlock, toBlock, logger$2);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async function queryBlockDataMulti(serverUrl, apiToken, blockNumbers, logger) {
|
|
245
|
+
var firstBlock = Belt_Array.get(blockNumbers, 0);
|
|
246
|
+
if (firstBlock === undefined) {
|
|
247
|
+
return {
|
|
248
|
+
TAG: "Ok",
|
|
249
|
+
_0: []
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
var fromBlock = firstBlock;
|
|
253
|
+
var toBlock = firstBlock;
|
|
254
|
+
var set = new Set();
|
|
255
|
+
for(var idx = 0 ,idx_finish = blockNumbers.length; idx < idx_finish; ++idx){
|
|
256
|
+
var blockNumber = blockNumbers[idx];
|
|
257
|
+
if (blockNumber < fromBlock) {
|
|
258
|
+
fromBlock = blockNumber;
|
|
259
|
+
}
|
|
260
|
+
if (blockNumber > toBlock) {
|
|
261
|
+
toBlock = blockNumber;
|
|
262
|
+
}
|
|
263
|
+
set.add(blockNumber);
|
|
264
|
+
}
|
|
265
|
+
if ((toBlock - fromBlock | 0) > 1000) {
|
|
266
|
+
Js_exn.raiseError("Invalid block data request. Range of block numbers is too large. Max range is 1000. Requested range: " + String(fromBlock) + "-" + String(toBlock));
|
|
267
|
+
}
|
|
268
|
+
var res = await queryBlockData(serverUrl, apiToken, fromBlock, toBlock, logger);
|
|
269
|
+
var filtered = Belt_Result.map(res, (function (datas) {
|
|
270
|
+
return Belt_Array.keep(datas, (function (data) {
|
|
271
|
+
return set.delete(data.blockNumber);
|
|
272
|
+
}));
|
|
273
|
+
}));
|
|
274
|
+
if (set.size > 0) {
|
|
275
|
+
Js_exn.raiseError("Invalid response. Failed to get block data for block numbers: " + Array.from(set).join(", "));
|
|
276
|
+
}
|
|
277
|
+
return filtered;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function queryBlockData$1(serverUrl, apiToken, blockNumber, logger) {
|
|
281
|
+
return queryBlockData(serverUrl, apiToken, blockNumber, blockNumber, logger).then(function (res) {
|
|
282
|
+
return Belt_Result.map(res, (function (res) {
|
|
283
|
+
return Belt_Array.get(res, 0);
|
|
284
|
+
}));
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
var Log = {};
|
|
289
|
+
|
|
290
|
+
var GetLogs = {
|
|
291
|
+
$$Error: $$Error,
|
|
292
|
+
query: query
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
exports.Log = Log;
|
|
296
|
+
exports.queryErrorToMsq = queryErrorToMsq;
|
|
297
|
+
exports.GetLogs = GetLogs;
|
|
298
|
+
exports.queryBlockData = queryBlockData$1;
|
|
299
|
+
exports.queryBlockDataMulti = queryBlockDataMulti;
|
|
300
|
+
exports.mapExn = mapExn;
|
|
301
|
+
/* Rest Not a pure module */
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var Address = require("../Address.res.js");
|
|
5
|
+
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
6
|
+
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
7
|
+
var HypersyncClient = require("@envio-dev/hypersync-client");
|
|
8
|
+
|
|
9
|
+
function makeTopicSelection(topic0Opt, topic1Opt, topic2Opt, topic3Opt) {
|
|
10
|
+
var topic0 = topic0Opt !== undefined ? topic0Opt : [];
|
|
11
|
+
var topic1 = topic1Opt !== undefined ? topic1Opt : [];
|
|
12
|
+
var topic2 = topic2Opt !== undefined ? topic2Opt : [];
|
|
13
|
+
var topic3 = topic3Opt !== undefined ? topic3Opt : [];
|
|
14
|
+
return [
|
|
15
|
+
topic0,
|
|
16
|
+
topic1,
|
|
17
|
+
topic2,
|
|
18
|
+
topic3
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function makeLogSelection(address, topics) {
|
|
23
|
+
return {
|
|
24
|
+
address: address,
|
|
25
|
+
topics: topics
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var QueryTypes = {
|
|
30
|
+
makeTopicSelection: makeTopicSelection,
|
|
31
|
+
makeLogSelection: makeLogSelection
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var accessListSchema = S$RescriptSchema.object(function (s) {
|
|
35
|
+
return {
|
|
36
|
+
address: s.f("address", S$RescriptSchema.option(Address.schema)),
|
|
37
|
+
storageKeys: s.f("storageKeys", S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.string)))
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
var authorizationListSchema = S$RescriptSchema.object(function (s) {
|
|
42
|
+
return {
|
|
43
|
+
chainId: s.f("chainId", S$RescriptSchema.bigint),
|
|
44
|
+
address: s.f("address", Address.schema),
|
|
45
|
+
nonce: s.f("nonce", S$RescriptSchema.$$int),
|
|
46
|
+
yParity: s.f("yParity", S$RescriptSchema.$$enum([
|
|
47
|
+
0,
|
|
48
|
+
1
|
|
49
|
+
])),
|
|
50
|
+
r: s.f("r", S$RescriptSchema.string),
|
|
51
|
+
s: s.f("s", S$RescriptSchema.string)
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
var ResponseTypes = {
|
|
56
|
+
accessListSchema: accessListSchema,
|
|
57
|
+
authorizationListSchema: authorizationListSchema
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function make(url, apiToken, httpReqTimeoutMillis, maxNumRetries) {
|
|
61
|
+
return HypersyncClient.HypersyncClient.new({
|
|
62
|
+
url: url,
|
|
63
|
+
bearerToken: apiToken,
|
|
64
|
+
httpReqTimeoutMillis: httpReqTimeoutMillis,
|
|
65
|
+
maxNumRetries: maxNumRetries,
|
|
66
|
+
enableChecksumAddresses: true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function toUnderlying(_d) {
|
|
71
|
+
while(true) {
|
|
72
|
+
var d = _d;
|
|
73
|
+
if (Array.isArray(d)) {
|
|
74
|
+
return Belt_Array.map(d, toUnderlying);
|
|
75
|
+
}
|
|
76
|
+
switch (typeof d) {
|
|
77
|
+
case "boolean" :
|
|
78
|
+
return d;
|
|
79
|
+
case "string" :
|
|
80
|
+
return d;
|
|
81
|
+
case "bigint" :
|
|
82
|
+
return d;
|
|
83
|
+
case "object" :
|
|
84
|
+
_d = d.val;
|
|
85
|
+
continue ;
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var Decoder = {
|
|
92
|
+
toUnderlying: toUnderlying
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
exports.QueryTypes = QueryTypes;
|
|
96
|
+
exports.ResponseTypes = ResponseTypes;
|
|
97
|
+
exports.make = make;
|
|
98
|
+
exports.Decoder = Decoder;
|
|
99
|
+
/* accessListSchema Not a pure module */
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var $$BigInt = require("../bindings/BigInt.res.js");
|
|
5
|
+
var Address = require("../Address.res.js");
|
|
6
|
+
var EvmTypes = require("../EvmTypes.res.js");
|
|
7
|
+
var S$RescriptSchema = require("rescript-schema/src/S.res.js");
|
|
8
|
+
|
|
9
|
+
var blockFieldOptionsSchema = S$RescriptSchema.$$enum([
|
|
10
|
+
"number",
|
|
11
|
+
"hash",
|
|
12
|
+
"parent_hash",
|
|
13
|
+
"nonce",
|
|
14
|
+
"sha3_uncles",
|
|
15
|
+
"logs_bloom",
|
|
16
|
+
"transactions_root",
|
|
17
|
+
"state_root",
|
|
18
|
+
"receipts_root",
|
|
19
|
+
"miner",
|
|
20
|
+
"difficulty",
|
|
21
|
+
"total_difficulty",
|
|
22
|
+
"extra_data",
|
|
23
|
+
"size",
|
|
24
|
+
"gas_limit",
|
|
25
|
+
"gas_used",
|
|
26
|
+
"timestamp",
|
|
27
|
+
"uncles",
|
|
28
|
+
"base_fee_per_gas"
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
var blockFieldSelectionSchema = S$RescriptSchema.array(blockFieldOptionsSchema);
|
|
32
|
+
|
|
33
|
+
var transactionFieldOptionsSchema = S$RescriptSchema.$$enum([
|
|
34
|
+
"block_hash",
|
|
35
|
+
"block_number",
|
|
36
|
+
"from",
|
|
37
|
+
"gas",
|
|
38
|
+
"gas_price",
|
|
39
|
+
"hash",
|
|
40
|
+
"input",
|
|
41
|
+
"nonce",
|
|
42
|
+
"to",
|
|
43
|
+
"transaction_index",
|
|
44
|
+
"value",
|
|
45
|
+
"v",
|
|
46
|
+
"r",
|
|
47
|
+
"s",
|
|
48
|
+
"max_priority_fee_per_gas",
|
|
49
|
+
"max_fee_per_gas",
|
|
50
|
+
"chain_id",
|
|
51
|
+
"cumulative_gas_used",
|
|
52
|
+
"effective_gas_price",
|
|
53
|
+
"gas_used",
|
|
54
|
+
"contract_address",
|
|
55
|
+
"logs_bloom",
|
|
56
|
+
"type",
|
|
57
|
+
"root",
|
|
58
|
+
"status",
|
|
59
|
+
"sighash"
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
var transactionFieldSelectionSchema = S$RescriptSchema.array(transactionFieldOptionsSchema);
|
|
63
|
+
|
|
64
|
+
var logFieldOptionsSchema = S$RescriptSchema.$$enum([
|
|
65
|
+
"removed",
|
|
66
|
+
"log_index",
|
|
67
|
+
"transaction_index",
|
|
68
|
+
"transaction_hash",
|
|
69
|
+
"block_hash",
|
|
70
|
+
"block_number",
|
|
71
|
+
"address",
|
|
72
|
+
"data",
|
|
73
|
+
"topic0",
|
|
74
|
+
"topic1",
|
|
75
|
+
"topic2",
|
|
76
|
+
"topic3"
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
var logFieldSelectionSchema = S$RescriptSchema.array(logFieldOptionsSchema);
|
|
80
|
+
|
|
81
|
+
var fieldSelectionSchema = S$RescriptSchema.object(function (s) {
|
|
82
|
+
return {
|
|
83
|
+
block: s.f("block", S$RescriptSchema.option(blockFieldSelectionSchema)),
|
|
84
|
+
transaction: s.f("transaction", S$RescriptSchema.option(transactionFieldSelectionSchema)),
|
|
85
|
+
log: s.f("log", S$RescriptSchema.option(logFieldSelectionSchema))
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
var logParamsSchema = S$RescriptSchema.object(function (s) {
|
|
90
|
+
return {
|
|
91
|
+
address: s.f("address", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
|
|
92
|
+
topics: s.f("topics", S$RescriptSchema.array(S$RescriptSchema.array(EvmTypes.Hex.schema)))
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
var transactionParamsSchema = S$RescriptSchema.object(function (s) {
|
|
97
|
+
return {
|
|
98
|
+
from: s.f("from", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
|
|
99
|
+
to: s.f("to", S$RescriptSchema.option(S$RescriptSchema.array(Address.schema))),
|
|
100
|
+
sighash: s.f("sighash", S$RescriptSchema.option(S$RescriptSchema.array(S$RescriptSchema.string)))
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
var postQueryBodySchema = S$RescriptSchema.object(function (s) {
|
|
105
|
+
return {
|
|
106
|
+
fromBlock: s.f("from_block", S$RescriptSchema.$$int),
|
|
107
|
+
toBlockExclusive: s.f("to_block", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
108
|
+
logs: s.f("logs", S$RescriptSchema.option(S$RescriptSchema.array(logParamsSchema))),
|
|
109
|
+
transactions: s.f("transactions", S$RescriptSchema.option(S$RescriptSchema.array(transactionParamsSchema))),
|
|
110
|
+
fieldSelection: s.f("field_selection", fieldSelectionSchema),
|
|
111
|
+
maxNumLogs: s.f("max_num_logs", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
112
|
+
includeAllBlocks: s.f("include_all_blocks", S$RescriptSchema.option(S$RescriptSchema.bool))
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
var QueryTypes = {
|
|
117
|
+
blockFieldOptionsSchema: blockFieldOptionsSchema,
|
|
118
|
+
blockFieldSelectionSchema: blockFieldSelectionSchema,
|
|
119
|
+
transactionFieldOptionsSchema: transactionFieldOptionsSchema,
|
|
120
|
+
transactionFieldSelectionSchema: transactionFieldSelectionSchema,
|
|
121
|
+
logFieldOptionsSchema: logFieldOptionsSchema,
|
|
122
|
+
logFieldSelectionSchema: logFieldSelectionSchema,
|
|
123
|
+
fieldSelectionSchema: fieldSelectionSchema,
|
|
124
|
+
logParamsSchema: logParamsSchema,
|
|
125
|
+
transactionParamsSchema: transactionParamsSchema,
|
|
126
|
+
postQueryBodySchema: postQueryBodySchema
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
var blockDataSchema = S$RescriptSchema.object(function (s) {
|
|
130
|
+
return {
|
|
131
|
+
number: s.f("number", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
132
|
+
hash: s.f("hash", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
133
|
+
parentHash: s.f("parent_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
134
|
+
nonce: s.f("nonce", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
|
|
135
|
+
sha3Uncles: s.f("sha3_uncles", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
136
|
+
logsBloom: s.f("logs_bloom", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
137
|
+
transactionsRoot: s.f("transactions_root", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
138
|
+
stateRoot: s.f("state_root", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
139
|
+
receiptsRoot: s.f("receipts_root", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
140
|
+
miner: s.f("miner", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
141
|
+
difficulty: s.f("difficulty", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
|
|
142
|
+
totalDifficulty: s.f("total_difficulty", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
|
|
143
|
+
extraData: s.f("extra_data", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
144
|
+
size: s.f("size", S$RescriptSchema.option($$BigInt.schema)),
|
|
145
|
+
gasLimit: s.f("gas_limit", S$RescriptSchema.option($$BigInt.schema)),
|
|
146
|
+
gasUsed: s.f("gas_used", S$RescriptSchema.option($$BigInt.schema)),
|
|
147
|
+
timestamp: s.f("timestamp", S$RescriptSchema.option($$BigInt.schema)),
|
|
148
|
+
uncles: s.f("unclus", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
149
|
+
baseFeePerGas: s.f("base_fee_per_gas", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema)))
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
var transactionDataSchema = S$RescriptSchema.object(function (s) {
|
|
154
|
+
return {
|
|
155
|
+
blockHash: s.f("block_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
156
|
+
blockNumber: s.f("block_number", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
157
|
+
from: s.f("from", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
158
|
+
gas: s.f("gas", S$RescriptSchema.option($$BigInt.schema)),
|
|
159
|
+
gasPrice: s.f("gas_price", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
|
|
160
|
+
hash: s.f("hash", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
161
|
+
input: s.f("input", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
162
|
+
nonce: s.f("nonce", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
163
|
+
to: s.f("to", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
164
|
+
transactionIndex: s.f("transaction_index", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
165
|
+
value: s.f("value", S$RescriptSchema.option($$BigInt.schema)),
|
|
166
|
+
v: s.f("v", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
167
|
+
r: s.f("r", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
168
|
+
s: s.f("s", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
169
|
+
maxPriorityFeePerGas: s.f("max_priority_fee_per_gas", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
|
|
170
|
+
maxFeePerGas: s.f("max_fee_per_gas", S$RescriptSchema.option(S$RescriptSchema.$$null($$BigInt.schema))),
|
|
171
|
+
chainId: s.f("chain_id", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
|
|
172
|
+
cumulativeGasUsed: s.f("cumulative_gas_used", S$RescriptSchema.option($$BigInt.schema)),
|
|
173
|
+
effectiveGasPrice: s.f("effective_gas_price", S$RescriptSchema.option($$BigInt.schema)),
|
|
174
|
+
gasUsed: s.f("gas_used", S$RescriptSchema.option($$BigInt.schema)),
|
|
175
|
+
contractAddress: s.f("contract_address", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
176
|
+
logsBoom: s.f("logs_bloom", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
177
|
+
type_: s.f("type", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
|
|
178
|
+
root: s.f("root", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string))),
|
|
179
|
+
status: s.f("status", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.$$int))),
|
|
180
|
+
sighash: s.f("sighash", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.string)))
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
var logDataSchema = S$RescriptSchema.object(function (s) {
|
|
185
|
+
return {
|
|
186
|
+
removed: s.f("removed", S$RescriptSchema.option(S$RescriptSchema.$$null(S$RescriptSchema.bool))),
|
|
187
|
+
index: s.f("log_index", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
188
|
+
transactionIndex: s.f("transaction_index", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
189
|
+
transactionHash: s.f("transaction_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
190
|
+
blockHash: s.f("block_hash", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
191
|
+
blockNumber: s.f("block_number", S$RescriptSchema.option(S$RescriptSchema.$$int)),
|
|
192
|
+
address: s.f("address", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
193
|
+
data: s.f("data", S$RescriptSchema.option(S$RescriptSchema.string)),
|
|
194
|
+
topic0: s.f("topic0", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema))),
|
|
195
|
+
topic1: s.f("topic1", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema))),
|
|
196
|
+
topic2: s.f("topic2", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema))),
|
|
197
|
+
topic3: s.f("topic3", S$RescriptSchema.option(S$RescriptSchema.$$null(EvmTypes.Hex.schema)))
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
var dataSchema = S$RescriptSchema.object(function (s) {
|
|
202
|
+
return {
|
|
203
|
+
blocks: s.f("blocks", S$RescriptSchema.option(S$RescriptSchema.array(blockDataSchema))),
|
|
204
|
+
transactions: s.f("transactions", S$RescriptSchema.option(S$RescriptSchema.array(transactionDataSchema))),
|
|
205
|
+
logs: s.f("logs", S$RescriptSchema.option(S$RescriptSchema.array(logDataSchema)))
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
var queryResponseSchema = S$RescriptSchema.object(function (s) {
|
|
210
|
+
return {
|
|
211
|
+
data: s.f("data", S$RescriptSchema.array(dataSchema)),
|
|
212
|
+
archiveHeight: s.f("archive_height", S$RescriptSchema.$$int),
|
|
213
|
+
nextBlock: s.f("next_block", S$RescriptSchema.$$int),
|
|
214
|
+
totalTime: s.f("total_execution_time", S$RescriptSchema.$$int)
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
var ResponseTypes = {
|
|
219
|
+
blockDataSchema: blockDataSchema,
|
|
220
|
+
transactionDataSchema: transactionDataSchema,
|
|
221
|
+
logDataSchema: logDataSchema,
|
|
222
|
+
dataSchema: dataSchema,
|
|
223
|
+
queryResponseSchema: queryResponseSchema
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
function queryRoute() {
|
|
227
|
+
return {
|
|
228
|
+
method: "POST",
|
|
229
|
+
path: "/query",
|
|
230
|
+
input: (function (s) {
|
|
231
|
+
return {
|
|
232
|
+
query: s.body(postQueryBodySchema),
|
|
233
|
+
token: s.auth("Bearer")
|
|
234
|
+
};
|
|
235
|
+
}),
|
|
236
|
+
responses: [(function (s) {
|
|
237
|
+
return s.data(queryResponseSchema);
|
|
238
|
+
})]
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function heightRoute() {
|
|
243
|
+
return {
|
|
244
|
+
method: "GET",
|
|
245
|
+
path: "/height",
|
|
246
|
+
input: (function (s) {
|
|
247
|
+
return s.auth("Bearer");
|
|
248
|
+
}),
|
|
249
|
+
responses: [(function (s) {
|
|
250
|
+
return s.field("height", S$RescriptSchema.$$int);
|
|
251
|
+
})]
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
exports.QueryTypes = QueryTypes;
|
|
256
|
+
exports.ResponseTypes = ResponseTypes;
|
|
257
|
+
exports.queryRoute = queryRoute;
|
|
258
|
+
exports.heightRoute = heightRoute;
|
|
259
|
+
/* blockFieldOptionsSchema Not a pure module */
|