envio 2.29.0-alpha.0 → 2.29.0-alpha.2
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/index.d.ts +3 -0
- package/package.json +5 -5
- package/src/Batch.res +4 -14
- package/src/Batch.res.js +3 -14
- package/src/Envio.gen.ts +14 -0
- package/src/Envio.res +18 -0
- package/src/EventRegister.res +173 -31
- package/src/EventRegister.res.js +138 -33
- package/src/EventRegister.resi +11 -0
- package/src/EventUtils.res +52 -58
- package/src/EventUtils.res.js +15 -51
- package/src/FetchState.res +90 -57
- package/src/FetchState.res.js +84 -56
- package/src/Internal.gen.ts +2 -0
- package/src/Internal.res +47 -3
- package/src/InternalConfig.res +18 -0
- package/src/Logging.res +36 -24
- package/src/Logging.res.js +35 -21
- package/src/sources/HyperFuelSource.res +506 -0
- package/src/sources/HyperFuelSource.res.js +451 -0
- package/src/sources/HyperSync.res +1 -1
- package/src/sources/HyperSync.resi +1 -1
- package/src/sources/HyperSyncSource.res +569 -0
- package/src/sources/HyperSyncSource.res.js +413 -0
- package/src/sources/RpcSource.res +18 -20
- package/src/sources/RpcSource.res.js +1 -0
- package/src/sources/Source.res +1 -1
package/src/FetchState.res.js
CHANGED
|
@@ -5,10 +5,12 @@ var Caml = require("rescript/lib/js/caml.js");
|
|
|
5
5
|
var Utils = require("./Utils.res.js");
|
|
6
6
|
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
7
7
|
var Js_dict = require("rescript/lib/js/js_dict.js");
|
|
8
|
+
var Js_math = require("rescript/lib/js/js_math.js");
|
|
8
9
|
var Logging = require("./Logging.res.js");
|
|
9
10
|
var Belt_Int = require("rescript/lib/js/belt_Int.js");
|
|
10
11
|
var Caml_obj = require("rescript/lib/js/caml_obj.js");
|
|
11
12
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
13
|
+
var Caml_int32 = require("rescript/lib/js/caml_int32.js");
|
|
12
14
|
var Prometheus = require("./Prometheus.res.js");
|
|
13
15
|
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
14
16
|
var Belt_Result = require("rescript/lib/js/belt_Result.js");
|
|
@@ -20,9 +22,9 @@ function copy(fetchState) {
|
|
|
20
22
|
partitions: fetchState.partitions,
|
|
21
23
|
nextPartitionIndex: fetchState.nextPartitionIndex,
|
|
22
24
|
isFetchingAtHead: fetchState.isFetchingAtHead,
|
|
25
|
+
startBlock: fetchState.startBlock,
|
|
23
26
|
endBlock: fetchState.endBlock,
|
|
24
27
|
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
25
|
-
firstEventBlockNumber: fetchState.firstEventBlockNumber,
|
|
26
28
|
normalSelection: fetchState.normalSelection,
|
|
27
29
|
indexingContracts: fetchState.indexingContracts,
|
|
28
30
|
contractConfigs: fetchState.contractConfigs,
|
|
@@ -30,7 +32,8 @@ function copy(fetchState) {
|
|
|
30
32
|
chainId: fetchState.chainId,
|
|
31
33
|
latestFullyFetchedBlock: fetchState.latestFullyFetchedBlock,
|
|
32
34
|
blockLag: fetchState.blockLag,
|
|
33
|
-
queue: fetchState.queue.slice(0)
|
|
35
|
+
queue: fetchState.queue.slice(0),
|
|
36
|
+
onBlockConfigs: fetchState.onBlockConfigs
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -137,14 +140,13 @@ function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexi
|
|
|
137
140
|
Prometheus.IndexingPartitions.set(partitions.length, fetchState.chainId);
|
|
138
141
|
Prometheus.IndexingBufferSize.set(bufferSize, fetchState.chainId);
|
|
139
142
|
Prometheus.IndexingBufferBlockNumber.set(latestFullyFetchedBlock$1.blockNumber, fetchState.chainId);
|
|
140
|
-
var item = Utils.$$Array.last(queue);
|
|
141
143
|
return {
|
|
142
144
|
partitions: partitions,
|
|
143
145
|
nextPartitionIndex: nextPartitionIndex,
|
|
144
146
|
isFetchingAtHead: isFetchingAtHead,
|
|
147
|
+
startBlock: fetchState.startBlock,
|
|
145
148
|
endBlock: fetchState.endBlock,
|
|
146
149
|
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
147
|
-
firstEventBlockNumber: item !== undefined ? Utils.$$Math.minOptInt(fetchState.firstEventBlockNumber, item.blockNumber) : fetchState.firstEventBlockNumber,
|
|
148
150
|
normalSelection: fetchState.normalSelection,
|
|
149
151
|
indexingContracts: indexingContracts,
|
|
150
152
|
contractConfigs: fetchState.contractConfigs,
|
|
@@ -152,7 +154,8 @@ function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexi
|
|
|
152
154
|
chainId: fetchState.chainId,
|
|
153
155
|
latestFullyFetchedBlock: latestFullyFetchedBlock$1,
|
|
154
156
|
blockLag: blockLag,
|
|
155
|
-
queue: queue
|
|
157
|
+
queue: queue,
|
|
158
|
+
onBlockConfigs: fetchState.onBlockConfigs
|
|
156
159
|
};
|
|
157
160
|
}
|
|
158
161
|
|
|
@@ -409,7 +412,46 @@ function handleQueryResult(fetchState, query, latestFetchedBlock, newItems, curr
|
|
|
409
412
|
};
|
|
410
413
|
}
|
|
411
414
|
return Belt_Result.map(tmp, (function (partitions) {
|
|
412
|
-
|
|
415
|
+
var newQueue = Belt_Array.concat(fetchState.queue, newItems);
|
|
416
|
+
var onBlockConfigs = fetchState.onBlockConfigs;
|
|
417
|
+
if (onBlockConfigs !== undefined) {
|
|
418
|
+
var prevLatestFetchedBlockNumber = fetchState.latestFullyFetchedBlock.blockNumber;
|
|
419
|
+
var nextLatestFullyFetchedBlockNumber = latestFetchedBlock.blockNumber;
|
|
420
|
+
for(var idx = 0 ,idx_finish = partitions.length; idx < idx_finish; ++idx){
|
|
421
|
+
var p = partitions[idx];
|
|
422
|
+
if (nextLatestFullyFetchedBlockNumber > p.latestFetchedBlock.blockNumber) {
|
|
423
|
+
nextLatestFullyFetchedBlockNumber = p.latestFetchedBlock.blockNumber;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
}
|
|
427
|
+
var nextLatestFullyFetchedBlockNumber$1 = nextLatestFullyFetchedBlockNumber;
|
|
428
|
+
if (nextLatestFullyFetchedBlockNumber$1 > prevLatestFetchedBlockNumber) {
|
|
429
|
+
for(var configIdx = 0 ,configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx){
|
|
430
|
+
var onBlockConfig = onBlockConfigs[configIdx];
|
|
431
|
+
var startBlock = onBlockConfig.startBlock;
|
|
432
|
+
var handlerStartBlock = startBlock !== undefined ? startBlock : fetchState.startBlock;
|
|
433
|
+
var rangeStart = Caml.int_max(handlerStartBlock, prevLatestFetchedBlockNumber + 1 | 0);
|
|
434
|
+
var endBlock = onBlockConfig.endBlock;
|
|
435
|
+
var rangeEnd = endBlock !== undefined && endBlock < nextLatestFullyFetchedBlockNumber$1 ? endBlock : nextLatestFullyFetchedBlockNumber$1;
|
|
436
|
+
if (rangeStart <= rangeEnd) {
|
|
437
|
+
for(var blockNumber = rangeStart; blockNumber <= rangeEnd; ++blockNumber){
|
|
438
|
+
if (Caml_int32.mod_(blockNumber - handlerStartBlock | 0, onBlockConfig.interval) === 0) {
|
|
439
|
+
newQueue.push({
|
|
440
|
+
kind: 1,
|
|
441
|
+
onBlockConfig: onBlockConfig,
|
|
442
|
+
blockNumber: blockNumber,
|
|
443
|
+
logIndex: 16777216
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
}
|
|
454
|
+
return updateInternal(fetchState, partitions, undefined, undefined, undefined, currentBlockHeight, newQueue.sort(compareBufferItem), undefined);
|
|
413
455
|
}));
|
|
414
456
|
}
|
|
415
457
|
|
|
@@ -632,18 +674,6 @@ function getNextQuery(param, concurrencyLimit, targetBufferSize, currentBlockHei
|
|
|
632
674
|
}
|
|
633
675
|
}
|
|
634
676
|
|
|
635
|
-
function queueItemBlockNumber(queueItem) {
|
|
636
|
-
if (queueItem.TAG === "Item") {
|
|
637
|
-
return queueItem._0.item.blockNumber;
|
|
638
|
-
}
|
|
639
|
-
var blockNumber = queueItem.latestFetchedBlock.blockNumber;
|
|
640
|
-
if (blockNumber === 0) {
|
|
641
|
-
return 0;
|
|
642
|
-
} else {
|
|
643
|
-
return blockNumber + 1 | 0;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
677
|
function makeNoItem(param) {
|
|
648
678
|
return {
|
|
649
679
|
TAG: "NoItem",
|
|
@@ -651,28 +681,6 @@ function makeNoItem(param) {
|
|
|
651
681
|
};
|
|
652
682
|
}
|
|
653
683
|
|
|
654
|
-
function qItemLt(a, b) {
|
|
655
|
-
var aBlockNumber = queueItemBlockNumber(a);
|
|
656
|
-
var bBlockNumber = queueItemBlockNumber(b);
|
|
657
|
-
if (aBlockNumber < bBlockNumber) {
|
|
658
|
-
return true;
|
|
659
|
-
} else if (aBlockNumber === bBlockNumber) {
|
|
660
|
-
if (a.TAG === "Item") {
|
|
661
|
-
if (b.TAG === "Item") {
|
|
662
|
-
return a._0.item.logIndex < b._0.item.logIndex;
|
|
663
|
-
} else {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
} else if (b.TAG === "Item") {
|
|
667
|
-
return true;
|
|
668
|
-
} else {
|
|
669
|
-
return false;
|
|
670
|
-
}
|
|
671
|
-
} else {
|
|
672
|
-
return false;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
684
|
function getEarliestEvent(param) {
|
|
677
685
|
var queue = param.queue;
|
|
678
686
|
var latestFullyFetchedBlock = param.latestFullyFetchedBlock;
|
|
@@ -695,11 +703,11 @@ function getEarliestEvent(param) {
|
|
|
695
703
|
}
|
|
696
704
|
}
|
|
697
705
|
|
|
698
|
-
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId, blockLagOpt) {
|
|
706
|
+
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId, progressBlockNumberOpt, onBlockConfigs, blockLagOpt) {
|
|
707
|
+
var progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
|
|
699
708
|
var blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
|
|
700
|
-
var latestFetchedBlock_blockNumber = startBlock - 1 | 0;
|
|
701
709
|
var latestFetchedBlock = {
|
|
702
|
-
blockNumber:
|
|
710
|
+
blockNumber: progressBlockNumber,
|
|
703
711
|
blockTimestamp: 0
|
|
704
712
|
};
|
|
705
713
|
var notDependingOnAddresses = [];
|
|
@@ -786,7 +794,7 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
786
794
|
Prometheus.IndexingAddresses.set(numAddresses, chainId);
|
|
787
795
|
Prometheus.IndexingPartitions.set(partitions.length, chainId);
|
|
788
796
|
Prometheus.IndexingBufferSize.set(0, chainId);
|
|
789
|
-
Prometheus.IndexingBufferBlockNumber.set(
|
|
797
|
+
Prometheus.IndexingBufferBlockNumber.set(progressBlockNumber, chainId);
|
|
790
798
|
if (endBlock !== undefined) {
|
|
791
799
|
Prometheus.IndexingEndBlock.set(endBlock, chainId);
|
|
792
800
|
}
|
|
@@ -794,9 +802,9 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
794
802
|
partitions: partitions,
|
|
795
803
|
nextPartitionIndex: partitions.length,
|
|
796
804
|
isFetchingAtHead: false,
|
|
805
|
+
startBlock: startBlock,
|
|
797
806
|
endBlock: endBlock,
|
|
798
807
|
maxAddrInPartition: maxAddrInPartition,
|
|
799
|
-
firstEventBlockNumber: undefined,
|
|
800
808
|
normalSelection: normalSelection,
|
|
801
809
|
indexingContracts: indexingContracts,
|
|
802
810
|
contractConfigs: contractConfigs,
|
|
@@ -804,7 +812,8 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
804
812
|
chainId: chainId,
|
|
805
813
|
latestFullyFetchedBlock: latestFetchedBlock,
|
|
806
814
|
blockLag: blockLag,
|
|
807
|
-
queue: []
|
|
815
|
+
queue: [],
|
|
816
|
+
onBlockConfigs: onBlockConfigs
|
|
808
817
|
};
|
|
809
818
|
}
|
|
810
819
|
|
|
@@ -818,10 +827,15 @@ function getLatestFullyFetchedBlock(param) {
|
|
|
818
827
|
|
|
819
828
|
function pruneQueueFromFirstChangeEvent(queue, firstChangeEvent) {
|
|
820
829
|
return Belt_Array.keep(queue, (function (item) {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
830
|
+
var tmp;
|
|
831
|
+
tmp = item.kind === 0 ? [
|
|
832
|
+
item.blockNumber,
|
|
833
|
+
item.logIndex
|
|
834
|
+
] : [
|
|
835
|
+
item.blockNumber,
|
|
836
|
+
item.logIndex
|
|
837
|
+
];
|
|
838
|
+
return Caml_obj.lessthan(tmp, [
|
|
825
839
|
firstChangeEvent.blockNumber,
|
|
826
840
|
firstChangeEvent.logIndex
|
|
827
841
|
]);
|
|
@@ -956,7 +970,13 @@ function filterAndSortForUnorderedBatch(fetchStates, maxBatchSize) {
|
|
|
956
970
|
} else if (match$1) {
|
|
957
971
|
return 1;
|
|
958
972
|
}
|
|
959
|
-
|
|
973
|
+
var match$2 = Utils.$$Array.lastUnsafe(a.queue);
|
|
974
|
+
var match$3 = Utils.$$Array.lastUnsafe(b.queue);
|
|
975
|
+
if (match$2.kind === 0 && match$3.kind === 0) {
|
|
976
|
+
return match$2.timestamp - match$3.timestamp | 0;
|
|
977
|
+
} else {
|
|
978
|
+
return Js_math.random_int(-1, 1);
|
|
979
|
+
}
|
|
960
980
|
});
|
|
961
981
|
}
|
|
962
982
|
|
|
@@ -971,13 +991,22 @@ function getProgressBlockNumber(param) {
|
|
|
971
991
|
}
|
|
972
992
|
|
|
973
993
|
function getProgressNextBlockLogIndex(param) {
|
|
974
|
-
var
|
|
975
|
-
if (
|
|
976
|
-
return
|
|
994
|
+
var match = Utils.$$Array.last(param.queue);
|
|
995
|
+
if (match === undefined) {
|
|
996
|
+
return ;
|
|
997
|
+
}
|
|
998
|
+
if (match.kind !== 0) {
|
|
999
|
+
return ;
|
|
1000
|
+
}
|
|
1001
|
+
var logIndex = match.logIndex;
|
|
1002
|
+
if (param.latestFullyFetchedBlock.blockNumber >= match.blockNumber && logIndex > 0) {
|
|
1003
|
+
return logIndex - 1 | 0;
|
|
977
1004
|
}
|
|
978
1005
|
|
|
979
1006
|
}
|
|
980
1007
|
|
|
1008
|
+
var blockItemLogIndex = 16777216;
|
|
1009
|
+
|
|
981
1010
|
exports.copy = copy;
|
|
982
1011
|
exports.mergeIntoPartition = mergeIntoPartition;
|
|
983
1012
|
exports.checkIsWithinSyncRange = checkIsWithinSyncRange;
|
|
@@ -988,6 +1017,7 @@ exports.registerDynamicContracts = registerDynamicContracts;
|
|
|
988
1017
|
exports.UnexpectedPartitionNotFound = UnexpectedPartitionNotFound;
|
|
989
1018
|
exports.UnexpectedMergeQueryResponse = UnexpectedMergeQueryResponse;
|
|
990
1019
|
exports.compareBufferItem = compareBufferItem;
|
|
1020
|
+
exports.blockItemLogIndex = blockItemLogIndex;
|
|
991
1021
|
exports.handleQueryResult = handleQueryResult;
|
|
992
1022
|
exports.makePartitionQuery = makePartitionQuery;
|
|
993
1023
|
exports.startFetchingQueries = startFetchingQueries;
|
|
@@ -995,9 +1025,7 @@ exports.addressesByContractNameCount = addressesByContractNameCount;
|
|
|
995
1025
|
exports.addressesByContractNameGetAll = addressesByContractNameGetAll;
|
|
996
1026
|
exports.isFullPartition = isFullPartition;
|
|
997
1027
|
exports.getNextQuery = getNextQuery;
|
|
998
|
-
exports.queueItemBlockNumber = queueItemBlockNumber;
|
|
999
1028
|
exports.makeNoItem = makeNoItem;
|
|
1000
|
-
exports.qItemLt = qItemLt;
|
|
1001
1029
|
exports.getEarliestEvent = getEarliestEvent;
|
|
1002
1030
|
exports.make = make;
|
|
1003
1031
|
exports.bufferSize = bufferSize;
|
package/src/Internal.gen.ts
CHANGED
|
@@ -51,6 +51,8 @@ export type genericHandlerWithLoader<loader,handler,eventFilters> = {
|
|
|
51
51
|
readonly preRegisterDynamicContracts?: boolean
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
export type blockEvent = { readonly number: number; readonly chainId: number };
|
|
55
|
+
|
|
54
56
|
export type eventOptions<eventFilters> = {
|
|
55
57
|
readonly wildcard?: boolean;
|
|
56
58
|
readonly eventFilters?: eventFilters;
|
package/src/Internal.res
CHANGED
|
@@ -133,17 +133,61 @@ type evmContractConfig = {
|
|
|
133
133
|
events: array<evmEventConfig>,
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
type
|
|
136
|
+
// Duplicate the type from item
|
|
137
|
+
// to make item properly unboxed
|
|
138
|
+
type eventItem = private {
|
|
139
|
+
kind: [#0],
|
|
137
140
|
eventConfig: eventConfig,
|
|
138
141
|
timestamp: int,
|
|
139
142
|
chain: ChainMap.Chain.t,
|
|
140
143
|
blockNumber: int,
|
|
141
144
|
logIndex: int,
|
|
142
145
|
event: event,
|
|
143
|
-
// Reuse logger object for event
|
|
144
|
-
mutable loggerCache?: Pino.t,
|
|
145
146
|
}
|
|
146
147
|
|
|
148
|
+
@genType
|
|
149
|
+
type blockEvent = {
|
|
150
|
+
number: int,
|
|
151
|
+
chainId: int,
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type onBlockArgs = {
|
|
155
|
+
block: blockEvent,
|
|
156
|
+
context: handlerContext,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type onBlockConfig = {
|
|
160
|
+
// When there are multiple onBlock handlers per chain,
|
|
161
|
+
// we want to use the order they are defined for sorting
|
|
162
|
+
index: int,
|
|
163
|
+
name: string,
|
|
164
|
+
chainId: int,
|
|
165
|
+
startBlock: option<int>,
|
|
166
|
+
endBlock: option<int>,
|
|
167
|
+
interval: int,
|
|
168
|
+
handler: onBlockArgs => promise<unit>,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@tag("kind")
|
|
172
|
+
type item =
|
|
173
|
+
| @as(0)
|
|
174
|
+
Event({
|
|
175
|
+
eventConfig: eventConfig,
|
|
176
|
+
timestamp: int,
|
|
177
|
+
chain: ChainMap.Chain.t,
|
|
178
|
+
blockNumber: int,
|
|
179
|
+
logIndex: int,
|
|
180
|
+
event: event,
|
|
181
|
+
})
|
|
182
|
+
| @as(1) Block({onBlockConfig: onBlockConfig, blockNumber: int, logIndex: int})
|
|
183
|
+
|
|
184
|
+
external castUnsafeEventItem: item => eventItem = "%identity"
|
|
185
|
+
|
|
186
|
+
@get
|
|
187
|
+
external getItemBlockNumber: item => int = "blockNumber"
|
|
188
|
+
@get
|
|
189
|
+
external getItemLogIndex: item => int = "logIndex"
|
|
190
|
+
|
|
147
191
|
@genType
|
|
148
192
|
type eventOptions<'eventFilters> = {
|
|
149
193
|
wildcard?: bool,
|
package/src/InternalConfig.res
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
// And turn it into PublicConfig instead
|
|
3
3
|
// For internal use we should create Indexer.res with a stateful type
|
|
4
4
|
|
|
5
|
+
type ecosystem = | @as("evm") Evm | @as("fuel") Fuel
|
|
6
|
+
|
|
7
|
+
type sourceSyncOptions = {
|
|
8
|
+
initialBlockInterval?: int,
|
|
9
|
+
backoffMultiplicative?: float,
|
|
10
|
+
accelerationAdditive?: int,
|
|
11
|
+
intervalCeiling?: int,
|
|
12
|
+
backoffMillis?: int,
|
|
13
|
+
queryTimeoutMillis?: int,
|
|
14
|
+
fallbackStallTimeout?: int,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type historyFlag = FullHistory | MinHistory
|
|
18
|
+
type rollbackFlag = RollbackOnReorg | NoRollback
|
|
19
|
+
type historyConfig = {rollbackFlag: rollbackFlag, historyFlag: historyFlag}
|
|
20
|
+
|
|
5
21
|
type contract = {
|
|
6
22
|
name: string,
|
|
7
23
|
abi: EvmTypes.Abi.t,
|
|
@@ -28,3 +44,5 @@ type sourceSync = {
|
|
|
28
44
|
queryTimeoutMillis: int,
|
|
29
45
|
fallbackStallTimeout: int,
|
|
30
46
|
}
|
|
47
|
+
|
|
48
|
+
type multichain = | @as("ordered") Ordered | @as("unordered") Unordered
|
package/src/Logging.res
CHANGED
|
@@ -144,29 +144,41 @@ let createChildFrom = (~logger: t, ~params: 'a) => {
|
|
|
144
144
|
logger->child(params->createChildParams)
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
let
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
147
|
+
let getItemLogger = {
|
|
148
|
+
let cacheKey = "_logger"
|
|
149
|
+
(item: Internal.item) => {
|
|
150
|
+
switch item->Utils.magic->Utils.Dict.dangerouslyGetNonOption(cacheKey) {
|
|
151
|
+
| Some(l) => l
|
|
152
|
+
| None => {
|
|
153
|
+
let l = getLogger()->child(
|
|
154
|
+
switch item {
|
|
155
|
+
| Event({eventConfig, chain, blockNumber, logIndex, event}) =>
|
|
156
|
+
{
|
|
157
|
+
"contractName": eventConfig.contractName,
|
|
158
|
+
"eventName": eventConfig.name,
|
|
159
|
+
"chainId": chain->ChainMap.Chain.toChainId,
|
|
160
|
+
"block": blockNumber,
|
|
161
|
+
"logIndex": logIndex,
|
|
162
|
+
"address": event.srcAddress,
|
|
163
|
+
}->createChildParams
|
|
164
|
+
| Block({blockNumber, onBlockConfig}) =>
|
|
165
|
+
{
|
|
166
|
+
"onBlock": onBlockConfig.name,
|
|
167
|
+
"chainId": onBlockConfig.chainId,
|
|
168
|
+
"block": blockNumber,
|
|
169
|
+
}->createChildParams
|
|
170
|
+
},
|
|
171
|
+
)
|
|
172
|
+
item->Utils.magic->Js.Dict.set(cacheKey, l)
|
|
173
|
+
l
|
|
174
|
+
}
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
177
|
}
|
|
166
178
|
|
|
167
179
|
@inline
|
|
168
|
-
let logForItem = (
|
|
169
|
-
(
|
|
180
|
+
let logForItem = (item, level: Pino.logLevel, message: string, ~params=?) => {
|
|
181
|
+
(item->getItemLogger->Utils.magic->Js.Dict.unsafeGet((level :> string)))(params, message)
|
|
170
182
|
}
|
|
171
183
|
|
|
172
184
|
let noopLogger: Envio.logger = {
|
|
@@ -177,11 +189,11 @@ let noopLogger: Envio.logger = {
|
|
|
177
189
|
errorWithExn: (_message: string, _exn) => (),
|
|
178
190
|
}
|
|
179
191
|
|
|
180
|
-
let getUserLogger = (
|
|
181
|
-
info: (message: string, ~params=?) =>
|
|
182
|
-
debug: (message: string, ~params=?) =>
|
|
183
|
-
warn: (message: string, ~params=?) =>
|
|
184
|
-
error: (message: string, ~params=?) =>
|
|
192
|
+
let getUserLogger = (item): Envio.logger => {
|
|
193
|
+
info: (message: string, ~params=?) => item->logForItem(#uinfo, message, ~params?),
|
|
194
|
+
debug: (message: string, ~params=?) => item->logForItem(#udebug, message, ~params?),
|
|
195
|
+
warn: (message: string, ~params=?) => item->logForItem(#uwarn, message, ~params?),
|
|
196
|
+
error: (message: string, ~params=?) => item->logForItem(#uerror, message, ~params?),
|
|
185
197
|
errorWithExn: (message: string, exn) =>
|
|
186
|
-
|
|
198
|
+
item->logForItem(#uerror, message, ~params={"err": exn->Utils.prettifyExn}),
|
|
187
199
|
}
|
package/src/Logging.res.js
CHANGED
|
@@ -177,25 +177,39 @@ function createChildFrom(logger, params) {
|
|
|
177
177
|
return logger.child(Pino.createChildParams(params));
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
var cacheKey = "_logger";
|
|
181
|
+
|
|
182
|
+
function getItemLogger(item) {
|
|
183
|
+
var l = item[cacheKey];
|
|
182
184
|
if (l !== undefined) {
|
|
183
|
-
return l;
|
|
185
|
+
return Caml_option.valFromOption(l);
|
|
184
186
|
}
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
var tmp;
|
|
188
|
+
if (item.kind === 0) {
|
|
189
|
+
var eventConfig = item.eventConfig;
|
|
190
|
+
tmp = Pino.createChildParams({
|
|
191
|
+
contractName: eventConfig.contractName,
|
|
192
|
+
eventName: eventConfig.name,
|
|
193
|
+
chainId: item.chain,
|
|
194
|
+
block: item.blockNumber,
|
|
195
|
+
logIndex: item.logIndex,
|
|
196
|
+
address: item.event.srcAddress
|
|
197
|
+
});
|
|
198
|
+
} else {
|
|
199
|
+
var onBlockConfig = item.onBlockConfig;
|
|
200
|
+
tmp = Pino.createChildParams({
|
|
201
|
+
onBlock: onBlockConfig.name,
|
|
202
|
+
chainId: onBlockConfig.chainId,
|
|
203
|
+
block: item.blockNumber
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
var l$1 = getLogger().child(tmp);
|
|
207
|
+
item[cacheKey] = l$1;
|
|
194
208
|
return l$1;
|
|
195
209
|
}
|
|
196
210
|
|
|
197
|
-
function logForItem(
|
|
198
|
-
return
|
|
211
|
+
function logForItem(item, level, message, params) {
|
|
212
|
+
return getItemLogger(item)[level](params, message);
|
|
199
213
|
}
|
|
200
214
|
|
|
201
215
|
function noopLogger_debug(_message, param) {
|
|
@@ -226,25 +240,25 @@ var noopLogger = {
|
|
|
226
240
|
errorWithExn: noopLogger_errorWithExn
|
|
227
241
|
};
|
|
228
242
|
|
|
229
|
-
function getUserLogger(
|
|
243
|
+
function getUserLogger(item) {
|
|
230
244
|
return {
|
|
231
245
|
debug: (function (message, params) {
|
|
232
|
-
|
|
246
|
+
getItemLogger(item)["udebug"](params, message);
|
|
233
247
|
}),
|
|
234
248
|
info: (function (message, params) {
|
|
235
|
-
|
|
249
|
+
getItemLogger(item)["uinfo"](params, message);
|
|
236
250
|
}),
|
|
237
251
|
warn: (function (message, params) {
|
|
238
|
-
|
|
252
|
+
getItemLogger(item)["uwarn"](params, message);
|
|
239
253
|
}),
|
|
240
254
|
error: (function (message, params) {
|
|
241
|
-
|
|
255
|
+
getItemLogger(item)["uerror"](params, message);
|
|
242
256
|
}),
|
|
243
257
|
errorWithExn: (function (message, exn) {
|
|
244
258
|
var params = {
|
|
245
259
|
err: Utils.prettifyExn(exn)
|
|
246
260
|
};
|
|
247
|
-
|
|
261
|
+
getItemLogger(item)["uerror"](params, message);
|
|
248
262
|
})
|
|
249
263
|
};
|
|
250
264
|
}
|
|
@@ -270,7 +284,7 @@ exports.childErrorWithExn = childErrorWithExn;
|
|
|
270
284
|
exports.childFatal = childFatal;
|
|
271
285
|
exports.createChild = createChild;
|
|
272
286
|
exports.createChildFrom = createChildFrom;
|
|
273
|
-
exports.
|
|
287
|
+
exports.getItemLogger = getItemLogger;
|
|
274
288
|
exports.logForItem = logForItem;
|
|
275
289
|
exports.noopLogger = noopLogger;
|
|
276
290
|
exports.getUserLogger = getUserLogger;
|