univo 0.1.18 → 0.1.19
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/client.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/realtime.d.mts +7 -1
- package/dist/realtime.d.ts +7 -1
- package/dist/realtime.mjs +96 -44
- package/dist/shared/{univo.mtzSyY24.mjs → univo.DSp9mW7b.mjs} +2 -2
- 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 './client.mjs';
|
|
8
|
-
import { c as createLogger, v as version, l as name } from './shared/univo.
|
|
8
|
+
import { c as createLogger, v as version, l as name } from './shared/univo.DSp9mW7b.mjs';
|
|
9
9
|
|
|
10
10
|
const log = createLogger({ quiet: false });
|
|
11
11
|
const dev = defineCommand({
|
package/dist/client.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as createException, o as compress,
|
|
1
|
+
import { b as createException, o as compress, k as raise, g as getException } from './shared/univo.DSp9mW7b.mjs';
|
|
2
2
|
|
|
3
3
|
function http(url, opts = {}) {
|
|
4
4
|
return {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as createLogger, d as decompress, a as decoder, b as createException, g as getException, h as hexToNumber, i as isAddressEqual, e as catchException, r as retry, v as version, n as nonNullable, f as getSignature } from './shared/univo.
|
|
1
|
+
import { c as createLogger, d as decompress, a as decoder, b as createException, g as getException, h as hexToNumber, i as isAddressEqual, e as catchException, r as retry, v as version, n as nonNullable, f as getSignature } from './shared/univo.DSp9mW7b.mjs';
|
|
2
2
|
|
|
3
3
|
function matchFilter(block, filter) {
|
|
4
4
|
if (!chainValid(block, filter)) return false;
|
package/dist/realtime.d.mts
CHANGED
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
* Transport -----------------------------------------------------------------------------------------------------------------------------------
|
|
3
3
|
*/
|
|
4
4
|
type Transport = {
|
|
5
|
+
/**
|
|
6
|
+
* Performs as JSON RPC request and returns the result
|
|
7
|
+
*/
|
|
5
8
|
request(opts: {
|
|
6
9
|
method: string;
|
|
7
10
|
params: any[];
|
|
8
11
|
}): Promise<any>;
|
|
9
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Subscribes to specific event types and returns a function to unsubscribe.
|
|
14
|
+
*/
|
|
15
|
+
subscribe(param: "newHeads", handler: (message: any) => void): Promise<{
|
|
10
16
|
unsubscribe(): Promise<void>;
|
|
11
17
|
}>;
|
|
12
18
|
};
|
package/dist/realtime.d.ts
CHANGED
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
* Transport -----------------------------------------------------------------------------------------------------------------------------------
|
|
3
3
|
*/
|
|
4
4
|
type Transport = {
|
|
5
|
+
/**
|
|
6
|
+
* Performs as JSON RPC request and returns the result
|
|
7
|
+
*/
|
|
5
8
|
request(opts: {
|
|
6
9
|
method: string;
|
|
7
10
|
params: any[];
|
|
8
11
|
}): Promise<any>;
|
|
9
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Subscribes to specific event types and returns a function to unsubscribe.
|
|
14
|
+
*/
|
|
15
|
+
subscribe(param: "newHeads", handler: (message: any) => void): Promise<{
|
|
10
16
|
unsubscribe(): Promise<void>;
|
|
11
17
|
}>;
|
|
12
18
|
};
|
package/dist/realtime.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import WS from 'ws';
|
|
2
2
|
import { WebSocket } from 'partysocket';
|
|
3
3
|
import { http } from './client.mjs';
|
|
4
|
-
import { c as createLogger, r as retry, h as hexToNumber,
|
|
4
|
+
import { j as assert, c as createLogger, r as retry, h as hexToNumber, k as raise, m as mutex } from './shared/univo.DSp9mW7b.mjs';
|
|
5
5
|
|
|
6
6
|
function createSocket(url, opts) {
|
|
7
7
|
const ws = new WebSocket(url, [], { WebSocket: WS });
|
|
@@ -13,67 +13,119 @@ function createSocket(url, opts) {
|
|
|
13
13
|
return ws;
|
|
14
14
|
}
|
|
15
15
|
function defineTransport(url) {
|
|
16
|
+
assert(url.startsWith("wss://"), "Websocket connections must start with `wss://`");
|
|
16
17
|
let id = 0;
|
|
17
18
|
const requests = /* @__PURE__ */ new Map();
|
|
19
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
20
|
+
const params = /* @__PURE__ */ new Map();
|
|
21
|
+
const socket = createSocket(url, {
|
|
22
|
+
async onError(cause) {
|
|
23
|
+
console.error(new Error("Socket error", { cause }));
|
|
24
|
+
},
|
|
25
|
+
async onOpen() {
|
|
26
|
+
if (subscriptions.size === 0) return;
|
|
27
|
+
const params2 = [];
|
|
28
|
+
for (const [id2, subscription] of subscriptions) {
|
|
29
|
+
params2.push(subscription.param);
|
|
30
|
+
request({ method: "eth_unsubscribe", params: [id2] }).catch(() => {
|
|
31
|
+
console.warn("Failed to cancel old susbcription");
|
|
32
|
+
});
|
|
33
|
+
subscriptions.delete(id2);
|
|
34
|
+
}
|
|
35
|
+
for (const param of params2) {
|
|
36
|
+
request({ method: "eth_subscribe", params: [param] }).then((id2) => {
|
|
37
|
+
subscriptions.set(id2, { param, latest: Date.now() });
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async onMessage(event) {
|
|
42
|
+
const data = JSON.parse(event.data);
|
|
43
|
+
if (data.method === "eth_subscription") {
|
|
44
|
+
const subscription = subscriptions.get(data.params.subscription);
|
|
45
|
+
if (subscription === void 0) {
|
|
46
|
+
return await request({ method: "eth_unsubscribe", params: [data.params.subscription] }).catch(() => {
|
|
47
|
+
console.warn("Failed to unsubscribe stale subscription");
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const handlers = params.get(subscription.param);
|
|
51
|
+
if (handlers === void 0) {
|
|
52
|
+
return await request({ method: "eth_unsubscribe", params: [data.params.subscription] }).catch(() => {
|
|
53
|
+
console.warn("Failed to unsubscribe stale subscription");
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
for (const handler2 of handlers) {
|
|
57
|
+
try {
|
|
58
|
+
handler2(data.params.result);
|
|
59
|
+
} catch (cause) {
|
|
60
|
+
console.error(new Error("Handler error", { cause }));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
subscription.latest = Date.now();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const handler = requests.get(data.id);
|
|
67
|
+
if (handler === void 0) {
|
|
68
|
+
return console.warn(`Received unknown response for request id ${data.id}...`);
|
|
69
|
+
}
|
|
70
|
+
return handler(data.result);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
18
73
|
async function request(opts) {
|
|
19
74
|
return await new Promise((resolve) => {
|
|
20
75
|
const body = Object.assign({ id: id++ }, opts);
|
|
21
|
-
requests.set(body.id, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
resolve(data);
|
|
25
|
-
}
|
|
76
|
+
requests.set(body.id, (data) => {
|
|
77
|
+
requests.delete(body.id);
|
|
78
|
+
resolve(data);
|
|
26
79
|
});
|
|
27
80
|
socket.send(JSON.stringify(body));
|
|
28
81
|
});
|
|
29
82
|
}
|
|
30
|
-
const subscriptions = /* @__PURE__ */ new Map();
|
|
31
83
|
async function subscribe(param, handler) {
|
|
32
|
-
const
|
|
33
|
-
|
|
84
|
+
const handlers = params.get(param);
|
|
85
|
+
if (handlers === void 0) {
|
|
86
|
+
const handlers2 = (/* @__PURE__ */ new Set()).add(handler);
|
|
87
|
+
params.set(param, handlers2);
|
|
88
|
+
const id2 = await request({ method: "eth_subscribe", params: [param] }).catch((cause) => {
|
|
89
|
+
throw new Error(`Failed to initialise subscription for param ${param}`, { cause });
|
|
90
|
+
});
|
|
91
|
+
subscriptions.set(id2, { param, latest: Date.now() });
|
|
92
|
+
} else {
|
|
93
|
+
handlers.add(handler);
|
|
94
|
+
}
|
|
34
95
|
return {
|
|
35
96
|
async unsubscribe() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
const socket = createSocket(url, {
|
|
43
|
-
onError(cause) {
|
|
44
|
-
console.error(new Error("Socket error", { cause }));
|
|
45
|
-
},
|
|
46
|
-
onOpen() {
|
|
47
|
-
if (subscriptions.size) {
|
|
48
|
-
const handlers = [];
|
|
49
|
-
for (const [id2, subscription] of subscriptions) {
|
|
50
|
-
handlers.push(subscription);
|
|
51
|
-
request({ method: "eth_unsubscribe", params: [id2] }).catch(() => {
|
|
52
|
-
});
|
|
53
|
-
subscriptions.delete(id2);
|
|
97
|
+
const handlers2 = params.get(param);
|
|
98
|
+
if (handlers2 === void 0) {
|
|
99
|
+
return console.warn("Param already unsubscribed...");
|
|
54
100
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
101
|
+
handlers2.delete(handler);
|
|
102
|
+
if (handlers2.size === 0) {
|
|
103
|
+
await request({ method: "eth_unsubscribe", params: [id] }).catch(() => {
|
|
104
|
+
console.warn("Failed to unsubscribe unused subscription");
|
|
58
105
|
});
|
|
59
106
|
}
|
|
60
107
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function healthcheck() {
|
|
111
|
+
const params2 = [];
|
|
112
|
+
for (const [id2, subscription] of subscriptions) {
|
|
113
|
+
if (Date.now() - subscription.latest > 60 * 1e3) {
|
|
114
|
+
params2.push(subscription.param);
|
|
115
|
+
request({ method: "eth_unsubscribe", params: [id2] }).catch(() => {
|
|
116
|
+
console.warn("Failed to cancel old susbcription");
|
|
117
|
+
});
|
|
118
|
+
subscriptions.delete(id2);
|
|
119
|
+
console.warn(`Subscription ${id2} failed health check, reinitialising..`);
|
|
72
120
|
}
|
|
73
|
-
const _request = requests.get(data.id);
|
|
74
|
-
if (_request) _request.handler(data.result);
|
|
75
121
|
}
|
|
76
|
-
|
|
122
|
+
for (const param of params2) {
|
|
123
|
+
request({ method: "eth_subscribe", params: [param] }).then((id2) => {
|
|
124
|
+
subscriptions.set(id2, { param, latest: Date.now() });
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
setInterval(healthcheck, 60 * 1e3);
|
|
77
129
|
return { request, subscribe };
|
|
78
130
|
}
|
|
79
131
|
function defineBlockchain(opts) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const name = "univo";
|
|
2
|
-
const version = "0.1.
|
|
2
|
+
const version = "0.1.19";
|
|
3
3
|
|
|
4
4
|
function createException(message) {
|
|
5
5
|
return `univo:${message}`;
|
|
@@ -104,4 +104,4 @@ async function decompress(input) {
|
|
|
104
104
|
}
|
|
105
105
|
const decoder = new TextDecoder();
|
|
106
106
|
|
|
107
|
-
export { decoder as a, createException as b, createLogger as c, decompress as d, catchException as e, getSignature as f, getException as g, hexToNumber as h, isAddressEqual as i,
|
|
107
|
+
export { decoder as a, createException as b, createLogger as c, decompress as d, catchException as e, getSignature as f, getException as g, hexToNumber as h, isAddressEqual as i, assert as j, raise as k, name as l, mutex as m, nonNullable as n, compress as o, retry as r, version as v };
|