univo 0.1.18 → 0.2.0
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 +19 -18
- package/dist/index.d.mts +120 -39
- package/dist/index.d.ts +120 -39
- package/dist/index.mjs +366 -167
- package/dist/realtime.d.mts +23 -45
- package/dist/realtime.d.ts +23 -45
- package/dist/realtime.mjs +124 -150
- package/dist/shared/univo.BWa1smi3.d.ts +131 -0
- package/dist/shared/univo.BZ_L9bc2.d.mts +131 -0
- package/dist/shared/univo.C0flyVee.mjs +21 -0
- package/dist/shared/univo.HDazcQ9A.mjs +92 -0
- package/dist/transport.d.mts +3 -0
- package/dist/transport.d.ts +3 -0
- package/dist/transport.mjs +172 -0
- package/package.json +7 -4
- package/dist/client.d.mts +0 -24
- package/dist/client.d.ts +0 -24
- package/dist/client.mjs +0 -34
- package/dist/shared/univo.mtzSyY24.mjs +0 -107
package/dist/cli.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import ws from 'ws';
|
|
3
3
|
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 { http } from './
|
|
8
|
-
import { c as createLogger, v as version,
|
|
7
|
+
import { http } from './transport.mjs';
|
|
8
|
+
import { c as createLogger, v as version, g as name } from './shared/univo.HDazcQ9A.mjs';
|
|
9
|
+
import './shared/univo.C0flyVee.mjs';
|
|
9
10
|
|
|
10
11
|
const log = createLogger({ quiet: false });
|
|
11
12
|
const dev = defineCommand({
|
|
@@ -24,39 +25,39 @@ const dev = defineCommand({
|
|
|
24
25
|
if (localSigningKey === void 0) throw new Error("Please provide a UNIVO_SIGNING_KEY environment variable");
|
|
25
26
|
const client = http(ctx.args.url, { signingKey: localSigningKey });
|
|
26
27
|
const [events, metadata] = await Promise.all([
|
|
27
|
-
client.request({
|
|
28
|
-
client.request({
|
|
28
|
+
client.request({ method: "private_getEvents", params: [] }),
|
|
29
|
+
client.request({ method: "private_getMetadata", params: [] })
|
|
29
30
|
]);
|
|
30
|
-
if (events.error) throw new Error(`Failed to connect to ${ctx.args.url}. Check that your server is running on the correct port.`);
|
|
31
|
-
if (metadata.error) throw new Error(`Failed to connect to ${ctx.args.url}. Check that your server is running on the correct port.`);
|
|
32
31
|
const remoteSigningKey = crypto.randomUUID();
|
|
33
32
|
const url = `https://tunnel-univo.app/v1/${crypto.randomUUID()}`;
|
|
34
33
|
const endpoint = {
|
|
35
34
|
url,
|
|
36
|
-
events
|
|
37
|
-
metadata
|
|
35
|
+
events,
|
|
36
|
+
metadata,
|
|
38
37
|
signing_key: remoteSigningKey
|
|
39
38
|
};
|
|
40
39
|
const data = btoa(JSON.stringify(endpoint));
|
|
41
40
|
await open(`https://univo.app/dev/${data}`);
|
|
42
|
-
const ws = new WebSocket(url, [], { WebSocket:
|
|
43
|
-
ws.binaryType = "arraybuffer";
|
|
44
|
-
ws.onerror = (event) => log.error(event.message);
|
|
45
|
-
ws.onopen = () => log.info(`Dev server started for ${ctx.args.url}`);
|
|
46
|
-
ws.onclose = () => log.info(`Dev server closed for ${ctx.args.url}`);
|
|
47
|
-
ws.onmessage = async (event) => {
|
|
41
|
+
const ws$1 = new WebSocket(url, [], { WebSocket: ws });
|
|
42
|
+
ws$1.binaryType = "arraybuffer";
|
|
43
|
+
ws$1.onerror = (event) => log.error(event.message);
|
|
44
|
+
ws$1.onopen = () => log.info(`Dev server started for ${ctx.args.url}`);
|
|
45
|
+
ws$1.onclose = () => log.info(`Dev server closed for ${ctx.args.url}`);
|
|
46
|
+
ws$1.onmessage = async (event) => {
|
|
48
47
|
try {
|
|
49
48
|
const request = JSON.parse(event.data);
|
|
50
49
|
log.info(`Received request ${request.id}:${request.method}`);
|
|
51
50
|
const response = await client.request(request);
|
|
52
|
-
ws.send(JSON.stringify(response));
|
|
51
|
+
ws$1.send(JSON.stringify(response));
|
|
53
52
|
} catch (error) {
|
|
54
53
|
const response = { jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid request" } };
|
|
55
|
-
ws.send(JSON.stringify(response));
|
|
54
|
+
ws$1.send(JSON.stringify(response));
|
|
56
55
|
}
|
|
57
56
|
};
|
|
58
57
|
} catch (error) {
|
|
59
|
-
if (error instanceof Error)
|
|
58
|
+
if (error instanceof Error) {
|
|
59
|
+
return log.error(error.message);
|
|
60
|
+
}
|
|
60
61
|
throw error;
|
|
61
62
|
}
|
|
62
63
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,50 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
type Flatten<T> = {
|
|
3
|
-
[K in keyof T as CamelToSnake<Extract<K, string>>]: T[K];
|
|
4
|
-
};
|
|
1
|
+
import { Storage } from 'unstorage';
|
|
5
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Block -----------------------------------------------------------------------------------------------------------------------------------
|
|
5
|
+
*/
|
|
6
6
|
type Block = {
|
|
7
7
|
eth_chainId: `0x${string}`;
|
|
8
|
-
|
|
8
|
+
eth_getBlockByNumber: {
|
|
9
9
|
hash: `0x${string}`;
|
|
10
10
|
number: `0x${string}`;
|
|
11
|
+
parentHash: `0x${string}`;
|
|
11
12
|
};
|
|
12
13
|
eth_getBlockReceipts: Array<{
|
|
14
|
+
blockHash: `0x${string}`;
|
|
13
15
|
logs: Array<{
|
|
14
16
|
address: `0x${string}`;
|
|
15
17
|
topics: `0x${string}`[];
|
|
16
18
|
}>;
|
|
17
19
|
}>;
|
|
18
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Filters -----------------------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
*/
|
|
19
24
|
type Filter = {
|
|
20
|
-
/**
|
|
25
|
+
/** Index blocks with this chain id */
|
|
21
26
|
chain: number;
|
|
22
|
-
/**
|
|
27
|
+
/** Index blocks from this start block (inclusive) */
|
|
23
28
|
fromBlock: number;
|
|
24
|
-
/**
|
|
29
|
+
/** Index blocks until this stop block (inclusive) */
|
|
25
30
|
toBlock?: number;
|
|
26
|
-
/**
|
|
31
|
+
/** Index blocks where this event topic was emitted */
|
|
27
32
|
event?: `0x${string}`;
|
|
28
|
-
/**
|
|
33
|
+
/** Index blocks that involve this address */
|
|
29
34
|
address?: `0x${string}`;
|
|
30
35
|
};
|
|
31
36
|
declare function matchFilter(block: Block, filter: Filter): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Events -----------------------------------------------------------------------------------------------------------------------------------
|
|
39
|
+
*/
|
|
32
40
|
type Event<TBlock, TEvent> = {
|
|
33
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* A human-readable identifier for the event.
|
|
43
|
+
*/
|
|
34
44
|
id: string;
|
|
35
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Filters let you define what specific blocks you want this event to index.
|
|
47
|
+
*
|
|
48
|
+
* Blockchains are massive datasets and most of the time we are only ever interested in small portions of it.
|
|
49
|
+
* Sometimes that can be specific events like ERC20 transfers and other times it could be all events emitted
|
|
50
|
+
* by a specific contract. Filters provide a simple way for an event to define exactly which blocks we want
|
|
51
|
+
* to index.
|
|
52
|
+
*
|
|
53
|
+
* Filters reduce costs and improve backfill performance by ensuring we only index the blocks we need and
|
|
54
|
+
* ignore the blocks that don't have the data we are interested in.
|
|
55
|
+
*
|
|
56
|
+
* By default your event will not index any blocks, you must opt-in to indexing by providing atleast one filter.
|
|
57
|
+
*
|
|
58
|
+
* Each property in the filter operates like an AND statement. For example, if you specifiy an `address` and
|
|
59
|
+
* an `event` it implies that you only want to index blocks where the specific `address` emitted the specific
|
|
60
|
+
* `event` topic provided.
|
|
61
|
+
*
|
|
62
|
+
* However, when multiple filters are defined for a given event those filters operate like an OR statement. For
|
|
63
|
+
* example, if we define a second filter looking for a different `address` and `event` our event will now index
|
|
64
|
+
* any block that matches either the first filter or the second filter.
|
|
65
|
+
*
|
|
66
|
+
* Note that filters are a rudimentary method to dramatically reduce the number of blocks your application needs
|
|
67
|
+
* to index. Any advanced filtering should be performed in the event `handler` itself.
|
|
68
|
+
*/
|
|
36
69
|
filters: Filter[];
|
|
37
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Synchronously transforms a raw block into a list of events.
|
|
72
|
+
*
|
|
73
|
+
* When a block matches any of filters defined by your event it will be passed to this function to be synchronously
|
|
74
|
+
* transformed into a list of structured events.
|
|
75
|
+
*
|
|
76
|
+
* The shape of the input `block` is determined by the return value of `getBlock` function provided to your `indexer`.
|
|
77
|
+
*
|
|
78
|
+
* The returned output value should be an array containg any valid JavaScript values. Each event that you return from
|
|
79
|
+
* your handler should not depend on any information outside of the input block data. It should directly map a given
|
|
80
|
+
* input (the raw block) to a given output (structured events). This ensures that handler remains idempotent and that
|
|
81
|
+
* repeated calls with the same input block produce the same output events.
|
|
82
|
+
*/
|
|
38
83
|
handler: (block: TBlock) => TEvent[];
|
|
39
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Storage adapter to persist events in your off-chain storage.
|
|
86
|
+
*/
|
|
40
87
|
storage: {
|
|
88
|
+
/**
|
|
89
|
+
* Upserts a batch of events into your storage system.
|
|
90
|
+
*
|
|
91
|
+
* After a block is transformed into a list of structured events by your `handler` function, that batch
|
|
92
|
+
* is passed to this `upsert` function so they can be upserted into your storage system.
|
|
93
|
+
*
|
|
94
|
+
* This function must be idempotent. Functionally, this means that if the same batch of events is upserted
|
|
95
|
+
* multiple times it only produces a single set of events in your storage system.
|
|
96
|
+
*/
|
|
41
97
|
upsert: (events: TEvent[]) => Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Deletes a batch of events from your storage system.
|
|
100
|
+
*
|
|
101
|
+
* When your indexer encounters a chain reorganisation, this `delete` function will be invoked with the
|
|
102
|
+
* same batch of events created by that reorganised block. This ensures that any events that were previously
|
|
103
|
+
* upserted into your storage system that are no longer part of the canonical chain are safely removed.
|
|
104
|
+
*/
|
|
105
|
+
delete?: (events: TEvent[]) => Promise<void>;
|
|
42
106
|
};
|
|
43
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Indexer -----------------------------------------------------------------------------------------------------------------------------------
|
|
110
|
+
*/
|
|
44
111
|
type Head = {
|
|
45
112
|
hash: `0x${string}`;
|
|
46
113
|
chain: `0x${string}`;
|
|
47
114
|
number: `0x${string}`;
|
|
115
|
+
parentHash: `0x${string}`;
|
|
48
116
|
};
|
|
49
117
|
type Metadata = {
|
|
50
118
|
version: string;
|
|
@@ -60,49 +128,62 @@ type Result = {
|
|
|
60
128
|
};
|
|
61
129
|
type IndexerOptions<TBlock> = {
|
|
62
130
|
/**
|
|
131
|
+
* Silences all logs including errors.
|
|
132
|
+
*
|
|
63
133
|
* Logs are emitted based on the environment LOG_LEVEL. Set `quiet: true` to surpress all logs.
|
|
64
134
|
* Available log options are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
|
|
65
135
|
*/
|
|
66
136
|
quiet?: boolean;
|
|
67
137
|
/**
|
|
68
138
|
* Request signing key
|
|
139
|
+
*
|
|
140
|
+
* Facilitates secure communication with a trusted source like the univo dashboard.
|
|
69
141
|
*/
|
|
70
142
|
signingKey: string;
|
|
71
143
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
144
|
+
* Storage interface for durably persisting indexer metadata.
|
|
145
|
+
*
|
|
146
|
+
* This uses the unified key-value storage API from unstorage. Install the `unstorage` dependency
|
|
147
|
+
* and provide the return value of your `createStorage()` call. Check out the documentation for
|
|
148
|
+
* a full list of [supported storage drivers](https://unstorage.unjs.io/drivers).
|
|
149
|
+
*
|
|
150
|
+
* Functionally, storing metadata is fundamental to ensure the correct operation of your indexer. It
|
|
151
|
+
* ensures that you indexer recovers from downtime and ensures that all blocks are processed correctly during
|
|
152
|
+
* chain reorganisations.
|
|
153
|
+
*/
|
|
154
|
+
metadataStorage: Storage;
|
|
155
|
+
/**
|
|
156
|
+
* Loads raw block data in realtime from a trusted set of RPC sources.
|
|
157
|
+
*
|
|
158
|
+
* Note that historical backfills do not use this function to load block data.
|
|
159
|
+
*
|
|
160
|
+
* The response from this function determines the input data to your `handler` functions in each event.
|
|
161
|
+
* Generally, the shape is a list of RPC methods with their corresponding value from an RPC node. This
|
|
162
|
+
* generic format allows you support the full range of RPC data available to you from your node. This
|
|
163
|
+
* flexibility is important in cases where some methods are supported on specific chains only.
|
|
164
|
+
*
|
|
165
|
+
* Note that there is a minimum set of RPC methods expected on the response notably `eth_chainId`,
|
|
166
|
+
* `eth_getBlockByNumber` and `eth_getBlockReceipts`. These are expected so that we can safely match
|
|
167
|
+
* each block processed against your event filters.
|
|
168
|
+
*
|
|
169
|
+
* Note that we provide only the block number to look up block data. During a chain reorganisation, this
|
|
170
|
+
* makes it possible for different RPC calls to return data for different block hashes. We manually verify
|
|
171
|
+
* that all methods return the expected block hash. However, for any custom methods you add you must manually
|
|
172
|
+
* verify the block hash is consistent with the other known methods.
|
|
74
173
|
*/
|
|
75
|
-
getBlock: (block:
|
|
174
|
+
getBlock: (block: {
|
|
175
|
+
chain: `0x${string}`;
|
|
176
|
+
number: string;
|
|
177
|
+
}) => Promise<TBlock | null>;
|
|
76
178
|
};
|
|
77
179
|
type Indexer<TBlock> = {
|
|
78
180
|
fetch: (req: Request) => Promise<Response>;
|
|
79
181
|
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
80
182
|
};
|
|
81
|
-
type Rpc = {
|
|
82
|
-
public_writeBlocks(endpoint: string, heads: Head[]): Promise<void>;
|
|
83
|
-
private_getMetadata(): Promise<Metadata>;
|
|
84
|
-
private_getEvents(): Promise<{
|
|
85
|
-
id: string;
|
|
86
|
-
filters: Flatten<Filter>[];
|
|
87
|
-
}[]>;
|
|
88
|
-
private_writeEvents(params: {
|
|
89
|
-
events: string[];
|
|
90
|
-
blocks: Block[];
|
|
91
|
-
}): Promise<{
|
|
92
|
-
failures: Result[];
|
|
93
|
-
}>;
|
|
94
|
-
private_writeEventsAndGetKeys(params: {
|
|
95
|
-
events: string[];
|
|
96
|
-
block: Block;
|
|
97
|
-
}): Promise<{
|
|
98
|
-
results: Result[];
|
|
99
|
-
keys: string[];
|
|
100
|
-
}>;
|
|
101
|
-
};
|
|
102
183
|
declare function indexer<TBlock extends Block>(opts: IndexerOptions<TBlock>): {
|
|
103
184
|
fetch: (req: Request) => Promise<Response>;
|
|
104
185
|
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
105
186
|
};
|
|
106
187
|
|
|
107
188
|
export { indexer, matchFilter };
|
|
108
|
-
export type { Event, Indexer,
|
|
189
|
+
export type { Block, Event, Filter, Head, Indexer, Metadata, Result };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,50 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
type Flatten<T> = {
|
|
3
|
-
[K in keyof T as CamelToSnake<Extract<K, string>>]: T[K];
|
|
4
|
-
};
|
|
1
|
+
import { Storage } from 'unstorage';
|
|
5
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Block -----------------------------------------------------------------------------------------------------------------------------------
|
|
5
|
+
*/
|
|
6
6
|
type Block = {
|
|
7
7
|
eth_chainId: `0x${string}`;
|
|
8
|
-
|
|
8
|
+
eth_getBlockByNumber: {
|
|
9
9
|
hash: `0x${string}`;
|
|
10
10
|
number: `0x${string}`;
|
|
11
|
+
parentHash: `0x${string}`;
|
|
11
12
|
};
|
|
12
13
|
eth_getBlockReceipts: Array<{
|
|
14
|
+
blockHash: `0x${string}`;
|
|
13
15
|
logs: Array<{
|
|
14
16
|
address: `0x${string}`;
|
|
15
17
|
topics: `0x${string}`[];
|
|
16
18
|
}>;
|
|
17
19
|
}>;
|
|
18
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Filters -----------------------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
*/
|
|
19
24
|
type Filter = {
|
|
20
|
-
/**
|
|
25
|
+
/** Index blocks with this chain id */
|
|
21
26
|
chain: number;
|
|
22
|
-
/**
|
|
27
|
+
/** Index blocks from this start block (inclusive) */
|
|
23
28
|
fromBlock: number;
|
|
24
|
-
/**
|
|
29
|
+
/** Index blocks until this stop block (inclusive) */
|
|
25
30
|
toBlock?: number;
|
|
26
|
-
/**
|
|
31
|
+
/** Index blocks where this event topic was emitted */
|
|
27
32
|
event?: `0x${string}`;
|
|
28
|
-
/**
|
|
33
|
+
/** Index blocks that involve this address */
|
|
29
34
|
address?: `0x${string}`;
|
|
30
35
|
};
|
|
31
36
|
declare function matchFilter(block: Block, filter: Filter): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Events -----------------------------------------------------------------------------------------------------------------------------------
|
|
39
|
+
*/
|
|
32
40
|
type Event<TBlock, TEvent> = {
|
|
33
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* A human-readable identifier for the event.
|
|
43
|
+
*/
|
|
34
44
|
id: string;
|
|
35
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Filters let you define what specific blocks you want this event to index.
|
|
47
|
+
*
|
|
48
|
+
* Blockchains are massive datasets and most of the time we are only ever interested in small portions of it.
|
|
49
|
+
* Sometimes that can be specific events like ERC20 transfers and other times it could be all events emitted
|
|
50
|
+
* by a specific contract. Filters provide a simple way for an event to define exactly which blocks we want
|
|
51
|
+
* to index.
|
|
52
|
+
*
|
|
53
|
+
* Filters reduce costs and improve backfill performance by ensuring we only index the blocks we need and
|
|
54
|
+
* ignore the blocks that don't have the data we are interested in.
|
|
55
|
+
*
|
|
56
|
+
* By default your event will not index any blocks, you must opt-in to indexing by providing atleast one filter.
|
|
57
|
+
*
|
|
58
|
+
* Each property in the filter operates like an AND statement. For example, if you specifiy an `address` and
|
|
59
|
+
* an `event` it implies that you only want to index blocks where the specific `address` emitted the specific
|
|
60
|
+
* `event` topic provided.
|
|
61
|
+
*
|
|
62
|
+
* However, when multiple filters are defined for a given event those filters operate like an OR statement. For
|
|
63
|
+
* example, if we define a second filter looking for a different `address` and `event` our event will now index
|
|
64
|
+
* any block that matches either the first filter or the second filter.
|
|
65
|
+
*
|
|
66
|
+
* Note that filters are a rudimentary method to dramatically reduce the number of blocks your application needs
|
|
67
|
+
* to index. Any advanced filtering should be performed in the event `handler` itself.
|
|
68
|
+
*/
|
|
36
69
|
filters: Filter[];
|
|
37
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Synchronously transforms a raw block into a list of events.
|
|
72
|
+
*
|
|
73
|
+
* When a block matches any of filters defined by your event it will be passed to this function to be synchronously
|
|
74
|
+
* transformed into a list of structured events.
|
|
75
|
+
*
|
|
76
|
+
* The shape of the input `block` is determined by the return value of `getBlock` function provided to your `indexer`.
|
|
77
|
+
*
|
|
78
|
+
* The returned output value should be an array containg any valid JavaScript values. Each event that you return from
|
|
79
|
+
* your handler should not depend on any information outside of the input block data. It should directly map a given
|
|
80
|
+
* input (the raw block) to a given output (structured events). This ensures that handler remains idempotent and that
|
|
81
|
+
* repeated calls with the same input block produce the same output events.
|
|
82
|
+
*/
|
|
38
83
|
handler: (block: TBlock) => TEvent[];
|
|
39
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Storage adapter to persist events in your off-chain storage.
|
|
86
|
+
*/
|
|
40
87
|
storage: {
|
|
88
|
+
/**
|
|
89
|
+
* Upserts a batch of events into your storage system.
|
|
90
|
+
*
|
|
91
|
+
* After a block is transformed into a list of structured events by your `handler` function, that batch
|
|
92
|
+
* is passed to this `upsert` function so they can be upserted into your storage system.
|
|
93
|
+
*
|
|
94
|
+
* This function must be idempotent. Functionally, this means that if the same batch of events is upserted
|
|
95
|
+
* multiple times it only produces a single set of events in your storage system.
|
|
96
|
+
*/
|
|
41
97
|
upsert: (events: TEvent[]) => Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Deletes a batch of events from your storage system.
|
|
100
|
+
*
|
|
101
|
+
* When your indexer encounters a chain reorganisation, this `delete` function will be invoked with the
|
|
102
|
+
* same batch of events created by that reorganised block. This ensures that any events that were previously
|
|
103
|
+
* upserted into your storage system that are no longer part of the canonical chain are safely removed.
|
|
104
|
+
*/
|
|
105
|
+
delete?: (events: TEvent[]) => Promise<void>;
|
|
42
106
|
};
|
|
43
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Indexer -----------------------------------------------------------------------------------------------------------------------------------
|
|
110
|
+
*/
|
|
44
111
|
type Head = {
|
|
45
112
|
hash: `0x${string}`;
|
|
46
113
|
chain: `0x${string}`;
|
|
47
114
|
number: `0x${string}`;
|
|
115
|
+
parentHash: `0x${string}`;
|
|
48
116
|
};
|
|
49
117
|
type Metadata = {
|
|
50
118
|
version: string;
|
|
@@ -60,49 +128,62 @@ type Result = {
|
|
|
60
128
|
};
|
|
61
129
|
type IndexerOptions<TBlock> = {
|
|
62
130
|
/**
|
|
131
|
+
* Silences all logs including errors.
|
|
132
|
+
*
|
|
63
133
|
* Logs are emitted based on the environment LOG_LEVEL. Set `quiet: true` to surpress all logs.
|
|
64
134
|
* Available log options are `DEBUG`, `INFO`, `WARN`, and `ERROR`.
|
|
65
135
|
*/
|
|
66
136
|
quiet?: boolean;
|
|
67
137
|
/**
|
|
68
138
|
* Request signing key
|
|
139
|
+
*
|
|
140
|
+
* Facilitates secure communication with a trusted source like the univo dashboard.
|
|
69
141
|
*/
|
|
70
142
|
signingKey: string;
|
|
71
143
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
144
|
+
* Storage interface for durably persisting indexer metadata.
|
|
145
|
+
*
|
|
146
|
+
* This uses the unified key-value storage API from unstorage. Install the `unstorage` dependency
|
|
147
|
+
* and provide the return value of your `createStorage()` call. Check out the documentation for
|
|
148
|
+
* a full list of [supported storage drivers](https://unstorage.unjs.io/drivers).
|
|
149
|
+
*
|
|
150
|
+
* Functionally, storing metadata is fundamental to ensure the correct operation of your indexer. It
|
|
151
|
+
* ensures that you indexer recovers from downtime and ensures that all blocks are processed correctly during
|
|
152
|
+
* chain reorganisations.
|
|
153
|
+
*/
|
|
154
|
+
metadataStorage: Storage;
|
|
155
|
+
/**
|
|
156
|
+
* Loads raw block data in realtime from a trusted set of RPC sources.
|
|
157
|
+
*
|
|
158
|
+
* Note that historical backfills do not use this function to load block data.
|
|
159
|
+
*
|
|
160
|
+
* The response from this function determines the input data to your `handler` functions in each event.
|
|
161
|
+
* Generally, the shape is a list of RPC methods with their corresponding value from an RPC node. This
|
|
162
|
+
* generic format allows you support the full range of RPC data available to you from your node. This
|
|
163
|
+
* flexibility is important in cases where some methods are supported on specific chains only.
|
|
164
|
+
*
|
|
165
|
+
* Note that there is a minimum set of RPC methods expected on the response notably `eth_chainId`,
|
|
166
|
+
* `eth_getBlockByNumber` and `eth_getBlockReceipts`. These are expected so that we can safely match
|
|
167
|
+
* each block processed against your event filters.
|
|
168
|
+
*
|
|
169
|
+
* Note that we provide only the block number to look up block data. During a chain reorganisation, this
|
|
170
|
+
* makes it possible for different RPC calls to return data for different block hashes. We manually verify
|
|
171
|
+
* that all methods return the expected block hash. However, for any custom methods you add you must manually
|
|
172
|
+
* verify the block hash is consistent with the other known methods.
|
|
74
173
|
*/
|
|
75
|
-
getBlock: (block:
|
|
174
|
+
getBlock: (block: {
|
|
175
|
+
chain: `0x${string}`;
|
|
176
|
+
number: string;
|
|
177
|
+
}) => Promise<TBlock | null>;
|
|
76
178
|
};
|
|
77
179
|
type Indexer<TBlock> = {
|
|
78
180
|
fetch: (req: Request) => Promise<Response>;
|
|
79
181
|
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
80
182
|
};
|
|
81
|
-
type Rpc = {
|
|
82
|
-
public_writeBlocks(endpoint: string, heads: Head[]): Promise<void>;
|
|
83
|
-
private_getMetadata(): Promise<Metadata>;
|
|
84
|
-
private_getEvents(): Promise<{
|
|
85
|
-
id: string;
|
|
86
|
-
filters: Flatten<Filter>[];
|
|
87
|
-
}[]>;
|
|
88
|
-
private_writeEvents(params: {
|
|
89
|
-
events: string[];
|
|
90
|
-
blocks: Block[];
|
|
91
|
-
}): Promise<{
|
|
92
|
-
failures: Result[];
|
|
93
|
-
}>;
|
|
94
|
-
private_writeEventsAndGetKeys(params: {
|
|
95
|
-
events: string[];
|
|
96
|
-
block: Block;
|
|
97
|
-
}): Promise<{
|
|
98
|
-
results: Result[];
|
|
99
|
-
keys: string[];
|
|
100
|
-
}>;
|
|
101
|
-
};
|
|
102
183
|
declare function indexer<TBlock extends Block>(opts: IndexerOptions<TBlock>): {
|
|
103
184
|
fetch: (req: Request) => Promise<Response>;
|
|
104
185
|
event: <TEvent>(event: Event<TBlock, TEvent>) => Event<TBlock, TEvent>;
|
|
105
186
|
};
|
|
106
187
|
|
|
107
188
|
export { indexer, matchFilter };
|
|
108
|
-
export type { Event, Indexer,
|
|
189
|
+
export type { Block, Event, Filter, Head, Indexer, Metadata, Result };
|