@xyo-network/xl1-rest-block-viewer 2.0.12
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/LICENSE +165 -0
- package/README.md +115 -0
- package/dist/neutral/RestBlockViewer.d.ts +169 -0
- package/dist/neutral/RestBlockViewer.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +3 -0
- package/dist/neutral/index.d.ts.map +1 -0
- package/dist/neutral/index.mjs +254 -0
- package/dist/neutral/index.mjs.map +7 -0
- package/dist/neutral/paths.d.ts +28 -0
- package/dist/neutral/paths.d.ts.map +1 -0
- package/package.json +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
[![logo][]](https://xyo.network)
|
|
2
|
+
|
|
3
|
+
# @xyo-network/xl1-rest-block-viewer
|
|
4
|
+
|
|
5
|
+
[![npm-badge][]][npm-link]
|
|
6
|
+
[![license-badge][]][license-link]
|
|
7
|
+
|
|
8
|
+
> A BlockViewer over a statically generated REST file layout — anonymous HTTP reads of immutable chain files, no RPC server required.
|
|
9
|
+
|
|
10
|
+
## About
|
|
11
|
+
|
|
12
|
+
Finalized XL1 blocks and completed steps never change, so the whole chain can be published once as static files (e.g. to a public Cloudflare R2 bucket behind a CDN) and read forever with plain HTTP GETs. `RestBlockViewer` implements the full `BlockViewer` interface against that layout:
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
/chain/head.json ← the one mutable file (current head)
|
|
16
|
+
/block/number/<n>.json ← block by number
|
|
17
|
+
/block/hash/<hash>.json ← block by hash
|
|
18
|
+
/blocks/step/<level>/<index>.json ← completed step summary (all blocks in the frame)
|
|
19
|
+
/payload/<hash>.json ← payload by hash
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The path builders in `paths.ts` are the shared contract between the publisher that writes these files and this viewer that reads them. Every file except the head pointer is immutable, so responses are cached aggressively (in-memory LRU here, CDN/edge in front). `blocksByStep` serves completed steps only — the in-flight tail step has no file and returns `[]`.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { RestBlockViewer } from '@xyo-network/xl1-rest-block-viewer'
|
|
26
|
+
|
|
27
|
+
const viewer = await RestBlockViewer.create({
|
|
28
|
+
baseUrl: 'https://chain.example.com',
|
|
29
|
+
headPollIntervalMs: 10_000, // optional: emit headUpdated as the head advances
|
|
30
|
+
})
|
|
31
|
+
await viewer.start()
|
|
32
|
+
const head = await viewer.currentBlock()
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Reads are anonymous — no S3 client or credentials. Parsed files are validated with the protocol Zod schemas before being returned.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
Using npm:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm i --save @xyo-network/xl1-rest-block-viewer
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Using yarn:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
yarn add @xyo-network/xl1-rest-block-viewer
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Using pnpm:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
pnpm add @xyo-network/xl1-rest-block-viewer
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Using bun:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
bun add @xyo-network/xl1-rest-block-viewer
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## What's Inside
|
|
64
|
+
|
|
65
|
+
- **`RestBlockViewer`** — full `BlockViewer` implementation: blocks by number/hash, walking reads, `currentBlock` head polling with `headUpdated` events, completed-step `blocksByStep`, payloads by hash, and the rate calculations.
|
|
66
|
+
- **`paths.ts`** — the static layout contract (`headPath`, `blockNumberPath`, `blockHashPath`, `blocksStepPath`, `payloadPath`) shared with the publisher.
|
|
67
|
+
|
|
68
|
+
## Building Locally
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
xy build @xyo-network/xl1-rest-block-viewer
|
|
72
|
+
xy test @xyo-network/xl1-rest-block-viewer
|
|
73
|
+
xy lint @xyo-network/xl1-rest-block-viewer
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Maintainers
|
|
77
|
+
|
|
78
|
+
<table>
|
|
79
|
+
<tr>
|
|
80
|
+
<td align="center" valign="top" width="120">
|
|
81
|
+
<a href="https://github.com/arietrouw">
|
|
82
|
+
<img src="https://github.com/arietrouw.png" width="80" height="80" alt="Arie Trouw" /><br />
|
|
83
|
+
<sub><b>Arie Trouw</b></sub>
|
|
84
|
+
</a>
|
|
85
|
+
<br />
|
|
86
|
+
<a href="https://arietrouw.com">arietrouw.com</a>
|
|
87
|
+
</td>
|
|
88
|
+
<td align="center" valign="top" width="120">
|
|
89
|
+
<a href="https://github.com/jonesmac">
|
|
90
|
+
<img src="https://github.com/jonesmac.png" width="80" height="80" alt="Matt Jones" /><br />
|
|
91
|
+
<sub><b>Matt Jones</b></sub>
|
|
92
|
+
</a>
|
|
93
|
+
</td>
|
|
94
|
+
<td align="center" valign="top" width="120">
|
|
95
|
+
<a href="https://github.com/JoelBCarter">
|
|
96
|
+
<img src="https://github.com/JoelBCarter.png" width="80" height="80" alt="Joel Carter" /><br />
|
|
97
|
+
<sub><b>Joel Carter</b></sub>
|
|
98
|
+
</a>
|
|
99
|
+
</td>
|
|
100
|
+
</tr>
|
|
101
|
+
</table>
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
See the [LICENSE](./LICENSE) file (LGPL-3.0-only).
|
|
106
|
+
|
|
107
|
+
## Credits
|
|
108
|
+
|
|
109
|
+
[Made with 🔥 and ❄️ by XYO Foundation](https://xyo.network)
|
|
110
|
+
|
|
111
|
+
[npm-badge]: https://img.shields.io/npm/v/@xyo-network/xl1-rest-block-viewer.svg
|
|
112
|
+
[npm-link]: https://www.npmjs.com/package/@xyo-network/xl1-rest-block-viewer
|
|
113
|
+
[license-badge]: https://img.shields.io/npm/l/@xyo-network/xl1-rest-block-viewer.svg
|
|
114
|
+
[license-link]: ./LICENSE
|
|
115
|
+
[logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { Hash } from '@xylabs/sdk-js';
|
|
2
|
+
import type { Payload, WithHashMeta } from '@xyo-network/sdk-js';
|
|
3
|
+
import { LruCacheMap } from '@xyo-network/xl1-driver-memory';
|
|
4
|
+
import type { BlockRate, BlockViewer, ChainId, SignedHydratedBlockWithHashMeta, SingleTimeConfig, TimeDurations, XL1BlockNumber, XL1BlockRange } from '@xyo-network/xl1-protocol-lib';
|
|
5
|
+
import type { CreatableProviderParams } from '@xyo-network/xl1-protocol-sdk';
|
|
6
|
+
import { AbstractCreatableProvider } from '@xyo-network/xl1-protocol-sdk';
|
|
7
|
+
/** Parameters for RestBlockViewer. */
|
|
8
|
+
export interface RestBlockViewerParams extends CreatableProviderParams {
|
|
9
|
+
/** Base URL of the static chain layout (e.g. a public R2 bucket or CDN domain). */
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/** Optional fetch override (custom agents, auth headers, tests). Defaults to the global fetch. */
|
|
12
|
+
fetchFn?: typeof globalThis.fetch;
|
|
13
|
+
headPollIntervalMs?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A BlockViewer over a statically generated REST file layout (see `paths.ts`).
|
|
17
|
+
*
|
|
18
|
+
* Reads are anonymous HTTP GETs against immutable files, so everything except the head
|
|
19
|
+
* pointer is cached aggressively. `blocksByStep` serves only completed steps — the
|
|
20
|
+
* in-flight tail step has no static file and returns [].
|
|
21
|
+
*/
|
|
22
|
+
export declare class RestBlockViewer extends AbstractCreatableProvider<RestBlockViewerParams, BlockViewer['eventData']> implements BlockViewer {
|
|
23
|
+
static readonly defaultMoniker: "BlockViewer";
|
|
24
|
+
static readonly dependencies: never[];
|
|
25
|
+
static readonly monikers: "BlockViewer"[];
|
|
26
|
+
moniker: "BlockViewer";
|
|
27
|
+
protected blockByHashCache: LruCacheMap<import("@xylabs/sdk-js").BrandedHash, [{
|
|
28
|
+
schema: "network.xyo.boundwitness" & {
|
|
29
|
+
readonly __schema: true;
|
|
30
|
+
};
|
|
31
|
+
addresses: ((Lowercase<string> & {
|
|
32
|
+
readonly __hex: true;
|
|
33
|
+
} & {
|
|
34
|
+
readonly __address: true;
|
|
35
|
+
}) | import("@xyo-network/sdk-js").XyoQuantAddress)[];
|
|
36
|
+
payload_hashes: import("@xylabs/sdk-js").BrandedHash[];
|
|
37
|
+
payload_schemas: import("@xyo-network/sdk-js").BrandedSchema<string>[];
|
|
38
|
+
previous_hashes: (import("@xylabs/sdk-js").BrandedHash | null)[];
|
|
39
|
+
$signatures: import("@xylabs/sdk-js").BrandedHex[];
|
|
40
|
+
block: XL1BlockNumber;
|
|
41
|
+
chain: import("@xylabs/sdk-js").BrandedHex;
|
|
42
|
+
previous: import("@xylabs/sdk-js").BrandedHash | null;
|
|
43
|
+
$epoch: number;
|
|
44
|
+
_hash: import("@xylabs/sdk-js").BrandedHash;
|
|
45
|
+
_dataHash: import("@xylabs/sdk-js").BrandedHash;
|
|
46
|
+
$destination?: import("@xyo-network/sdk-js").XyoQuantAddress | (Lowercase<string> & {
|
|
47
|
+
readonly __hex: true;
|
|
48
|
+
} & {
|
|
49
|
+
readonly __address: true;
|
|
50
|
+
}) | undefined;
|
|
51
|
+
$sourceQuery?: import("@xylabs/sdk-js").BrandedHash | undefined;
|
|
52
|
+
protocol?: number | undefined;
|
|
53
|
+
step_hashes?: import("@xylabs/sdk-js").BrandedHash[] | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
[x: string]: unknown;
|
|
56
|
+
schema: import("@xyo-network/sdk-js").BrandedSchema<string>;
|
|
57
|
+
_hash: import("@xylabs/sdk-js").BrandedHash;
|
|
58
|
+
_dataHash: import("@xylabs/sdk-js").BrandedHash;
|
|
59
|
+
}[]], () => void>;
|
|
60
|
+
protected blockByNumberCache: LruCacheMap<XL1BlockNumber, [{
|
|
61
|
+
schema: "network.xyo.boundwitness" & {
|
|
62
|
+
readonly __schema: true;
|
|
63
|
+
};
|
|
64
|
+
addresses: ((Lowercase<string> & {
|
|
65
|
+
readonly __hex: true;
|
|
66
|
+
} & {
|
|
67
|
+
readonly __address: true;
|
|
68
|
+
}) | import("@xyo-network/sdk-js").XyoQuantAddress)[];
|
|
69
|
+
payload_hashes: import("@xylabs/sdk-js").BrandedHash[];
|
|
70
|
+
payload_schemas: import("@xyo-network/sdk-js").BrandedSchema<string>[];
|
|
71
|
+
previous_hashes: (import("@xylabs/sdk-js").BrandedHash | null)[];
|
|
72
|
+
$signatures: import("@xylabs/sdk-js").BrandedHex[];
|
|
73
|
+
block: XL1BlockNumber;
|
|
74
|
+
chain: import("@xylabs/sdk-js").BrandedHex;
|
|
75
|
+
previous: import("@xylabs/sdk-js").BrandedHash | null;
|
|
76
|
+
$epoch: number;
|
|
77
|
+
_hash: import("@xylabs/sdk-js").BrandedHash;
|
|
78
|
+
_dataHash: import("@xylabs/sdk-js").BrandedHash;
|
|
79
|
+
$destination?: import("@xyo-network/sdk-js").XyoQuantAddress | (Lowercase<string> & {
|
|
80
|
+
readonly __hex: true;
|
|
81
|
+
} & {
|
|
82
|
+
readonly __address: true;
|
|
83
|
+
}) | undefined;
|
|
84
|
+
$sourceQuery?: import("@xylabs/sdk-js").BrandedHash | undefined;
|
|
85
|
+
protocol?: number | undefined;
|
|
86
|
+
step_hashes?: import("@xylabs/sdk-js").BrandedHash[] | undefined;
|
|
87
|
+
}, {
|
|
88
|
+
[x: string]: unknown;
|
|
89
|
+
schema: import("@xyo-network/sdk-js").BrandedSchema<string>;
|
|
90
|
+
_hash: import("@xylabs/sdk-js").BrandedHash;
|
|
91
|
+
_dataHash: import("@xylabs/sdk-js").BrandedHash;
|
|
92
|
+
}[]], () => void>;
|
|
93
|
+
protected payloadCache: LruCacheMap<import("@xylabs/sdk-js").BrandedHash, WithHashMeta<Payload>, () => void>;
|
|
94
|
+
protected stepCache: LruCacheMap<string, [{
|
|
95
|
+
schema: "network.xyo.boundwitness" & {
|
|
96
|
+
readonly __schema: true;
|
|
97
|
+
};
|
|
98
|
+
addresses: ((Lowercase<string> & {
|
|
99
|
+
readonly __hex: true;
|
|
100
|
+
} & {
|
|
101
|
+
readonly __address: true;
|
|
102
|
+
}) | import("@xyo-network/sdk-js").XyoQuantAddress)[];
|
|
103
|
+
payload_hashes: import("@xylabs/sdk-js").BrandedHash[];
|
|
104
|
+
payload_schemas: import("@xyo-network/sdk-js").BrandedSchema<string>[];
|
|
105
|
+
previous_hashes: (import("@xylabs/sdk-js").BrandedHash | null)[];
|
|
106
|
+
$signatures: import("@xylabs/sdk-js").BrandedHex[];
|
|
107
|
+
block: XL1BlockNumber;
|
|
108
|
+
chain: import("@xylabs/sdk-js").BrandedHex;
|
|
109
|
+
previous: import("@xylabs/sdk-js").BrandedHash | null;
|
|
110
|
+
$epoch: number;
|
|
111
|
+
_hash: import("@xylabs/sdk-js").BrandedHash;
|
|
112
|
+
_dataHash: import("@xylabs/sdk-js").BrandedHash;
|
|
113
|
+
$destination?: import("@xyo-network/sdk-js").XyoQuantAddress | (Lowercase<string> & {
|
|
114
|
+
readonly __hex: true;
|
|
115
|
+
} & {
|
|
116
|
+
readonly __address: true;
|
|
117
|
+
}) | undefined;
|
|
118
|
+
$sourceQuery?: import("@xylabs/sdk-js").BrandedHash | undefined;
|
|
119
|
+
protocol?: number | undefined;
|
|
120
|
+
step_hashes?: import("@xylabs/sdk-js").BrandedHash[] | undefined;
|
|
121
|
+
}, {
|
|
122
|
+
[x: string]: unknown;
|
|
123
|
+
schema: import("@xyo-network/sdk-js").BrandedSchema<string>;
|
|
124
|
+
_hash: import("@xylabs/sdk-js").BrandedHash;
|
|
125
|
+
_dataHash: import("@xylabs/sdk-js").BrandedHash;
|
|
126
|
+
}[]][], () => void>;
|
|
127
|
+
private _headPollHash?;
|
|
128
|
+
private _headPollInProgress;
|
|
129
|
+
private _headPollTimer;
|
|
130
|
+
get baseUrl(): string;
|
|
131
|
+
protected get fetchFn(): typeof globalThis.fetch;
|
|
132
|
+
protected get headPollIntervalMs(): number | undefined;
|
|
133
|
+
static paramsHandler(params: Partial<RestBlockViewerParams>): Promise<{
|
|
134
|
+
baseUrl: string;
|
|
135
|
+
fetchFn: typeof fetch | undefined;
|
|
136
|
+
headPollIntervalMs: number | undefined;
|
|
137
|
+
context: import("@xyo-network/xl1-protocol-sdk").CreatableProviderContextType;
|
|
138
|
+
name?: import("@xylabs/sdk-js").CreatableName;
|
|
139
|
+
statusReporter?: import("@xylabs/sdk-js").CreatableStatusReporter<void> | undefined;
|
|
140
|
+
logger?: import("@xylabs/sdk-js").Logger;
|
|
141
|
+
meterProvider?: import("@opentelemetry/api").MeterProvider;
|
|
142
|
+
traceProvider?: import("@opentelemetry/api").TracerProvider;
|
|
143
|
+
}>;
|
|
144
|
+
blockByHash(hash: Hash): Promise<SignedHydratedBlockWithHashMeta | null>;
|
|
145
|
+
blockByNumber(blockNumber: XL1BlockNumber): Promise<SignedHydratedBlockWithHashMeta | null>;
|
|
146
|
+
blocksByHash(hash: Hash, limit?: number): Promise<SignedHydratedBlockWithHashMeta[]>;
|
|
147
|
+
blocksByNumber(blockNumber: XL1BlockNumber, limit?: number): Promise<SignedHydratedBlockWithHashMeta[]>;
|
|
148
|
+
blocksByStep(stepLevel: number, stepIndex: number): Promise<SignedHydratedBlockWithHashMeta[]>;
|
|
149
|
+
chainId(): Promise<ChainId>;
|
|
150
|
+
chainId(blockNumber: XL1BlockNumber): Promise<ChainId>;
|
|
151
|
+
chainId(blockNumber: 'latest'): Promise<ChainId>;
|
|
152
|
+
currentBlock(): Promise<SignedHydratedBlockWithHashMeta>;
|
|
153
|
+
currentBlockHash(): Promise<Hash>;
|
|
154
|
+
currentBlockNumber(): Promise<XL1BlockNumber>;
|
|
155
|
+
payloadByHash(hash: Hash): Promise<WithHashMeta<Payload> | null>;
|
|
156
|
+
payloadsByHash(hashes: Hash[]): Promise<WithHashMeta<Payload>[]>;
|
|
157
|
+
rate(range: XL1BlockRange, timeUnit?: keyof TimeDurations): Promise<BlockRate>;
|
|
158
|
+
stepSizeRate(start: XL1BlockNumber, stepIndex: number, count?: number, timeUnit?: keyof TimeDurations): Promise<BlockRate>;
|
|
159
|
+
timeDurationRate(timeConfig: SingleTimeConfig, startBlockNumber?: XL1BlockNumber, timeUnit?: keyof TimeDurations, toleranceMs?: number, maxAttempts?: number): Promise<BlockRate>;
|
|
160
|
+
protected startHandler(): Promise<void>;
|
|
161
|
+
protected stopHandler(): Promise<void>;
|
|
162
|
+
/** Validates a parsed block file and populates both block caches. */
|
|
163
|
+
private cacheBlock;
|
|
164
|
+
private fetchJson;
|
|
165
|
+
private pollHead;
|
|
166
|
+
private startHeadPolling;
|
|
167
|
+
private stopHeadPolling;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=RestBlockViewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RestBlockViewer.d.ts","sourceRoot":"","sources":["../../src/RestBlockViewer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAC5D,OAAO,KAAK,EACV,SAAS,EAAE,WAAW,EAAE,OAAO,EAC/B,+BAA+B,EAAE,gBAAgB,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAChG,MAAM,+BAA+B,CAAA;AAItC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAC5E,OAAO,EACL,yBAAyB,EAC1B,MAAM,+BAA+B,CAAA;AAMtC,sCAAsC;AACtC,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAA;IACf,kGAAkG;IAClG,OAAO,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAMD;;;;;;GAMG;AACH,qBACa,eAAgB,SAAQ,yBAAyB,CAAC,qBAAqB,EAAE,WAAW,CAAC,WAAW,CAAC,CAAE,YAAW,W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A;AAC1B,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
5
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
6
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
|
+
if (decorator = decorators[i])
|
|
8
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
|
|
14
|
+
// src/paths.ts
|
|
15
|
+
var headPath = () => "chain/head.json";
|
|
16
|
+
var blockNumberPath = (block) => `block/number/${block}.json`;
|
|
17
|
+
var blockHashPath = (hash) => `block/hash/${hash}.json`;
|
|
18
|
+
var blocksStepPath = (stepLevel, stepIndex) => `blocks/step/${stepLevel}/${stepIndex}.json`;
|
|
19
|
+
var payloadPath = (hash) => `payload/${hash}.json`;
|
|
20
|
+
|
|
21
|
+
// src/RestBlockViewer.ts
|
|
22
|
+
import { assertEx, exists } from "@xylabs/sdk-js";
|
|
23
|
+
import { PayloadZodLoose, WithHashMetaZod } from "@xyo-network/sdk-js";
|
|
24
|
+
import { LruCacheMap } from "@xyo-network/xl1-driver-memory";
|
|
25
|
+
import {
|
|
26
|
+
asSignedHydratedBlockWithHashMeta,
|
|
27
|
+
asXL1BlockNumber,
|
|
28
|
+
BlockViewerMoniker,
|
|
29
|
+
stepSize
|
|
30
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
31
|
+
import {
|
|
32
|
+
AbstractCreatableProvider,
|
|
33
|
+
asBlocksStepSummary,
|
|
34
|
+
blocksMaxStep,
|
|
35
|
+
calculateBlockRate,
|
|
36
|
+
calculateStepSizeRate,
|
|
37
|
+
calculateTimeRate,
|
|
38
|
+
creatableProvider
|
|
39
|
+
} from "@xyo-network/xl1-protocol-sdk";
|
|
40
|
+
var MIN_HEAD_POLL_INTERVAL_MS = 5e3;
|
|
41
|
+
var PayloadFileZod = WithHashMetaZod(PayloadZodLoose);
|
|
42
|
+
var RestBlockViewer = class extends AbstractCreatableProvider {
|
|
43
|
+
moniker = RestBlockViewer.defaultMoniker;
|
|
44
|
+
blockByHashCache = new LruCacheMap({ max: 2e3 });
|
|
45
|
+
blockByNumberCache = new LruCacheMap({ max: 2e3 });
|
|
46
|
+
payloadCache = new LruCacheMap({ max: 1e4 });
|
|
47
|
+
stepCache = new LruCacheMap({ max: 4 });
|
|
48
|
+
_headPollHash;
|
|
49
|
+
_headPollInProgress = false;
|
|
50
|
+
_headPollTimer = null;
|
|
51
|
+
get baseUrl() {
|
|
52
|
+
return this.params.baseUrl;
|
|
53
|
+
}
|
|
54
|
+
get fetchFn() {
|
|
55
|
+
return this.params.fetchFn ?? globalThis.fetch.bind(globalThis);
|
|
56
|
+
}
|
|
57
|
+
get headPollIntervalMs() {
|
|
58
|
+
return this.params.headPollIntervalMs;
|
|
59
|
+
}
|
|
60
|
+
static async paramsHandler(params) {
|
|
61
|
+
const headPollIntervalMs = params.headPollIntervalMs;
|
|
62
|
+
if (headPollIntervalMs !== void 0) {
|
|
63
|
+
assertEx(headPollIntervalMs >= MIN_HEAD_POLL_INTERVAL_MS, () => `headPollIntervalMs must be at least ${MIN_HEAD_POLL_INTERVAL_MS}ms`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...await super.paramsHandler(params),
|
|
67
|
+
baseUrl: assertEx(params.baseUrl, () => "baseUrl is required").replace(/\/+$/, ""),
|
|
68
|
+
fetchFn: params.fetchFn,
|
|
69
|
+
headPollIntervalMs
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async blockByHash(hash) {
|
|
73
|
+
return await this.spanAsync("blockByHash", async () => {
|
|
74
|
+
const cached = this.blockByHashCache.get(hash);
|
|
75
|
+
if (cached) return cached;
|
|
76
|
+
const parsed = await this.fetchJson(blockHashPath(hash));
|
|
77
|
+
return parsed === void 0 ? null : this.cacheBlock(parsed);
|
|
78
|
+
}, { ...this.context, timeBudgetLimit: 100 });
|
|
79
|
+
}
|
|
80
|
+
async blockByNumber(blockNumber) {
|
|
81
|
+
return await this.spanAsync("blockByNumber", async () => {
|
|
82
|
+
const cached = this.blockByNumberCache.get(blockNumber);
|
|
83
|
+
if (cached) return cached;
|
|
84
|
+
const parsed = await this.fetchJson(blockNumberPath(blockNumber));
|
|
85
|
+
return parsed === void 0 ? null : this.cacheBlock(parsed);
|
|
86
|
+
}, { ...this.context, timeBudgetLimit: 100 });
|
|
87
|
+
}
|
|
88
|
+
async blocksByHash(hash, limit = 50) {
|
|
89
|
+
return await this.spanAsync("blocksByHash", async () => {
|
|
90
|
+
assertEx(limit > 0, () => "limit must be greater than 0");
|
|
91
|
+
assertEx(limit <= 100, () => "limit must be less than 100");
|
|
92
|
+
const blocks = [];
|
|
93
|
+
let current = await this.blockByHash(hash);
|
|
94
|
+
while (current && blocks.length < limit) {
|
|
95
|
+
blocks.push(current);
|
|
96
|
+
const previousHash = current[0].previous;
|
|
97
|
+
if (previousHash === null) break;
|
|
98
|
+
current = await this.blockByHash(previousHash);
|
|
99
|
+
}
|
|
100
|
+
return blocks;
|
|
101
|
+
}, { ...this.context, timeBudgetLimit: 300 });
|
|
102
|
+
}
|
|
103
|
+
async blocksByNumber(blockNumber, limit = 50) {
|
|
104
|
+
return await this.spanAsync("blocksByNumber", async () => {
|
|
105
|
+
assertEx(limit > 0, () => "limit must be greater than 0");
|
|
106
|
+
assertEx(limit <= 100, () => "limit must be less than 100");
|
|
107
|
+
const blocks = [];
|
|
108
|
+
let current = await this.blockByNumber(blockNumber);
|
|
109
|
+
while (current && blocks.length < limit) {
|
|
110
|
+
blocks.push(current);
|
|
111
|
+
if (current[0].block === 0) break;
|
|
112
|
+
current = await this.blockByNumber(asXL1BlockNumber(current[0].block - 1, true));
|
|
113
|
+
}
|
|
114
|
+
return blocks;
|
|
115
|
+
}, this.context);
|
|
116
|
+
}
|
|
117
|
+
async blocksByStep(stepLevel, stepIndex) {
|
|
118
|
+
return await this.spanAsync("blocksByStep", async () => {
|
|
119
|
+
assertEx(Number.isInteger(stepIndex) && stepIndex >= 0, () => "stepIndex must be a non-negative integer");
|
|
120
|
+
stepSize(stepLevel);
|
|
121
|
+
assertEx(
|
|
122
|
+
stepLevel <= blocksMaxStep,
|
|
123
|
+
() => `blocksByStep does not support step levels above ${blocksMaxStep} (requested ${stepLevel})`
|
|
124
|
+
);
|
|
125
|
+
const cacheKey = `${stepLevel}|${stepIndex}`;
|
|
126
|
+
const cached = this.stepCache.get(cacheKey);
|
|
127
|
+
if (cached) return cached;
|
|
128
|
+
const parsed = await this.fetchJson(blocksStepPath(stepLevel, stepIndex));
|
|
129
|
+
if (parsed === void 0) return [];
|
|
130
|
+
const summary = asBlocksStepSummary(parsed, { required: true });
|
|
131
|
+
const blocks = summary.blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true)).toReversed();
|
|
132
|
+
this.stepCache.set(cacheKey, blocks);
|
|
133
|
+
return blocks;
|
|
134
|
+
}, this.context);
|
|
135
|
+
}
|
|
136
|
+
async chainId(blockNumber = "latest") {
|
|
137
|
+
return await this.spanAsync("chainId", async () => {
|
|
138
|
+
return blockNumber === "latest" ? (await this.currentBlock())[0].chain : assertEx(await this.blockByNumber(blockNumber), () => `Block not found [${blockNumber}]`)[0].chain;
|
|
139
|
+
}, this.context);
|
|
140
|
+
}
|
|
141
|
+
async currentBlock() {
|
|
142
|
+
return await this.spanAsync("currentBlock", async () => {
|
|
143
|
+
const parsed = assertEx(await this.fetchJson(headPath()), () => "Head not found");
|
|
144
|
+
return this.cacheBlock(parsed);
|
|
145
|
+
}, this.context);
|
|
146
|
+
}
|
|
147
|
+
async currentBlockHash() {
|
|
148
|
+
return (await this.currentBlock())[0]._hash;
|
|
149
|
+
}
|
|
150
|
+
async currentBlockNumber() {
|
|
151
|
+
return (await this.currentBlock())[0].block;
|
|
152
|
+
}
|
|
153
|
+
async payloadByHash(hash) {
|
|
154
|
+
const [payload] = await this.payloadsByHash([hash]);
|
|
155
|
+
return payload ?? null;
|
|
156
|
+
}
|
|
157
|
+
async payloadsByHash(hashes) {
|
|
158
|
+
return await this.spanAsync("payloadsByHash", async () => {
|
|
159
|
+
const results = await Promise.all(hashes.map(async (hash) => {
|
|
160
|
+
const cached = this.payloadCache.get(hash);
|
|
161
|
+
if (cached) return cached;
|
|
162
|
+
const parsed = await this.fetchJson(payloadPath(hash));
|
|
163
|
+
if (parsed === void 0) return;
|
|
164
|
+
const payload = PayloadFileZod.parse(parsed);
|
|
165
|
+
this.payloadCache.set(hash, payload);
|
|
166
|
+
return payload;
|
|
167
|
+
}));
|
|
168
|
+
return results.filter(exists);
|
|
169
|
+
}, this.context);
|
|
170
|
+
}
|
|
171
|
+
async rate(range, timeUnit) {
|
|
172
|
+
return await calculateBlockRate(this, range, timeUnit);
|
|
173
|
+
}
|
|
174
|
+
async stepSizeRate(start, stepIndex, count = 1, timeUnit) {
|
|
175
|
+
return await calculateStepSizeRate(this, start, stepIndex, count, timeUnit);
|
|
176
|
+
}
|
|
177
|
+
async timeDurationRate(timeConfig, startBlockNumber, timeUnit, toleranceMs, maxAttempts) {
|
|
178
|
+
return await calculateTimeRate(this, timeConfig, startBlockNumber, timeUnit, toleranceMs, maxAttempts);
|
|
179
|
+
}
|
|
180
|
+
async startHandler() {
|
|
181
|
+
await super.startHandler();
|
|
182
|
+
if (this.headPollIntervalMs === void 0) return;
|
|
183
|
+
await this.pollHead(false);
|
|
184
|
+
this.startHeadPolling();
|
|
185
|
+
}
|
|
186
|
+
async stopHandler() {
|
|
187
|
+
this.stopHeadPolling();
|
|
188
|
+
this._headPollHash = void 0;
|
|
189
|
+
await super.stopHandler();
|
|
190
|
+
}
|
|
191
|
+
/** Validates a parsed block file and populates both block caches. */
|
|
192
|
+
cacheBlock(parsed) {
|
|
193
|
+
const block = asSignedHydratedBlockWithHashMeta(parsed, true);
|
|
194
|
+
this.blockByHashCache.set(block[0]._hash, block);
|
|
195
|
+
this.blockByNumberCache.set(block[0].block, block);
|
|
196
|
+
return block;
|
|
197
|
+
}
|
|
198
|
+
async fetchJson(path) {
|
|
199
|
+
const response = await this.fetchFn(`${this.baseUrl}/${path}`);
|
|
200
|
+
if (response.status === 404) return void 0;
|
|
201
|
+
assertEx(response.ok, () => `Request failed [${response.status}] for ${path}`);
|
|
202
|
+
return await response.json();
|
|
203
|
+
}
|
|
204
|
+
async pollHead(emitOnChange) {
|
|
205
|
+
if (this._headPollInProgress) return;
|
|
206
|
+
this._headPollInProgress = true;
|
|
207
|
+
try {
|
|
208
|
+
const block = await this.currentBlock();
|
|
209
|
+
const hash = block[0]._hash;
|
|
210
|
+
if (this._headPollHash === void 0) {
|
|
211
|
+
this._headPollHash = hash;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (hash !== this._headPollHash) {
|
|
215
|
+
this._headPollHash = hash;
|
|
216
|
+
if (emitOnChange) {
|
|
217
|
+
await this.emit("headUpdated", { block });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} catch (ex) {
|
|
221
|
+
this.logger?.error("Error polling block head", ex);
|
|
222
|
+
} finally {
|
|
223
|
+
this._headPollInProgress = false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
startHeadPolling() {
|
|
227
|
+
if (this.headPollIntervalMs === void 0) return;
|
|
228
|
+
this.stopHeadPolling();
|
|
229
|
+
this._headPollTimer = setInterval(() => {
|
|
230
|
+
void this.pollHead(true);
|
|
231
|
+
}, this.headPollIntervalMs);
|
|
232
|
+
}
|
|
233
|
+
stopHeadPolling() {
|
|
234
|
+
if (this._headPollTimer) {
|
|
235
|
+
clearInterval(this._headPollTimer);
|
|
236
|
+
this._headPollTimer = null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
__publicField(RestBlockViewer, "defaultMoniker", BlockViewerMoniker);
|
|
241
|
+
__publicField(RestBlockViewer, "dependencies", []);
|
|
242
|
+
__publicField(RestBlockViewer, "monikers", [BlockViewerMoniker]);
|
|
243
|
+
RestBlockViewer = __decorateClass([
|
|
244
|
+
creatableProvider()
|
|
245
|
+
], RestBlockViewer);
|
|
246
|
+
export {
|
|
247
|
+
RestBlockViewer,
|
|
248
|
+
blockHashPath,
|
|
249
|
+
blockNumberPath,
|
|
250
|
+
blocksStepPath,
|
|
251
|
+
headPath,
|
|
252
|
+
payloadPath
|
|
253
|
+
};
|
|
254
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/paths.ts", "../../src/RestBlockViewer.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\n\n/**\n * Path contract for the static REST chain layout.\n *\n * These builders are the single source of truth for where files live, shared by the\n * publisher (which writes the static files) and `RestBlockViewer` (which reads them),\n * so the layout cannot drift between the two. Paths are relative \u2014 no leading slash \u2014\n * and joined to a base URL by the consumer.\n *\n * Every file except the head pointer is immutable once written:\n * - block and payload files never change after finalization\n * - step files are only written for completed steps\n * - the head pointer is rewritten as the chain advances and must not be cached long-term\n */\n\n/** The mutable head pointer: the current head SignedHydratedBlockWithHashMeta. */\nexport const headPath = (): string => 'chain/head.json'\n\n/** A block by number: SignedHydratedBlockWithHashMeta. */\nexport const blockNumberPath = (block: number): string => `block/number/${block}.json`\n\n/** A block by hash: the same content as its by-number twin. */\nexport const blockHashPath = (hash: Hash): string => `block/hash/${hash}.json`\n\n/**\n * A completed step's blocks: a BlocksStepSummary payload whose `blocks` array is ordered\n * oldest-first. Only complete steps are published; the in-flight tail step has no file.\n */\nexport const blocksStepPath = (stepLevel: number, stepIndex: number): string => `blocks/step/${stepLevel}/${stepIndex}.json`\n\n/** A payload by hash: WithHashMeta<Payload>. */\nexport const payloadPath = (hash: Hash): string => `payload/${hash}.json`\n", "import type { Hash } from '@xylabs/sdk-js'\nimport { assertEx, exists } from '@xylabs/sdk-js'\nimport type { Payload, WithHashMeta } from '@xyo-network/sdk-js'\nimport { PayloadZodLoose, WithHashMetaZod } from '@xyo-network/sdk-js'\nimport { LruCacheMap } from '@xyo-network/xl1-driver-memory'\nimport type {\n BlockRate, BlockViewer, ChainId,\n SignedHydratedBlockWithHashMeta, SingleTimeConfig, TimeDurations, XL1BlockNumber, XL1BlockRange,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n asSignedHydratedBlockWithHashMeta, asXL1BlockNumber, BlockViewerMoniker, stepSize,\n} from '@xyo-network/xl1-protocol-lib'\nimport type { CreatableProviderParams } from '@xyo-network/xl1-protocol-sdk'\nimport {\n AbstractCreatableProvider, asBlocksStepSummary, blocksMaxStep, calculateBlockRate, calculateStepSizeRate, calculateTimeRate, creatableProvider,\n} from '@xyo-network/xl1-protocol-sdk'\n\nimport {\n blockHashPath, blockNumberPath, blocksStepPath, headPath, payloadPath,\n} from './paths.ts'\n\n/** Parameters for RestBlockViewer. */\nexport interface RestBlockViewerParams extends CreatableProviderParams {\n /** Base URL of the static chain layout (e.g. a public R2 bucket or CDN domain). */\n baseUrl: string\n /** Optional fetch override (custom agents, auth headers, tests). Defaults to the global fetch. */\n fetchFn?: typeof globalThis.fetch\n headPollIntervalMs?: number\n}\n\nconst MIN_HEAD_POLL_INTERVAL_MS = 5000\n\nconst PayloadFileZod = WithHashMetaZod(PayloadZodLoose)\n\n/**\n * A BlockViewer over a statically generated REST file layout (see `paths.ts`).\n *\n * Reads are anonymous HTTP GETs against immutable files, so everything except the head\n * pointer is cached aggressively. `blocksByStep` serves only completed steps \u2014 the\n * in-flight tail step has no static file and returns [].\n */\n@creatableProvider()\nexport class RestBlockViewer extends AbstractCreatableProvider<RestBlockViewerParams, BlockViewer['eventData']> implements BlockViewer {\n static readonly defaultMoniker = BlockViewerMoniker\n static readonly dependencies = []\n static readonly monikers = [BlockViewerMoniker]\n moniker = RestBlockViewer.defaultMoniker\n\n protected blockByHashCache = new LruCacheMap<Hash, SignedHydratedBlockWithHashMeta>({ max: 2000 })\n protected blockByNumberCache = new LruCacheMap<XL1BlockNumber, SignedHydratedBlockWithHashMeta>({ max: 2000 })\n protected payloadCache = new LruCacheMap<Hash, WithHashMeta<Payload>>({ max: 10_000 })\n protected stepCache = new LruCacheMap<string, SignedHydratedBlockWithHashMeta[]>({ max: 4 })\n\n private _headPollHash?: Hash\n private _headPollInProgress = false\n private _headPollTimer: ReturnType<typeof setInterval> | null = null\n\n get baseUrl(): string {\n return this.params.baseUrl\n }\n\n protected get fetchFn(): typeof globalThis.fetch {\n return this.params.fetchFn ?? globalThis.fetch.bind(globalThis)\n }\n\n protected get headPollIntervalMs() {\n return this.params.headPollIntervalMs\n }\n\n static override async paramsHandler(params: Partial<RestBlockViewerParams>) {\n const headPollIntervalMs = params.headPollIntervalMs\n if (headPollIntervalMs !== undefined) {\n assertEx(headPollIntervalMs >= MIN_HEAD_POLL_INTERVAL_MS, () => `headPollIntervalMs must be at least ${MIN_HEAD_POLL_INTERVAL_MS}ms`)\n }\n return {\n ...await super.paramsHandler(params),\n baseUrl: assertEx(params.baseUrl, () => 'baseUrl is required').replace(/\\/+$/, ''),\n fetchFn: params.fetchFn,\n headPollIntervalMs,\n } satisfies RestBlockViewerParams\n }\n\n async blockByHash(hash: Hash): Promise<SignedHydratedBlockWithHashMeta | null> {\n return await this.spanAsync('blockByHash', async () => {\n const cached = this.blockByHashCache.get(hash)\n if (cached) return cached\n const parsed = await this.fetchJson(blockHashPath(hash))\n return parsed === undefined ? null : this.cacheBlock(parsed)\n }, { ...this.context, timeBudgetLimit: 100 })\n }\n\n async blockByNumber(blockNumber: XL1BlockNumber): Promise<SignedHydratedBlockWithHashMeta | null> {\n return await this.spanAsync('blockByNumber', async () => {\n const cached = this.blockByNumberCache.get(blockNumber)\n if (cached) return cached\n const parsed = await this.fetchJson(blockNumberPath(blockNumber))\n return parsed === undefined ? null : this.cacheBlock(parsed)\n }, { ...this.context, timeBudgetLimit: 100 })\n }\n\n async blocksByHash(hash: Hash, limit = 50): Promise<SignedHydratedBlockWithHashMeta[]> {\n return await this.spanAsync('blocksByHash', async () => {\n assertEx(limit > 0, () => 'limit must be greater than 0')\n assertEx(limit <= 100, () => 'limit must be less than 100')\n const blocks: SignedHydratedBlockWithHashMeta[] = []\n let current = await this.blockByHash(hash)\n while (current && blocks.length < limit) {\n blocks.push(current)\n const previousHash = current[0].previous\n if (previousHash === null) break\n current = await this.blockByHash(previousHash)\n }\n return blocks\n }, { ...this.context, timeBudgetLimit: 300 })\n }\n\n async blocksByNumber(blockNumber: XL1BlockNumber, limit = 50): Promise<SignedHydratedBlockWithHashMeta[]> {\n return await this.spanAsync('blocksByNumber', async () => {\n assertEx(limit > 0, () => 'limit must be greater than 0')\n assertEx(limit <= 100, () => 'limit must be less than 100')\n const blocks: SignedHydratedBlockWithHashMeta[] = []\n let current = await this.blockByNumber(blockNumber)\n while (current && blocks.length < limit) {\n blocks.push(current)\n if (current[0].block === 0) break\n current = await this.blockByNumber(asXL1BlockNumber(current[0].block - 1, true))\n }\n return blocks\n }, this.context)\n }\n\n async blocksByStep(stepLevel: number, stepIndex: number): Promise<SignedHydratedBlockWithHashMeta[]> {\n return await this.spanAsync('blocksByStep', async () => {\n assertEx(Number.isInteger(stepIndex) && stepIndex >= 0, () => 'stepIndex must be a non-negative integer')\n stepSize(stepLevel) // validates the level against StepSizes\n assertEx(\n stepLevel <= blocksMaxStep,\n () => `blocksByStep does not support step levels above ${blocksMaxStep} (requested ${stepLevel})`,\n )\n const cacheKey = `${stepLevel}|${stepIndex}`\n const cached = this.stepCache.get(cacheKey)\n if (cached) return cached\n const parsed = await this.fetchJson(blocksStepPath(stepLevel, stepIndex))\n // Only completed steps are published; the in-flight tail step has no file\n if (parsed === undefined) return []\n const summary = asBlocksStepSummary(parsed, { required: true })\n // Step files store blocks oldest-first; the viewer interface returns newest-first\n const blocks = summary.blocks.map(b => asSignedHydratedBlockWithHashMeta(b, true)).toReversed()\n this.stepCache.set(cacheKey, blocks)\n return blocks\n }, this.context)\n }\n\n chainId(): Promise<ChainId>\n chainId(blockNumber: XL1BlockNumber): Promise<ChainId>\n chainId(blockNumber: 'latest'): Promise<ChainId>\n async chainId(blockNumber: XL1BlockNumber | 'latest' = 'latest'): Promise<ChainId> {\n return await this.spanAsync('chainId', async () => {\n return blockNumber === 'latest'\n ? (await this.currentBlock())[0].chain\n : assertEx(await this.blockByNumber(blockNumber), () => `Block not found [${blockNumber}]`)[0].chain\n }, this.context)\n }\n\n async currentBlock(): Promise<SignedHydratedBlockWithHashMeta> {\n return await this.spanAsync('currentBlock', async () => {\n const parsed = assertEx(await this.fetchJson(headPath()), () => 'Head not found')\n return this.cacheBlock(parsed)\n }, this.context)\n }\n\n async currentBlockHash(): Promise<Hash> {\n return (await this.currentBlock())[0]._hash\n }\n\n async currentBlockNumber(): Promise<XL1BlockNumber> {\n return (await this.currentBlock())[0].block\n }\n\n async payloadByHash(hash: Hash): Promise<WithHashMeta<Payload> | null> {\n const [payload] = await this.payloadsByHash([hash])\n return payload ?? null\n }\n\n async payloadsByHash(hashes: Hash[]): Promise<WithHashMeta<Payload>[]> {\n return await this.spanAsync('payloadsByHash', async () => {\n const results = await Promise.all(hashes.map(async (hash) => {\n const cached = this.payloadCache.get(hash)\n if (cached) return cached\n const parsed = await this.fetchJson(payloadPath(hash))\n if (parsed === undefined) return\n const payload = PayloadFileZod.parse(parsed)\n this.payloadCache.set(hash, payload)\n return payload\n }))\n return results.filter(exists)\n }, this.context)\n }\n\n async rate(range: XL1BlockRange, timeUnit?: keyof TimeDurations): Promise<BlockRate> {\n return await calculateBlockRate(this, range, timeUnit)\n }\n\n async stepSizeRate(start: XL1BlockNumber, stepIndex: number, count = 1, timeUnit?: keyof TimeDurations): Promise<BlockRate> {\n return await calculateStepSizeRate(this, start, stepIndex, count, timeUnit)\n }\n\n async timeDurationRate(\n timeConfig: SingleTimeConfig,\n startBlockNumber?: XL1BlockNumber,\n timeUnit?: keyof TimeDurations,\n toleranceMs?: number,\n maxAttempts?: number,\n ): Promise<BlockRate> {\n return await calculateTimeRate(this, timeConfig, startBlockNumber, timeUnit, toleranceMs, maxAttempts)\n }\n\n protected override async startHandler(): Promise<void> {\n await super.startHandler()\n if (this.headPollIntervalMs === undefined) return\n await this.pollHead(false)\n this.startHeadPolling()\n }\n\n protected override async stopHandler(): Promise<void> {\n this.stopHeadPolling()\n this._headPollHash = undefined\n await super.stopHandler()\n }\n\n /** Validates a parsed block file and populates both block caches. */\n private cacheBlock(parsed: unknown): SignedHydratedBlockWithHashMeta {\n const block = asSignedHydratedBlockWithHashMeta(parsed, true)\n this.blockByHashCache.set(block[0]._hash, block)\n this.blockByNumberCache.set(block[0].block, block)\n return block\n }\n\n private async fetchJson(path: string): Promise<unknown> {\n const response = await this.fetchFn(`${this.baseUrl}/${path}`)\n if (response.status === 404) return undefined\n assertEx(response.ok, () => `Request failed [${response.status}] for ${path}`)\n return await response.json()\n }\n\n private async pollHead(emitOnChange: boolean): Promise<void> {\n if (this._headPollInProgress) return\n this._headPollInProgress = true\n try {\n const block = await this.currentBlock()\n const hash = block[0]._hash\n if (this._headPollHash === undefined) {\n this._headPollHash = hash\n return\n }\n if (hash !== this._headPollHash) {\n this._headPollHash = hash\n if (emitOnChange) {\n await this.emit('headUpdated', { block })\n }\n }\n } catch (ex) {\n this.logger?.error('Error polling block head', ex)\n } finally {\n this._headPollInProgress = false\n }\n }\n\n private startHeadPolling() {\n if (this.headPollIntervalMs === undefined) return\n this.stopHeadPolling()\n this._headPollTimer = setInterval(() => {\n void this.pollHead(true)\n }, this.headPollIntervalMs)\n }\n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AAM,SAAS,IAAI,EAAE;AAC7E,WAAO,MAAM,SAAS,KAAK;AAAA,EAC7B;AAAA,EAEA,MAAc,SAAS,cAAsC;AAC3D,QAAI,KAAK,oBAAqB;AAC9B,SAAK,sBAAsB;AAC3B,QAAI;AACF,YAAM,QAAQ,MAAM,KAAK,aAAa;AACtC,YAAM,OAAO,MAAM,CAAC,EAAE;AACtB,UAAI,KAAK,kBAAkB,QAAW;AACpC,aAAK,gBAAgB;AACrB;AAAA,MACF;AACA,UAAI,SAAS,KAAK,eAAe;AAC/B,aAAK,gBAAgB;AACrB,YAAI,cAAc;AAChB,gBAAM,KAAK,KAAK,eAAe,EAAE,MAAM,CAAC;AAAA,QAC1C;AAAA,MACF;AAAA,IACF,SAAS,IAAI;AACX,WAAK,QAAQ,MAAM,4BAA4B,EAAE;AAAA,IACnD,UAAE;AACA,WAAK,sBAAsB;AAAA,IAC7B;AAAA,EACF;AAAA,EAEQ,mBAAmB;AACzB,QAAI,KAAK,uBAAuB,OAAW;AAC3C,SAAK,gBAAgB;AACrB,SAAK,iBAAiB,YAAY,MAAM;AACtC,WAAK,KAAK,SAAS,IAAI;AAAA,IACzB,GAAG,KAAK,kBAAkB;AAAA,EAC5B;AAAA,EAEQ,kBAAkB;AACxB,QAAI,KAAK,gBAAgB;AACvB,oBAAc,KAAK,cAAc;AACjC,WAAK,iBAAiB;AAAA,IACxB;AAAA,EACF;AACF;AA/OE,cADW,iBACK,kBAAiB;AACjC,cAFW,iBAEK,gBAAe,CAAC;AAChC,cAHW,iBAGK,YAAW,CAAC,kBAAkB;AAHnC,kBAAN;AAAA,EADN,kBAAkB;AAAA,GACN;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Hash } from '@xylabs/sdk-js';
|
|
2
|
+
/**
|
|
3
|
+
* Path contract for the static REST chain layout.
|
|
4
|
+
*
|
|
5
|
+
* These builders are the single source of truth for where files live, shared by the
|
|
6
|
+
* publisher (which writes the static files) and `RestBlockViewer` (which reads them),
|
|
7
|
+
* so the layout cannot drift between the two. Paths are relative — no leading slash —
|
|
8
|
+
* and joined to a base URL by the consumer.
|
|
9
|
+
*
|
|
10
|
+
* Every file except the head pointer is immutable once written:
|
|
11
|
+
* - block and payload files never change after finalization
|
|
12
|
+
* - step files are only written for completed steps
|
|
13
|
+
* - the head pointer is rewritten as the chain advances and must not be cached long-term
|
|
14
|
+
*/
|
|
15
|
+
/** The mutable head pointer: the current head SignedHydratedBlockWithHashMeta. */
|
|
16
|
+
export declare const headPath: () => string;
|
|
17
|
+
/** A block by number: SignedHydratedBlockWithHashMeta. */
|
|
18
|
+
export declare const blockNumberPath: (block: number) => string;
|
|
19
|
+
/** A block by hash: the same content as its by-number twin. */
|
|
20
|
+
export declare const blockHashPath: (hash: Hash) => string;
|
|
21
|
+
/**
|
|
22
|
+
* A completed step's blocks: a BlocksStepSummary payload whose `blocks` array is ordered
|
|
23
|
+
* oldest-first. Only complete steps are published; the in-flight tail step has no file.
|
|
24
|
+
*/
|
|
25
|
+
export declare const blocksStepPath: (stepLevel: number, stepIndex: number) => string;
|
|
26
|
+
/** A payload by hash: WithHashMeta<Payload>. */
|
|
27
|
+
export declare const payloadPath: (hash: Hash) => string;
|
|
28
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAE1C;;;;;;;;;;;;GAYG;AAEH,kFAAkF;AAClF,eAAO,MAAM,QAAQ,QAAO,MAA2B,CAAA;AAEvD,0DAA0D;AAC1D,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,MAAsC,CAAA;AAEtF,+DAA+D;AAC/D,eAAO,MAAM,aAAa,GAAI,MAAM,IAAI,KAAG,MAAmC,CAAA;AAE9E;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,EAAE,WAAW,MAAM,KAAG,MAAsD,CAAA;AAE5H,gDAAgD;AAChD,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,MAAgC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json.schemastore.org/package.json",
|
|
3
|
+
"name": "@xyo-network/xl1-rest-block-viewer",
|
|
4
|
+
"version": "2.0.12",
|
|
5
|
+
"description": "XYO Layer One BlockViewer over a statically generated REST file layout",
|
|
6
|
+
"homepage": "https://xylabs.com",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/XYOracleNetwork/xl1-protocol/issues",
|
|
9
|
+
"email": "support@xylabs.com"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/XYOracleNetwork/xl1-protocol.git"
|
|
14
|
+
},
|
|
15
|
+
"license": "LGPL-3.0-only",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "XY Labs Development Team",
|
|
18
|
+
"email": "support@xylabs.com",
|
|
19
|
+
"url": "https://xylabs.com"
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/neutral/index.d.ts",
|
|
26
|
+
"default": "./dist/neutral/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"!**/*.bench.*",
|
|
33
|
+
"!**/*.spec.*",
|
|
34
|
+
"!**/*.test.*",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@xyo-network/xl1-driver-memory": "~2.0.12",
|
|
39
|
+
"@xyo-network/xl1-protocol-sdk": "~2.0.12",
|
|
40
|
+
"@xyo-network/xl1-protocol-lib": "~2.0.12"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@bitauth/libauth": "~3.0",
|
|
44
|
+
"@metamask/providers": "^22.1",
|
|
45
|
+
"@noble/post-quantum": "~0.6.1",
|
|
46
|
+
"@opentelemetry/api": "^1.9",
|
|
47
|
+
"@opentelemetry/sdk-trace-base": "^2.7",
|
|
48
|
+
"@scure/base": "~2.2",
|
|
49
|
+
"@scure/bip39": "~2.2",
|
|
50
|
+
"@xylabs/geo": "^6.0",
|
|
51
|
+
"@xylabs/sdk-js": "^6.0.10",
|
|
52
|
+
"@xylabs/threads": "~6.0",
|
|
53
|
+
"@xylabs/toolchain": "~8.1.19",
|
|
54
|
+
"@xylabs/tsconfig": "~8.1.19",
|
|
55
|
+
"@xyo-network/address": "^6.0",
|
|
56
|
+
"@xyo-network/sdk-js": "^6.0",
|
|
57
|
+
"@xyo-network/sdk-protocol-js": "~6.0",
|
|
58
|
+
"ajv": "^8.20",
|
|
59
|
+
"async-mutex": "^0.5",
|
|
60
|
+
"bn.js": "^5.2",
|
|
61
|
+
"buffer": "^6.0",
|
|
62
|
+
"cosmiconfig": "^9.0",
|
|
63
|
+
"debug": "~4.4",
|
|
64
|
+
"eslint": "^10.4.1",
|
|
65
|
+
"ethers": "^6.16",
|
|
66
|
+
"hash-wasm": "~4.12",
|
|
67
|
+
"idb": "^8.0",
|
|
68
|
+
"lru-cache": "^11.3",
|
|
69
|
+
"observable-fns": "~0.6",
|
|
70
|
+
"typescript": "~6.0.3",
|
|
71
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
72
|
+
"vitest": "~4.1.8",
|
|
73
|
+
"webextension-polyfill": "^0.12",
|
|
74
|
+
"zod": "~4.4"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"@bitauth/libauth": "~3.0",
|
|
78
|
+
"@metamask/providers": "^22.1",
|
|
79
|
+
"@noble/post-quantum": "~0.6.1",
|
|
80
|
+
"@opentelemetry/api": "^1.9",
|
|
81
|
+
"@opentelemetry/sdk-trace-base": "^2.7",
|
|
82
|
+
"@scure/base": "~2.2",
|
|
83
|
+
"@scure/bip39": "~2.2",
|
|
84
|
+
"@xylabs/geo": "^6.0",
|
|
85
|
+
"@xylabs/sdk-js": "^6.0",
|
|
86
|
+
"@xylabs/threads": "~6.0",
|
|
87
|
+
"@xyo-network/address": "^6.0",
|
|
88
|
+
"@xyo-network/sdk-js": "^6.0",
|
|
89
|
+
"@xyo-network/sdk-protocol-js": "~6.0",
|
|
90
|
+
"ajv": "^8.20",
|
|
91
|
+
"async-mutex": "^0.5",
|
|
92
|
+
"bn.js": "^5.2",
|
|
93
|
+
"buffer": "^6.0",
|
|
94
|
+
"cosmiconfig": "^9.0",
|
|
95
|
+
"debug": "~4.4",
|
|
96
|
+
"ethers": "^6.16",
|
|
97
|
+
"hash-wasm": "~4.12",
|
|
98
|
+
"idb": "^8.0",
|
|
99
|
+
"lru-cache": "^11.3",
|
|
100
|
+
"observable-fns": "~0.6",
|
|
101
|
+
"webextension-polyfill": "^0.12",
|
|
102
|
+
"zod": "~4.4"
|
|
103
|
+
},
|
|
104
|
+
"engines": {
|
|
105
|
+
"node": ">=22.3"
|
|
106
|
+
},
|
|
107
|
+
"engineStrict": true,
|
|
108
|
+
"publishConfig": {
|
|
109
|
+
"access": "public"
|
|
110
|
+
}
|
|
111
|
+
}
|