univo 0.2.6 → 0.2.8
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/dist/cli.mjs +1 -1
- package/dist/index.mjs +43 -36
- package/dist/realtime.mjs +10 -14
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/shared/{univo.CTWk2lBv.mjs → univo.Br975GsZ.mjs} +1 -1
- package/dist/transport.mjs +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { config } from 'dotenv';
|
|
|
5
5
|
import { WebSocket } from 'partysocket';
|
|
6
6
|
import { defineCommand, runMain } from 'citty';
|
|
7
7
|
import { http } from './transport.mjs';
|
|
8
|
-
import { c as createLogger, v as version, g as name } from './shared/univo.
|
|
8
|
+
import { c as createLogger, v as version, g as name } from './shared/univo.Br975GsZ.mjs';
|
|
9
9
|
import './shared/univo.C0flyVee.mjs';
|
|
10
10
|
|
|
11
11
|
const log = createLogger({ quiet: false });
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as createLogger, d as decompress, a as decoder, h as hexToNumber, i as isHexEqual, r as retry, v as version, n as nonNullable, b as normalizeHex } from './shared/univo.
|
|
1
|
+
import { c as createLogger, d as decompress, a as decoder, h as hexToNumber, i as isHexEqual, r as retry, v as version, n as nonNullable, b as normalizeHex } from './shared/univo.Br975GsZ.mjs';
|
|
2
2
|
import { c as createException, g as getException, a as catchException } from './shared/univo.C0flyVee.mjs';
|
|
3
3
|
|
|
4
4
|
function matchFilter(block, filter) {
|
|
@@ -130,11 +130,21 @@ function indexer(opts) {
|
|
|
130
130
|
return block;
|
|
131
131
|
}
|
|
132
132
|
const public_getFinalizedHeight = async (chain) => {
|
|
133
|
-
const [stored] = await
|
|
133
|
+
const [[stored], finalizedBlock] = await Promise.all([
|
|
134
|
+
metadata.blocks.list({ chain }),
|
|
135
|
+
//
|
|
136
|
+
getBlock({ chain, number: "finalized" })
|
|
137
|
+
]);
|
|
138
|
+
if (finalizedBlock === null) {
|
|
139
|
+
log.debug("Failed to fetch finalized block and unable to determine finalized height, aborting...");
|
|
140
|
+
throw new Error(GetBlockError);
|
|
141
|
+
}
|
|
142
|
+
const finalizedHeight = hexToNumber(finalizedBlock.eth_getBlockByNumber.number);
|
|
134
143
|
if (stored === void 0) {
|
|
135
|
-
return
|
|
144
|
+
return finalizedHeight;
|
|
136
145
|
}
|
|
137
|
-
|
|
146
|
+
const indexerHeight = hexToNumber(stored.number) - 1;
|
|
147
|
+
return Math.min(indexerHeight, finalizedHeight);
|
|
138
148
|
};
|
|
139
149
|
const public_writeUnfinalizedHeads = async (heads) => {
|
|
140
150
|
let chain = void 0;
|
|
@@ -239,6 +249,10 @@ function indexer(opts) {
|
|
|
239
249
|
await Promise.all(promises);
|
|
240
250
|
};
|
|
241
251
|
const public_writeFinalizedHeads = async (heads) => {
|
|
252
|
+
if (heads.length === 0) {
|
|
253
|
+
return log.debug("No heads received, returning...");
|
|
254
|
+
}
|
|
255
|
+
log.debug(`Received ${heads.length} finalized heads...`);
|
|
242
256
|
let chain = void 0;
|
|
243
257
|
for (const head of heads) {
|
|
244
258
|
if (chain === void 0) {
|
|
@@ -249,40 +263,11 @@ function indexer(opts) {
|
|
|
249
263
|
}
|
|
250
264
|
}
|
|
251
265
|
if (chain === void 0) {
|
|
252
|
-
throw new Error(
|
|
266
|
+
throw new Error("Internal error. Expected chain to be defined after checking heads length");
|
|
253
267
|
}
|
|
254
|
-
|
|
255
|
-
const [indexerHeight, finalizedBlock] = await Promise.all([
|
|
256
|
-
public_getFinalizedHeight(chain),
|
|
257
|
-
//
|
|
258
|
-
getBlock({ chain, number: "finalized" })
|
|
259
|
-
]);
|
|
260
|
-
if (indexerHeight === null) {
|
|
261
|
-
return log.debug(`No unfinalized blocks processed for chain ${hexToNumber(chain)}, aborting...`);
|
|
262
|
-
}
|
|
263
|
-
if (finalizedBlock === null) {
|
|
264
|
-
log.debug("Failed to load finalized block, aborting...");
|
|
265
|
-
throw new Error(GetBlockError);
|
|
266
|
-
}
|
|
267
|
-
const finalizedHeight = hexToNumber(finalizedBlock.eth_getBlockByNumber.number);
|
|
268
|
-
log.debug(`Indexer height ${indexerHeight}, finalized height ${finalizedHeight}`);
|
|
269
|
-
const newHeads = heads.filter((head) => {
|
|
270
|
-
if (hexToNumber(head.number) > finalizedHeight) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
if (hexToNumber(head.number) > indexerHeight) {
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
return false;
|
|
277
|
-
});
|
|
278
|
-
const [firstHead, ...remainingHeads] = newHeads;
|
|
268
|
+
const [firstHead, ...remainingHeads] = heads;
|
|
279
269
|
if (firstHead === void 0) {
|
|
280
|
-
|
|
281
|
-
throw new Error(InvalidHeadsError);
|
|
282
|
-
}
|
|
283
|
-
if (hexToNumber(firstHead.number) !== indexerHeight + 1) {
|
|
284
|
-
log.debug("First unfinalized head received didn't match metadata, aborting...");
|
|
285
|
-
throw new Error(InvalidHeadsError);
|
|
270
|
+
throw new Error("Internal error. Expected firstHead to be defined after checking heads length");
|
|
286
271
|
}
|
|
287
272
|
let previousHead = firstHead;
|
|
288
273
|
for (const head of remainingHeads) {
|
|
@@ -296,6 +281,28 @@ function indexer(opts) {
|
|
|
296
281
|
}
|
|
297
282
|
previousHead = head;
|
|
298
283
|
}
|
|
284
|
+
const [indexerHeight, finalizedBlock] = await Promise.all([
|
|
285
|
+
public_getFinalizedHeight(chain),
|
|
286
|
+
//
|
|
287
|
+
getBlock({ chain, number: "finalized" })
|
|
288
|
+
]);
|
|
289
|
+
if (finalizedBlock === null) {
|
|
290
|
+
log.debug("Failed to load chain finalized block. Request should be retried");
|
|
291
|
+
throw new Error(GetBlockError);
|
|
292
|
+
}
|
|
293
|
+
const finalizedHeight = hexToNumber(finalizedBlock.eth_getBlockByNumber.number);
|
|
294
|
+
for (const head of heads) {
|
|
295
|
+
if (hexToNumber(head.number) > finalizedHeight) {
|
|
296
|
+
throw new Error(InvalidHeadsError);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
log.debug(`Indexer height ${indexerHeight}, finalized height ${finalizedHeight}`);
|
|
300
|
+
const newHeads = heads.filter((head) => {
|
|
301
|
+
return hexToNumber(head.number) > indexerHeight;
|
|
302
|
+
});
|
|
303
|
+
if (newHeads.length === 0) {
|
|
304
|
+
return log.debug("No new heads received, returning...");
|
|
305
|
+
}
|
|
299
306
|
for (const head of newHeads) {
|
|
300
307
|
const processed = await metadata.blocks.get({ chain: head.chain, number: head.number });
|
|
301
308
|
if (processed.length === 0) {
|
package/dist/realtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as createLogger, e as iife, h as hexToNumber, f as numberToHex, m as mutex, r as retry, i as isHexEqual } from './shared/univo.
|
|
1
|
+
import { c as createLogger, e as iife, h as hexToNumber, f as numberToHex, m as mutex, r as retry, i as isHexEqual } from './shared/univo.Br975GsZ.mjs';
|
|
2
2
|
|
|
3
3
|
const MAX_LENGTH = 1e4;
|
|
4
4
|
function defineBlockchain(opts) {
|
|
@@ -139,18 +139,14 @@ function realtime(opts) {
|
|
|
139
139
|
getBlockByHash,
|
|
140
140
|
quiet: opts.quiet ?? false
|
|
141
141
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
await indexer.reconcile(indexerBlock);
|
|
151
|
-
await indexer.reconcile(latestBlock);
|
|
152
|
-
log.debug("Reconciled local indexer chain");
|
|
153
|
-
}
|
|
142
|
+
log.debug(`Indexer last finalized at ${initialIndexerHeight}, reconciling local chain...`);
|
|
143
|
+
const indexerBlock = await opts.node.request({
|
|
144
|
+
method: "eth_getBlockByNumber",
|
|
145
|
+
params: [numberToHex(initialIndexerHeight), false]
|
|
146
|
+
});
|
|
147
|
+
await indexer.reconcile(indexerBlock);
|
|
148
|
+
await indexer.reconcile(latestBlock);
|
|
149
|
+
log.debug("Reconciled local indexer chain");
|
|
154
150
|
await opts.node.subscribe("newHeads", async (head) => {
|
|
155
151
|
try {
|
|
156
152
|
await indexer.reconcile(head);
|
|
@@ -161,7 +157,7 @@ function realtime(opts) {
|
|
|
161
157
|
}
|
|
162
158
|
});
|
|
163
159
|
log.debug("Subscribed indexer chain to new heads");
|
|
164
|
-
let indexerHeight = initialIndexerHeight
|
|
160
|
+
let indexerHeight = initialIndexerHeight;
|
|
165
161
|
const poll = async () => {
|
|
166
162
|
try {
|
|
167
163
|
const finalizedBlock = await opts.node.request({
|
package/dist/rpc.d.mts
CHANGED
|
@@ -57,7 +57,7 @@ type IndexerRpc = {
|
|
|
57
57
|
* Accepts a chain identifier
|
|
58
58
|
* @returns Height of the last finalized block indexed
|
|
59
59
|
*/
|
|
60
|
-
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number
|
|
60
|
+
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number>;
|
|
61
61
|
/**
|
|
62
62
|
* Accepts a reorganised block and deletes all related events from storage
|
|
63
63
|
*/
|
package/dist/rpc.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ type IndexerRpc = {
|
|
|
57
57
|
* Accepts a chain identifier
|
|
58
58
|
* @returns Height of the last finalized block indexed
|
|
59
59
|
*/
|
|
60
|
-
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number
|
|
60
|
+
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number>;
|
|
61
61
|
/**
|
|
62
62
|
* Accepts a reorganised block and deletes all related events from storage
|
|
63
63
|
*/
|
package/dist/transport.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ws from 'ws';
|
|
2
2
|
import { WebSocket } from 'partysocket';
|
|
3
3
|
import { c as createException } from './shared/univo.C0flyVee.mjs';
|
|
4
|
-
import { j as compress, k as raise, c as createLogger } from './shared/univo.
|
|
4
|
+
import { j as compress, k as raise, c as createLogger } from './shared/univo.Br975GsZ.mjs';
|
|
5
5
|
|
|
6
6
|
function createSocket(url, opts) {
|
|
7
7
|
const socket = new WebSocket(url, [], { WebSocket: ws });
|