univo 0.3.0 → 0.3.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/dist/cli.mjs
CHANGED
|
@@ -4,8 +4,8 @@ import open from 'open';
|
|
|
4
4
|
import { config } from 'dotenv';
|
|
5
5
|
import { WebSocket } from 'partysocket';
|
|
6
6
|
import { defineCommand, runMain } from 'citty';
|
|
7
|
-
import { h as http } from './shared/univo.
|
|
8
|
-
import { c as createLogger, v as version, n as name } from './shared/univo.
|
|
7
|
+
import { h as http } from './shared/univo.BlbeUAWT.mjs';
|
|
8
|
+
import { c as createLogger, v as version, n as name } from './shared/univo.Dxj7VaSK.mjs';
|
|
9
9
|
|
|
10
10
|
const log = createLogger({ quiet: false });
|
|
11
11
|
const dev = defineCommand({
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
|
-
import { g as getException, c as createException, a as catchException, l as local } from './shared/univo.
|
|
3
|
-
import { c as createLogger, d as decompress, b as decoder, r as retry, v as version, e as normalizeHex, a as isHexEqual, f as compress } from './shared/univo.
|
|
2
|
+
import { g as getException, c as createException, a as catchException, l as local } from './shared/univo.BlbeUAWT.mjs';
|
|
3
|
+
import { c as createLogger, d as decompress, b as decoder, r as retry, v as version, e as normalizeHex, a as isHexEqual, f as compress } from './shared/univo.Dxj7VaSK.mjs';
|
|
4
4
|
import { AdapterError } from './metadata/adapters.mjs';
|
|
5
5
|
import 'ws';
|
|
6
6
|
import 'partysocket';
|
|
@@ -406,7 +406,8 @@ function defineIndexer(opts) {
|
|
|
406
406
|
const number = normalizeHex(block.eth_getBlockByNumber.number, 16);
|
|
407
407
|
const parentHash = normalizeHex(block.eth_getBlockByNumber.parentHash);
|
|
408
408
|
const commitsKey = `commits/v1/${chain}/${number}/${hash}/${parentHash}`;
|
|
409
|
-
|
|
409
|
+
const commitsValue = JSON.stringify({ hello: "world" });
|
|
410
|
+
await opts.metadataStorage.adapter.put(commitsKey, commitsValue);
|
|
410
411
|
}
|
|
411
412
|
const public_writeUnfinalizedHead = async (head) => {
|
|
412
413
|
log.debug("Received unfinalized head...");
|
|
@@ -428,9 +429,7 @@ function defineIndexer(opts) {
|
|
|
428
429
|
const parentHash = normalizeHex(block.eth_getBlockByNumber.parentHash);
|
|
429
430
|
const blocksKey = `blocks/v1/${chain}/${number}/${hash}/${parentHash}`;
|
|
430
431
|
const blocksValue = await compress(JSON.stringify(block));
|
|
431
|
-
const conditional = {
|
|
432
|
-
ifNoneMatch: "*"
|
|
433
|
-
};
|
|
432
|
+
const conditional = { ifNoneMatch: "*" };
|
|
434
433
|
const result = await opts.metadataStorage.adapter.put(blocksKey, blocksValue, conditional).catch((error) => {
|
|
435
434
|
if (error instanceof AdapterError) {
|
|
436
435
|
if (error.tag === "PreconditionFailed") {
|
|
@@ -540,7 +539,8 @@ function defineIndexer(opts) {
|
|
|
540
539
|
throw failure.reason;
|
|
541
540
|
}
|
|
542
541
|
const commitsKey = `${prefix}/action/${action2.id}`;
|
|
543
|
-
|
|
542
|
+
const commitsValue = JSON.stringify({ hello: "world" });
|
|
543
|
+
await opts.metadataStorage.adapter.put(commitsKey, commitsValue);
|
|
544
544
|
});
|
|
545
545
|
await Promise.all(promises);
|
|
546
546
|
}
|
|
@@ -570,7 +570,9 @@ function defineIndexer(opts) {
|
|
|
570
570
|
const hash = normalizeHex(block.eth_getBlockByNumber.hash);
|
|
571
571
|
const parentHash = normalizeHex(block.eth_getBlockByNumber.parentHash);
|
|
572
572
|
const finalizedKey = `finalized/v1/${chain}/${number}/${hash}/${parentHash}`;
|
|
573
|
-
const
|
|
573
|
+
const finalizedValue = JSON.stringify({ hello: "world" });
|
|
574
|
+
const conditional = { ifNoneMatch: "*" };
|
|
575
|
+
const result = await opts.metadataStorage.adapter.put(finalizedKey, finalizedValue, conditional).catch((error) => {
|
|
574
576
|
if (error instanceof AdapterError && error.tag === "PreconditionFailed") {
|
|
575
577
|
return null;
|
|
576
578
|
}
|
package/dist/realtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hexToNumber } from 'viem';
|
|
2
|
-
import { c as createLogger, i as iife, m as mutex, r as retry, a as isHexEqual } from './shared/univo.
|
|
2
|
+
import { c as createLogger, i as iife, m as mutex, r as retry, a as isHexEqual } from './shared/univo.Dxj7VaSK.mjs';
|
|
3
3
|
|
|
4
4
|
function defineBlockchain(opts) {
|
|
5
5
|
const log = createLogger({ quiet: opts.quiet });
|
|
@@ -145,37 +145,6 @@ function realtime(opts) {
|
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
147
|
log.debug("Subscribed unfinalized chain to new heads");
|
|
148
|
-
let chainFinalizedHeight = hexToNumber(chainFinalizedBlock.number);
|
|
149
|
-
async function writeFinalizedHead(nextFinalizedBlock) {
|
|
150
|
-
const nextFinalizedHeight = hexToNumber(nextFinalizedBlock.number);
|
|
151
|
-
const newFinalizedHeads = unfinalized.chain.filter((head) => {
|
|
152
|
-
if (hexToNumber(head.number) > chainFinalizedHeight && hexToNumber(head.number) <= nextFinalizedHeight) {
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}).map((head) => {
|
|
157
|
-
return { chain, ...head };
|
|
158
|
-
});
|
|
159
|
-
if (newFinalizedHeads.length === 0) {
|
|
160
|
-
return log.debug("No new finalized heads to process");
|
|
161
|
-
}
|
|
162
|
-
log.debug(`Processing ${newFinalizedHeads.length} finalized head(s) in parallel`);
|
|
163
|
-
const promises = newFinalizedHeads.map(async (head) => {
|
|
164
|
-
try {
|
|
165
|
-
log.debug("Received finalized head");
|
|
166
|
-
await opts.indexer.request({ params: [head], method: "public_writeFinalizedHead" });
|
|
167
|
-
log.debug("Delivered finalized head");
|
|
168
|
-
} catch (error) {
|
|
169
|
-
if (error instanceof Error) {
|
|
170
|
-
log.warn(`Failed to write finalized head: ${error.message}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
await Promise.allSettled(promises);
|
|
175
|
-
log.debug(`Processed ${newFinalizedHeads.length} finalized head(s) in parallel`);
|
|
176
|
-
chainFinalizedHeight = nextFinalizedHeight;
|
|
177
|
-
await unfinalized.prune(nextFinalizedBlock);
|
|
178
|
-
}
|
|
179
148
|
async function finalize() {
|
|
180
149
|
try {
|
|
181
150
|
log.debug("Finalizing indexer...");
|
|
@@ -183,11 +152,12 @@ function realtime(opts) {
|
|
|
183
152
|
log.debug("Indexer finalized");
|
|
184
153
|
} catch (error) {
|
|
185
154
|
if (error instanceof Error) {
|
|
186
|
-
log.warn(`Failed to
|
|
155
|
+
log.warn(`Failed to finalize ${error.message}`);
|
|
187
156
|
}
|
|
188
157
|
}
|
|
189
158
|
}
|
|
190
159
|
const mutex_finalize = mutex(finalize);
|
|
160
|
+
let chainFinalizedHeight = hexToNumber(chainFinalizedBlock.number);
|
|
191
161
|
async function poll() {
|
|
192
162
|
try {
|
|
193
163
|
log.debug("Polling for finalized height...");
|
|
@@ -195,7 +165,34 @@ function realtime(opts) {
|
|
|
195
165
|
method: "eth_getBlockByNumber",
|
|
196
166
|
params: ["finalized", false]
|
|
197
167
|
});
|
|
198
|
-
|
|
168
|
+
const nextFinalizedHeight = hexToNumber(finalizedBlock.number);
|
|
169
|
+
const newFinalizedHeads = unfinalized.chain.filter((head) => {
|
|
170
|
+
if (hexToNumber(head.number) > chainFinalizedHeight && hexToNumber(head.number) <= nextFinalizedHeight) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}).map((head) => {
|
|
175
|
+
return { chain, ...head };
|
|
176
|
+
});
|
|
177
|
+
if (newFinalizedHeads.length === 0) {
|
|
178
|
+
return log.debug("No new finalized heads to process");
|
|
179
|
+
}
|
|
180
|
+
log.debug(`Processing ${newFinalizedHeads.length} finalized head(s) in parallel`);
|
|
181
|
+
const promises = newFinalizedHeads.map(async (head) => {
|
|
182
|
+
try {
|
|
183
|
+
log.debug("Received finalized head");
|
|
184
|
+
await opts.indexer.request({ params: [head], method: "public_writeFinalizedHead" });
|
|
185
|
+
log.debug("Delivered finalized head");
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (error instanceof Error) {
|
|
188
|
+
log.warn(`Failed to write finalized head: ${error.message}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
await Promise.allSettled(promises);
|
|
193
|
+
log.debug(`Processed ${newFinalizedHeads.length} finalized head(s) in parallel`);
|
|
194
|
+
chainFinalizedHeight = nextFinalizedHeight;
|
|
195
|
+
await unfinalized.prune({
|
|
199
196
|
hash: finalizedBlock.hash,
|
|
200
197
|
number: finalizedBlock.number,
|
|
201
198
|
parent_hash: finalizedBlock.parentHash
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ws from 'ws';
|
|
2
2
|
import { WebSocket } from 'partysocket';
|
|
3
|
-
import { f as compress, g as raise, c as createLogger, m as mutex } from './univo.
|
|
3
|
+
import { f as compress, g as raise, c as createLogger, m as mutex } from './univo.Dxj7VaSK.mjs';
|
|
4
4
|
|
|
5
5
|
function createException(message) {
|
|
6
6
|
return `univo:${message}`;
|
package/dist/transport.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'ws';
|
|
2
2
|
import 'partysocket';
|
|
3
|
-
export { h as http, l as local, w as wss } from './shared/univo.
|
|
4
|
-
import './shared/univo.
|
|
3
|
+
export { h as http, l as local, w as wss } from './shared/univo.BlbeUAWT.mjs';
|
|
4
|
+
import './shared/univo.Dxj7VaSK.mjs';
|