envio 2.11.7 → 2.11.9
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 +5 -5
- package/src/ReorgDetection.res +32 -24
- package/src/Utils.res +41 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "v2.11.
|
|
3
|
+
"version": "v2.11.9",
|
|
4
4
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
5
5
|
"bin": "./bin.js",
|
|
6
6
|
"repository": {
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://envio.dev",
|
|
25
25
|
"optionalDependencies": {
|
|
26
|
-
"envio-linux-x64": "v2.11.
|
|
27
|
-
"envio-linux-arm64": "v2.11.
|
|
28
|
-
"envio-darwin-x64": "v2.11.
|
|
29
|
-
"envio-darwin-arm64": "v2.11.
|
|
26
|
+
"envio-linux-x64": "v2.11.9",
|
|
27
|
+
"envio-linux-arm64": "v2.11.9",
|
|
28
|
+
"envio-darwin-x64": "v2.11.9",
|
|
29
|
+
"envio-darwin-arm64": "v2.11.9"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@envio-dev/hypersync-client": "0.6.3",
|
package/src/ReorgDetection.res
CHANGED
|
@@ -11,6 +11,11 @@ type blockData = {
|
|
|
11
11
|
blockTimestamp: int,
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
type reorgGuard = {
|
|
15
|
+
lastBlockScannedData: blockData,
|
|
16
|
+
firstBlockParentNumberAndHash: option<blockNumberAndHash>,
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
module LastBlockScannedHashes: {
|
|
15
20
|
type t
|
|
16
21
|
/**Instantiat t with existing data*/
|
|
@@ -69,7 +74,7 @@ module LastBlockScannedHashes: {
|
|
|
69
74
|
|
|
70
75
|
let getAllBlockNumbers: t => Belt.Array.t<int>
|
|
71
76
|
|
|
72
|
-
let hasReorgOccurred: (t, ~
|
|
77
|
+
let hasReorgOccurred: (t, ~reorgGuard: reorgGuard) => bool
|
|
73
78
|
|
|
74
79
|
/**
|
|
75
80
|
Return a BlockNumbersAndHashes.t rolled back to where blockData is less
|
|
@@ -402,31 +407,34 @@ module LastBlockScannedHashes: {
|
|
|
402
407
|
/**
|
|
403
408
|
Checks whether reorg has occured by comparing the parent hash with the last saved block hash.
|
|
404
409
|
*/
|
|
405
|
-
let rec hasReorgOccurredInternal = (
|
|
406
|
-
lastBlockScannedDataList
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
parentHash != head.blockHash
|
|
413
|
-
} else {
|
|
414
|
-
//if block numbers do not match, this is a dynamic contract case and should recurse
|
|
415
|
-
//through the list to look for a matching block or nothing to validate
|
|
416
|
-
tail->hasReorgOccurredInternal(~firstBlockParentNumberAndHash)
|
|
417
|
-
}
|
|
418
|
-
| _ => //If parentHash is None, either it's the genesis block (no reorg)
|
|
410
|
+
let rec hasReorgOccurredInternal = (lastBlockScannedDataList, ~reorgGuard: reorgGuard) => {
|
|
411
|
+
switch lastBlockScannedDataList {
|
|
412
|
+
| list{head, ...tail} =>
|
|
413
|
+
switch reorgGuard {
|
|
414
|
+
| {lastBlockScannedData} if lastBlockScannedData.blockNumber == head.blockNumber =>
|
|
415
|
+
lastBlockScannedData.blockHash != head.blockHash
|
|
416
|
+
//If parentHash is None, either it's the genesis block (no reorg)
|
|
419
417
|
//Or its already confirmed so no Reorg
|
|
420
|
-
|
|
421
|
-
|
|
418
|
+
| {firstBlockParentNumberAndHash: None} => false
|
|
419
|
+
| {
|
|
420
|
+
firstBlockParentNumberAndHash: Some({
|
|
421
|
+
blockHash: parentHash,
|
|
422
|
+
blockNumber: parentBlockNumber,
|
|
423
|
+
}),
|
|
424
|
+
} =>
|
|
425
|
+
if parentBlockNumber == head.blockNumber {
|
|
426
|
+
parentHash != head.blockHash
|
|
427
|
+
} else {
|
|
428
|
+
//if block numbers do not match, this is a dynamic contract case and should recurse
|
|
429
|
+
//through the list to look for a matching block or nothing to validate
|
|
430
|
+
tail->hasReorgOccurredInternal(~reorgGuard)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
//If recentLastBlockData is None, we have not yet saved blockData to compare against
|
|
434
|
+
| _ => false
|
|
422
435
|
}
|
|
423
436
|
}
|
|
424
437
|
|
|
425
|
-
let hasReorgOccurred = (
|
|
426
|
-
lastBlockScannedHashes
|
|
427
|
-
~firstBlockParentNumberAndHash: option<blockNumberAndHash>,
|
|
428
|
-
) =>
|
|
429
|
-
lastBlockScannedHashes.lastBlockScannedDataList->hasReorgOccurredInternal(
|
|
430
|
-
~firstBlockParentNumberAndHash,
|
|
431
|
-
)
|
|
438
|
+
let hasReorgOccurred = (lastBlockScannedHashes: t, ~reorgGuard: reorgGuard) =>
|
|
439
|
+
lastBlockScannedHashes.lastBlockScannedDataList->hasReorgOccurredInternal(~reorgGuard)
|
|
432
440
|
}
|
package/src/Utils.res
CHANGED
|
@@ -52,11 +52,35 @@ module Dict = {
|
|
|
52
52
|
|
|
53
53
|
let merge: (dict<'a>, dict<'a>) => dict<'a> = %raw(`(dictA, dictB) => ({...dictA, ...dictB})`)
|
|
54
54
|
|
|
55
|
+
let map = (dict, fn) => {
|
|
56
|
+
let newDict = Js.Dict.empty()
|
|
57
|
+
let keys = dict->Js.Dict.keys
|
|
58
|
+
for idx in 0 to keys->Js.Array2.length - 1 {
|
|
59
|
+
let key = keys->Js.Array2.unsafe_get(idx)
|
|
60
|
+
newDict->Js.Dict.set(key, fn(dict->Js.Dict.unsafeGet(key)))
|
|
61
|
+
}
|
|
62
|
+
newDict
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let forEach = (dict, fn) => {
|
|
66
|
+
let keys = dict->Js.Dict.keys
|
|
67
|
+
for idx in 0 to keys->Js.Array2.length - 1 {
|
|
68
|
+
fn(dict->Js.Dict.unsafeGet(keys->Js.Array2.unsafe_get(idx)))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let deleteInPlace: (dict<'a>, string) => unit = %raw(`(dict, key) => {
|
|
73
|
+
delete dict[key];
|
|
74
|
+
}
|
|
75
|
+
`)
|
|
76
|
+
|
|
55
77
|
let updateImmutable: (
|
|
56
78
|
dict<'a>,
|
|
57
79
|
string,
|
|
58
80
|
'a,
|
|
59
81
|
) => dict<'a> = %raw(`(dict, key, value) => ({...dict, [key]: value})`)
|
|
82
|
+
|
|
83
|
+
let shallowCopy: dict<'a> => dict<'a> = %raw(`(dict) => ({...dict})`)
|
|
60
84
|
}
|
|
61
85
|
|
|
62
86
|
module Math = {
|
|
@@ -156,12 +180,12 @@ Helper to check if a value exists in an array
|
|
|
156
180
|
Index > array length or < 0 results in a copy of the array
|
|
157
181
|
*/
|
|
158
182
|
let removeAtIndex = (array, index) => {
|
|
159
|
-
if index < 0
|
|
183
|
+
if index < 0 {
|
|
160
184
|
array->Array.copy
|
|
161
185
|
} else {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
186
|
+
array
|
|
187
|
+
->Js.Array2.slice(~start=0, ~end_=index)
|
|
188
|
+
->Js.Array2.concat(array->Js.Array2.sliceFrom(index + 1))
|
|
165
189
|
}
|
|
166
190
|
}
|
|
167
191
|
|
|
@@ -205,6 +229,9 @@ Helper to check if a value exists in an array
|
|
|
205
229
|
})
|
|
206
230
|
interleaved
|
|
207
231
|
}
|
|
232
|
+
|
|
233
|
+
@send
|
|
234
|
+
external flatten: (array<array<'a>>, @as(1) _) => array<'a> = "flat"
|
|
208
235
|
}
|
|
209
236
|
|
|
210
237
|
module String = {
|
|
@@ -214,6 +241,16 @@ module String = {
|
|
|
214
241
|
}
|
|
215
242
|
}
|
|
216
243
|
|
|
244
|
+
module Result = {
|
|
245
|
+
let forEach = (result, fn) => {
|
|
246
|
+
switch result {
|
|
247
|
+
| Ok(v) => fn(v)
|
|
248
|
+
| Error(_) => ()
|
|
249
|
+
}
|
|
250
|
+
result
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
217
254
|
/**
|
|
218
255
|
Useful when an unsafe unwrap is needed on Result type
|
|
219
256
|
and Error holds an exn. This is better than Result.getExn
|