univo 0.2.4 → 0.2.6
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 +63 -65
- package/dist/realtime.mjs +71 -51
- package/dist/rpc.d.mts +11 -3
- package/dist/rpc.d.ts +11 -3
- package/dist/shared/{univo.6U84KZUp.mjs → univo.CTWk2lBv.mjs} +16 -6
- 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,
|
|
8
|
+
import { c as createLogger, v as version, g as name } from './shared/univo.CTWk2lBv.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 } 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.CTWk2lBv.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) {
|
|
@@ -41,15 +41,26 @@ const includesLogEvent = (block, filter) => {
|
|
|
41
41
|
return false;
|
|
42
42
|
};
|
|
43
43
|
function indexer(opts) {
|
|
44
|
-
const log = createLogger({ quiet: opts.quiet ?? false });
|
|
44
|
+
const log = createLogger({ quiet: opts.quiet ?? false, prefix: "[indexer]" });
|
|
45
45
|
const all_events = [];
|
|
46
46
|
const events_grouped_by_storage_map = /* @__PURE__ */ new Map();
|
|
47
47
|
const metadata = {
|
|
48
48
|
blocks: {
|
|
49
|
+
async list(head) {
|
|
50
|
+
let prefix = `/blocks/v1/${normalizeHex(head.chain)}`;
|
|
51
|
+
if (typeof head.number === "string") {
|
|
52
|
+
prefix += `/${normalizeHex(head.number, 16)}`;
|
|
53
|
+
}
|
|
54
|
+
const keys = await opts.metadataStorage.getKeys(prefix);
|
|
55
|
+
return keys.map((key) => {
|
|
56
|
+
const [__, ___, chain, number, hash] = key.split(":");
|
|
57
|
+
return { chain, number, hash };
|
|
58
|
+
});
|
|
59
|
+
},
|
|
49
60
|
async get(head) {
|
|
50
61
|
let prefix = `/blocks/v1/${head.chain.toLowerCase()}`;
|
|
51
62
|
if (typeof head.number === "string") {
|
|
52
|
-
prefix += `/${head.number
|
|
63
|
+
prefix += `/${normalizeHex(head.number, 16)}`;
|
|
53
64
|
}
|
|
54
65
|
if (typeof head.hash === "string") {
|
|
55
66
|
if (head.number === void 0) {
|
|
@@ -72,9 +83,9 @@ function indexer(opts) {
|
|
|
72
83
|
}
|
|
73
84
|
await opts.metadataStorage.setItems(
|
|
74
85
|
blocks.map((block) => {
|
|
75
|
-
const chain = block.eth_chainId
|
|
76
|
-
const hash = block.eth_getBlockByNumber.hash
|
|
77
|
-
const number = block.eth_getBlockByNumber.number
|
|
86
|
+
const chain = normalizeHex(block.eth_chainId);
|
|
87
|
+
const hash = normalizeHex(block.eth_getBlockByNumber.hash);
|
|
88
|
+
const number = normalizeHex(block.eth_getBlockByNumber.number, 16);
|
|
78
89
|
const key = `/blocks/v1/${chain}/${number}/${hash}`;
|
|
79
90
|
return { key, value: block };
|
|
80
91
|
})
|
|
@@ -86,9 +97,9 @@ function indexer(opts) {
|
|
|
86
97
|
}
|
|
87
98
|
await Promise.all(
|
|
88
99
|
blocks.map(async (block) => {
|
|
89
|
-
const chain = block.eth_chainId
|
|
90
|
-
const hash = block.eth_getBlockByNumber.hash
|
|
91
|
-
const number = block.eth_getBlockByNumber.number
|
|
100
|
+
const chain = normalizeHex(block.eth_chainId);
|
|
101
|
+
const hash = normalizeHex(block.eth_getBlockByNumber.hash);
|
|
102
|
+
const number = normalizeHex(block.eth_getBlockByNumber.number, 16);
|
|
92
103
|
await opts.metadataStorage.del(`/blocks/v1/${chain}/${number}/${hash}`);
|
|
93
104
|
})
|
|
94
105
|
);
|
|
@@ -119,20 +130,11 @@ function indexer(opts) {
|
|
|
119
130
|
return block;
|
|
120
131
|
}
|
|
121
132
|
const public_getFinalizedHeight = async (chain) => {
|
|
122
|
-
const [
|
|
123
|
-
getBlock({ chain, number: "finalized" }),
|
|
124
|
-
//
|
|
125
|
-
metadata.blocks.get({ chain })
|
|
126
|
-
]);
|
|
127
|
-
if (finalized === null) {
|
|
128
|
-
throw new Error("Failed to determine unfinalized height");
|
|
129
|
-
}
|
|
130
|
-
const finalizedHeight = hexToNumber(finalized.eth_getBlockByNumber.number);
|
|
133
|
+
const [stored] = await metadata.blocks.list({ chain });
|
|
131
134
|
if (stored === void 0) {
|
|
132
|
-
return
|
|
135
|
+
return null;
|
|
133
136
|
}
|
|
134
|
-
|
|
135
|
-
return Math.min(finalizedHeight, storedHeight);
|
|
137
|
+
return hexToNumber(stored.number) - 1;
|
|
136
138
|
};
|
|
137
139
|
const public_writeUnfinalizedHeads = async (heads) => {
|
|
138
140
|
let chain = void 0;
|
|
@@ -247,76 +249,72 @@ function indexer(opts) {
|
|
|
247
249
|
}
|
|
248
250
|
}
|
|
249
251
|
if (chain === void 0) {
|
|
250
|
-
throw new Error(
|
|
252
|
+
throw new Error(InvalidHeadsError);
|
|
251
253
|
}
|
|
252
254
|
log.debug(`Received ${heads.length} finalized heads...`);
|
|
253
|
-
const [
|
|
254
|
-
|
|
255
|
+
const [indexerHeight, finalizedBlock] = await Promise.all([
|
|
256
|
+
public_getFinalizedHeight(chain),
|
|
255
257
|
//
|
|
256
258
|
getBlock({ chain, number: "finalized" })
|
|
257
259
|
]);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return log.debug(`No unfinalised blocks processed for chain ${hexToNumber(chain)}, ignoring...`);
|
|
260
|
+
if (indexerHeight === null) {
|
|
261
|
+
return log.debug(`No unfinalized blocks processed for chain ${hexToNumber(chain)}, aborting...`);
|
|
261
262
|
}
|
|
262
263
|
if (finalizedBlock === null) {
|
|
264
|
+
log.debug("Failed to load finalized block, aborting...");
|
|
263
265
|
throw new Error(GetBlockError);
|
|
264
266
|
}
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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;
|
|
272
277
|
});
|
|
273
|
-
const [
|
|
274
|
-
if (
|
|
278
|
+
const [firstHead, ...remainingHeads] = newHeads;
|
|
279
|
+
if (firstHead === void 0) {
|
|
280
|
+
log.debug("Received no new finalized heads, aborting...");
|
|
275
281
|
throw new Error(InvalidHeadsError);
|
|
276
282
|
}
|
|
277
|
-
if (hexToNumber(
|
|
283
|
+
if (hexToNumber(firstHead.number) !== indexerHeight + 1) {
|
|
284
|
+
log.debug("First unfinalized head received didn't match metadata, aborting...");
|
|
278
285
|
throw new Error(InvalidHeadsError);
|
|
279
286
|
}
|
|
280
|
-
let previousHead =
|
|
281
|
-
for (const head of
|
|
287
|
+
let previousHead = firstHead;
|
|
288
|
+
for (const head of remainingHeads) {
|
|
282
289
|
if (hexToNumber(head.number) !== hexToNumber(previousHead.number) + 1) {
|
|
290
|
+
log.debug("Found invalid block number in received heads, aborting...");
|
|
283
291
|
throw new Error(InvalidHeadsError);
|
|
284
292
|
}
|
|
285
293
|
if (!isHexEqual(head.parentHash, previousHead.hash)) {
|
|
294
|
+
log.debug("Found invalid block hash in received heads, aborting...");
|
|
286
295
|
throw new Error(InvalidHeadsError);
|
|
287
296
|
}
|
|
288
297
|
previousHead = head;
|
|
289
298
|
}
|
|
290
|
-
for (const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
299
|
+
for (const head of newHeads) {
|
|
300
|
+
const processed = await metadata.blocks.get({ chain: head.chain, number: head.number });
|
|
301
|
+
if (processed.length === 0) {
|
|
302
|
+
await writeFinalizedHead(head, null);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const reorganised = processed.filter((block2) => {
|
|
306
|
+
return !isHexEqual(head.hash, block2.eth_getBlockByNumber.hash);
|
|
294
307
|
});
|
|
295
|
-
if (
|
|
296
|
-
|
|
308
|
+
if (reorganised.length > 0) {
|
|
309
|
+
await deleteReorganisedBlocks(reorganised);
|
|
297
310
|
}
|
|
298
|
-
|
|
299
|
-
|
|
311
|
+
const block = processed.find((block2) => {
|
|
312
|
+
return isHexEqual(head.hash, block2.eth_getBlockByNumber.hash);
|
|
313
|
+
});
|
|
314
|
+
await writeFinalizedHead(head, block ?? null);
|
|
315
|
+
await metadata.blocks.delete(processed);
|
|
300
316
|
}
|
|
301
317
|
};
|
|
302
|
-
async function reprocessFinalizedHead(canonical, processed) {
|
|
303
|
-
if (processed.length === 0) {
|
|
304
|
-
return await writeFinalizedHead(canonical, null);
|
|
305
|
-
}
|
|
306
|
-
const reorganised = processed.filter((block2) => {
|
|
307
|
-
return !isHexEqual(canonical.hash, block2.eth_getBlockByNumber.hash);
|
|
308
|
-
});
|
|
309
|
-
if (reorganised.length > 0) {
|
|
310
|
-
await deleteReorganisedBlocks(reorganised);
|
|
311
|
-
}
|
|
312
|
-
const block = processed.find((block2) => {
|
|
313
|
-
return isHexEqual(canonical.hash, block2.eth_getBlockByNumber.hash);
|
|
314
|
-
});
|
|
315
|
-
if (block === void 0) {
|
|
316
|
-
return await writeFinalizedHead(canonical, null);
|
|
317
|
-
}
|
|
318
|
-
return await writeFinalizedHead(canonical, block);
|
|
319
|
-
}
|
|
320
318
|
async function writeFinalizedHead(head, block_nullable) {
|
|
321
319
|
let block = block_nullable;
|
|
322
320
|
if (block === null) {
|
package/dist/realtime.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as createLogger,
|
|
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.CTWk2lBv.mjs';
|
|
2
2
|
|
|
3
3
|
const MAX_LENGTH = 1e4;
|
|
4
4
|
function defineBlockchain(opts) {
|
|
@@ -79,29 +79,18 @@ function defineBlockchain(opts) {
|
|
|
79
79
|
}
|
|
80
80
|
const POLLING_INTERVAL_MS = 12 * 1e3;
|
|
81
81
|
function realtime(opts) {
|
|
82
|
-
const log = createLogger({ quiet: opts.quiet ?? false });
|
|
82
|
+
const log = createLogger({ quiet: opts.quiet ?? false, prefix: "[realtime]" });
|
|
83
83
|
const getBlockByHash = async (hash) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const getLatestBlock = async () => {
|
|
87
|
-
return await opts.node.request({ method: "eth_getBlockByNumber", params: ["latest", false] });
|
|
88
|
-
};
|
|
89
|
-
const getChainFinalizedBlock = async () => {
|
|
90
|
-
return await opts.node.request({ method: "eth_getBlockByNumber", params: ["finalized", false] });
|
|
91
|
-
};
|
|
92
|
-
const getIndexerFinalizedBlock = async (chain) => {
|
|
93
|
-
const height = await opts.indexer.request({ method: "public_getFinalizedHeight", params: [chain] });
|
|
94
|
-
return await opts.node.request({ method: "eth_getBlockByNumber", params: [numberToHex(height), false] });
|
|
84
|
+
const block = await opts.node.request({ method: "eth_getBlockByHash", params: [hash, false] });
|
|
85
|
+
return { number: block.number, hash: block.hash, parentHash: block.parentHash };
|
|
95
86
|
};
|
|
96
87
|
const promise = iife(async () => {
|
|
97
88
|
log.debug("Initialising realtime client for indexer");
|
|
98
89
|
const chain = await opts.node.request({ method: "eth_chainId", params: [] });
|
|
99
90
|
log.debug(`Determined chain identifier for connected node: ${hexToNumber(chain)}`);
|
|
100
|
-
const [latestBlock,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
getIndexerFinalizedBlock(chain)
|
|
91
|
+
const [latestBlock, initialIndexerHeight] = await Promise.all([
|
|
92
|
+
opts.node.request({ method: "eth_getBlockByNumber", params: ["latest", false] }),
|
|
93
|
+
opts.indexer.request({ method: "public_getFinalizedHeight", params: [chain] })
|
|
105
94
|
]);
|
|
106
95
|
let pending = [];
|
|
107
96
|
const latest = defineBlockchain({
|
|
@@ -109,6 +98,7 @@ function realtime(opts) {
|
|
|
109
98
|
quiet: opts.quiet ?? false,
|
|
110
99
|
onBlockAdded: async (head) => {
|
|
111
100
|
try {
|
|
101
|
+
log.debug("Received unfinalized head");
|
|
112
102
|
pending.push(head);
|
|
113
103
|
const heads = pending.map((head2) => ({ chain, ...head2 }));
|
|
114
104
|
await opts.indexer.request({ method: "public_writeUnfinalizedHeads", params: [heads] });
|
|
@@ -118,72 +108,102 @@ function realtime(opts) {
|
|
|
118
108
|
return isHexEqual(head2.hash, _head.hash);
|
|
119
109
|
});
|
|
120
110
|
});
|
|
121
|
-
} catch {
|
|
122
|
-
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error instanceof Error) {
|
|
113
|
+
log.warn(`Failed to write heads: ${error.message}`);
|
|
114
|
+
}
|
|
123
115
|
}
|
|
124
116
|
},
|
|
125
117
|
onBlockReorganised: async (head) => {
|
|
126
118
|
try {
|
|
127
119
|
await retry(() => opts.indexer.request({ method: "public_deleteReorganisedHead", params: [{ chain, ...head }] }), 2);
|
|
128
|
-
} catch {
|
|
129
|
-
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error instanceof Error) {
|
|
122
|
+
log.warn(`Failed to write reorganised head: ${error.message}`);
|
|
123
|
+
}
|
|
130
124
|
}
|
|
131
125
|
}
|
|
132
126
|
});
|
|
133
127
|
await latest.reconcile(latestBlock);
|
|
134
|
-
log.debug("Reconciled latest block...");
|
|
135
128
|
await opts.node.subscribe("newHeads", async (head) => {
|
|
136
129
|
try {
|
|
137
130
|
await latest.reconcile(head);
|
|
138
|
-
} catch {
|
|
139
|
-
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof Error) {
|
|
133
|
+
log.error(`Failed to reconcile latest head: ${error.message}`);
|
|
134
|
+
}
|
|
140
135
|
}
|
|
141
136
|
});
|
|
142
|
-
log.debug("Subscribed to
|
|
143
|
-
|
|
144
|
-
log.debug(`Indexer last finalized at ${lastFinalizedHeight}, chain at ${hexToNumber(chainFinalizedBlock.number)}`);
|
|
145
|
-
const finalized = defineBlockchain({
|
|
137
|
+
log.debug("Subscribed latest chain to new heads");
|
|
138
|
+
const indexer = defineBlockchain({
|
|
146
139
|
getBlockByHash,
|
|
147
140
|
quiet: opts.quiet ?? false
|
|
148
141
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
if (initialIndexerHeight === null) {
|
|
143
|
+
await indexer.reconcile(latestBlock);
|
|
144
|
+
} else {
|
|
145
|
+
log.debug(`Indexer last finalized at ${initialIndexerHeight}, reconciling local chain...`);
|
|
146
|
+
const indexerBlock = await opts.node.request({
|
|
147
|
+
method: "eth_getBlockByNumber",
|
|
148
|
+
params: [numberToHex(initialIndexerHeight), false]
|
|
149
|
+
});
|
|
150
|
+
await indexer.reconcile(indexerBlock);
|
|
151
|
+
await indexer.reconcile(latestBlock);
|
|
152
|
+
log.debug("Reconciled local indexer chain");
|
|
153
|
+
}
|
|
154
|
+
await opts.node.subscribe("newHeads", async (head) => {
|
|
155
|
+
try {
|
|
156
|
+
await indexer.reconcile(head);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (error instanceof Error) {
|
|
159
|
+
log.debug(`Failed to reconcile latest indexer head: ${error.message}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
log.debug("Subscribed indexer chain to new heads");
|
|
164
|
+
let indexerHeight = initialIndexerHeight || hexToNumber(latestBlock.number);
|
|
152
165
|
const poll = async () => {
|
|
153
166
|
try {
|
|
154
167
|
const finalizedBlock = await opts.node.request({
|
|
155
168
|
method: "eth_getBlockByNumber",
|
|
156
169
|
params: ["finalized", false]
|
|
157
|
-
//
|
|
158
170
|
});
|
|
159
171
|
const finalizedHeight = hexToNumber(finalizedBlock.number);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (hexToNumber(head.number) >
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
log.debug(`Finalized chain height ${finalizedHeight} and indexer height ${indexerHeight}`);
|
|
173
|
+
const newHeads = indexer.chain.filter((head) => {
|
|
174
|
+
if (hexToNumber(head.number) > finalizedHeight) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
if (hexToNumber(head.number) > indexerHeight) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
168
181
|
}).map((head) => {
|
|
169
182
|
return { chain, ...head };
|
|
170
183
|
});
|
|
171
|
-
if (
|
|
184
|
+
if (newHeads.length === 0) {
|
|
172
185
|
return log.debug("No new finalized heads to deliver, ignoring...");
|
|
173
186
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
log.
|
|
187
|
+
log.debug(`Delivering ${newHeads.length} finalized head(s)...`);
|
|
188
|
+
await opts.indexer.request({ method: "public_writeFinalizedHeads", params: [newHeads] });
|
|
189
|
+
log.debug(`Delivered ${newHeads.length} finalized head(s)`);
|
|
190
|
+
indexerHeight = hexToNumber(finalizedBlock.number);
|
|
191
|
+
log.debug(`Updated indexer height to ${indexerHeight}`);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (error instanceof Error) {
|
|
194
|
+
log.error(`Failed to reconcile finalized head: ${error.message}`);
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
setTimeout(poll, POLLING_INTERVAL_MS);
|
|
179
198
|
}
|
|
180
199
|
};
|
|
181
200
|
await poll();
|
|
182
|
-
|
|
183
|
-
log.debug("Start polling finalized height");
|
|
201
|
+
log.debug("Started polling finalized height");
|
|
184
202
|
});
|
|
185
|
-
promise.catch(() => {
|
|
186
|
-
|
|
203
|
+
promise.catch((error) => {
|
|
204
|
+
if (error instanceof Error) {
|
|
205
|
+
log.error(`Failed to initialise realtime client: ${error.message}`);
|
|
206
|
+
}
|
|
187
207
|
});
|
|
188
208
|
}
|
|
189
209
|
|
package/dist/rpc.d.mts
CHANGED
|
@@ -29,12 +29,20 @@ type NodeRpc = {
|
|
|
29
29
|
* Accepts a block tag and boolean for including receipts
|
|
30
30
|
* @returns A block with optional receipts
|
|
31
31
|
*/
|
|
32
|
-
eth_getBlockByNumber: (number: string, receipts: boolean) => Promise<
|
|
32
|
+
eth_getBlockByNumber: (number: string, receipts: boolean) => Promise<{
|
|
33
|
+
hash: `0x${string}`;
|
|
34
|
+
number: `0x${string}`;
|
|
35
|
+
parentHash: `0x${string}`;
|
|
36
|
+
}>;
|
|
33
37
|
/**
|
|
34
38
|
* Accepts a block hash and boolean for including receipts
|
|
35
39
|
* @returns A block with optional receipts
|
|
36
40
|
*/
|
|
37
|
-
eth_getBlockByHash: (hash: `0x${string}`, receipts: boolean) => Promise<
|
|
41
|
+
eth_getBlockByHash: (hash: `0x${string}`, receipts: boolean) => Promise<{
|
|
42
|
+
hash: `0x${string}`;
|
|
43
|
+
number: `0x${string}`;
|
|
44
|
+
parentHash: `0x${string}`;
|
|
45
|
+
}>;
|
|
38
46
|
};
|
|
39
47
|
subscribe: {
|
|
40
48
|
newHeads: Head;
|
|
@@ -49,7 +57,7 @@ type IndexerRpc = {
|
|
|
49
57
|
* Accepts a chain identifier
|
|
50
58
|
* @returns Height of the last finalized block indexed
|
|
51
59
|
*/
|
|
52
|
-
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number>;
|
|
60
|
+
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number | null>;
|
|
53
61
|
/**
|
|
54
62
|
* Accepts a reorganised block and deletes all related events from storage
|
|
55
63
|
*/
|
package/dist/rpc.d.ts
CHANGED
|
@@ -29,12 +29,20 @@ type NodeRpc = {
|
|
|
29
29
|
* Accepts a block tag and boolean for including receipts
|
|
30
30
|
* @returns A block with optional receipts
|
|
31
31
|
*/
|
|
32
|
-
eth_getBlockByNumber: (number: string, receipts: boolean) => Promise<
|
|
32
|
+
eth_getBlockByNumber: (number: string, receipts: boolean) => Promise<{
|
|
33
|
+
hash: `0x${string}`;
|
|
34
|
+
number: `0x${string}`;
|
|
35
|
+
parentHash: `0x${string}`;
|
|
36
|
+
}>;
|
|
33
37
|
/**
|
|
34
38
|
* Accepts a block hash and boolean for including receipts
|
|
35
39
|
* @returns A block with optional receipts
|
|
36
40
|
*/
|
|
37
|
-
eth_getBlockByHash: (hash: `0x${string}`, receipts: boolean) => Promise<
|
|
41
|
+
eth_getBlockByHash: (hash: `0x${string}`, receipts: boolean) => Promise<{
|
|
42
|
+
hash: `0x${string}`;
|
|
43
|
+
number: `0x${string}`;
|
|
44
|
+
parentHash: `0x${string}`;
|
|
45
|
+
}>;
|
|
38
46
|
};
|
|
39
47
|
subscribe: {
|
|
40
48
|
newHeads: Head;
|
|
@@ -49,7 +57,7 @@ type IndexerRpc = {
|
|
|
49
57
|
* Accepts a chain identifier
|
|
50
58
|
* @returns Height of the last finalized block indexed
|
|
51
59
|
*/
|
|
52
|
-
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number>;
|
|
60
|
+
public_getFinalizedHeight: (chain: `0x${string}`) => Promise<number | null>;
|
|
53
61
|
/**
|
|
54
62
|
* Accepts a reorganised block and deletes all related events from storage
|
|
55
63
|
*/
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
const name = "univo";
|
|
2
|
-
const version = "0.2.
|
|
2
|
+
const version = "0.2.6";
|
|
3
3
|
|
|
4
4
|
function createLogger(opts) {
|
|
5
|
+
let prefix = `[${name}@${version}]`;
|
|
6
|
+
if (opts.prefix !== void 0) {
|
|
7
|
+
prefix += ` ${opts.prefix}`;
|
|
8
|
+
}
|
|
5
9
|
return {
|
|
6
10
|
debug(...any) {
|
|
7
11
|
if (opts.quiet) {
|
|
8
12
|
return;
|
|
9
13
|
}
|
|
10
14
|
if (process.env.LOG_LEVEL === "DEBUG") {
|
|
11
|
-
console.log(
|
|
15
|
+
console.log(`${opts.prefix} DEBUG`, ...any);
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
info(...any) {
|
|
@@ -16,7 +20,7 @@ function createLogger(opts) {
|
|
|
16
20
|
return;
|
|
17
21
|
}
|
|
18
22
|
if (process.env.LOG_LEVEL === "DEBUG" || process.env.LOG_LEVEL === "INFO") {
|
|
19
|
-
console.log(
|
|
23
|
+
console.log(`${opts.prefix} INFO`, ...any);
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
warn(...any) {
|
|
@@ -24,7 +28,7 @@ function createLogger(opts) {
|
|
|
24
28
|
return;
|
|
25
29
|
}
|
|
26
30
|
if (process.env.LOG_LEVEL === "DEBUG" || process.env.LOG_LEVEL === "INFO" || process.env.LOG_LEVEL === "WARN") {
|
|
27
|
-
console.log(
|
|
31
|
+
console.log(`${opts.prefix} WARN`, ...any);
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
error(...any) {
|
|
@@ -32,7 +36,7 @@ function createLogger(opts) {
|
|
|
32
36
|
return;
|
|
33
37
|
}
|
|
34
38
|
if (process.env.LOG_LEVEL === "DEBUG" || process.env.LOG_LEVEL === "INFO" || process.env.LOG_LEVEL === "WARN" || process.env.LOG_LEVEL === "ERROR") {
|
|
35
|
-
console.log(
|
|
39
|
+
console.log(`${opts.prefix} ERROR`, ...any);
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
};
|
|
@@ -81,5 +85,11 @@ async function decompress(input) {
|
|
|
81
85
|
return new Response(decompressed).text();
|
|
82
86
|
}
|
|
83
87
|
const decoder = new TextDecoder();
|
|
88
|
+
const normalizeHex = (hex, length) => {
|
|
89
|
+
if (length === void 0) {
|
|
90
|
+
return hex.toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
return `0x${hex.slice(2).toLowerCase().padStart(length, "0")}`;
|
|
93
|
+
};
|
|
84
94
|
|
|
85
|
-
export { decoder as a,
|
|
95
|
+
export { decoder as a, normalizeHex as b, createLogger as c, decompress as d, iife as e, numberToHex as f, name as g, hexToNumber as h, isHexEqual as i, compress as j, raise as k, mutex as m, nonNullable as n, retry as r, version as v };
|
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 {
|
|
4
|
+
import { j as compress, k as raise, c as createLogger } from './shared/univo.CTWk2lBv.mjs';
|
|
5
5
|
|
|
6
6
|
function createSocket(url, opts) {
|
|
7
7
|
const socket = new WebSocket(url, [], { WebSocket: ws });
|