smoldot 1.0.2 → 1.0.3
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/cjs/client.js +13 -13
- package/dist/cjs/instance/autogen/wasm0.js +1 -1
- package/dist/cjs/instance/autogen/wasm1.js +1 -1
- package/dist/cjs/instance/autogen/wasm2.js +1 -1
- package/dist/cjs/instance/bindings-smoldot-light.d.ts +6 -6
- package/dist/cjs/instance/bindings-smoldot-light.js +0 -4
- package/dist/cjs/instance/bindings-wasi.d.ts +4 -0
- package/dist/cjs/instance/bindings-wasi.js +30 -0
- package/dist/cjs/instance/buffer.d.ts +1 -0
- package/dist/cjs/instance/buffer.js +13 -1
- package/dist/cjs/instance/raw-instance.js +2 -1
- package/dist/mjs/client.js +13 -13
- package/dist/mjs/instance/autogen/wasm0.js +1 -1
- package/dist/mjs/instance/autogen/wasm1.js +1 -1
- package/dist/mjs/instance/autogen/wasm2.js +1 -1
- package/dist/mjs/instance/bindings-smoldot-light.d.ts +6 -6
- package/dist/mjs/instance/bindings-smoldot-light.js +0 -4
- package/dist/mjs/instance/bindings-wasi.d.ts +4 -0
- package/dist/mjs/instance/bindings-wasi.js +30 -0
- package/dist/mjs/instance/buffer.d.ts +1 -0
- package/dist/mjs/instance/buffer.js +11 -0
- package/dist/mjs/instance/raw-instance.js +2 -1
- package/package.json +2 -2
|
@@ -7,10 +7,6 @@ export interface Config {
|
|
|
7
7
|
* When `buffer_size` or `buffer_index` are called, the buffer is found here.
|
|
8
8
|
*/
|
|
9
9
|
bufferIndices: Array<Uint8Array>;
|
|
10
|
-
/**
|
|
11
|
-
* Returns the number of milliseconds since an arbitrary epoch.
|
|
12
|
-
*/
|
|
13
|
-
performanceNow: () => number;
|
|
14
10
|
/**
|
|
15
11
|
* Tries to open a new connection using the given configuration.
|
|
16
12
|
*
|
|
@@ -71,7 +67,7 @@ export interface Connection {
|
|
|
71
67
|
*
|
|
72
68
|
* The connection and stream must currently be in the `Open` state.
|
|
73
69
|
*
|
|
74
|
-
* The number of bytes
|
|
70
|
+
* The number of bytes must never exceed the number of "writable bytes" of the stream.
|
|
75
71
|
* `onWritableBytes` can be used in order to notify that more writable bytes are available.
|
|
76
72
|
*
|
|
77
73
|
* The `streamId` must be provided if and only if the connection is of type "multi-stream".
|
|
@@ -160,7 +156,8 @@ export interface ConnectionConfig {
|
|
|
160
156
|
*/
|
|
161
157
|
onStreamReset: (streamId: number) => void;
|
|
162
158
|
/**
|
|
163
|
-
* Callback called when
|
|
159
|
+
* Callback called when some data sent using {@link Connection.send} has effectively been
|
|
160
|
+
* written on the stream, meaning that some buffer space is now free.
|
|
164
161
|
*
|
|
165
162
|
* Can only happen while the connection is in the `Open` state.
|
|
166
163
|
*
|
|
@@ -168,6 +165,9 @@ export interface ConnectionConfig {
|
|
|
168
165
|
*
|
|
169
166
|
* The `streamId` parameter must be provided if and only if the connection is of type
|
|
170
167
|
* "multi-stream".
|
|
168
|
+
*
|
|
169
|
+
* Only a number of bytes equal to the size of the data provided to {@link Connection.send}
|
|
170
|
+
* must be reported. In other words, the `initialWritableBytes` must never be exceeded.
|
|
171
171
|
*/
|
|
172
172
|
onWritableBytes: (numExtra: number, streamId?: number) => void;
|
|
173
173
|
/**
|
|
@@ -85,10 +85,6 @@ export default function (config) {
|
|
|
85
85
|
config.logCallback(level, target, message);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
// Must return the UNIX time in milliseconds.
|
|
89
|
-
unix_time_ms: () => Date.now(),
|
|
90
|
-
// Must return the value of a monotonic clock in milliseconds.
|
|
91
|
-
monotonic_clock_ms: () => config.performanceNow(),
|
|
92
88
|
// Must call `timer_finished` after the given number of milliseconds has elapsed.
|
|
93
89
|
start_timer: (id, ms) => {
|
|
94
90
|
if (killedTracked.killed)
|
|
@@ -5,6 +5,10 @@ export interface Config {
|
|
|
5
5
|
* Fills the given buffer with randomly-generated bytes.
|
|
6
6
|
*/
|
|
7
7
|
getRandomValues: (buffer: Uint8Array) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the number of milliseconds since an arbitrary epoch.
|
|
10
|
+
*/
|
|
11
|
+
performanceNow: () => number;
|
|
8
12
|
/**
|
|
9
13
|
* List of environment variables to feed to the Rust program. An array of strings.
|
|
10
14
|
* Example: `["RUST_BACKTRACE=1", "RUST_LOG=foo"];`
|
|
@@ -39,6 +39,36 @@ export default (config) => {
|
|
|
39
39
|
}
|
|
40
40
|
return 0;
|
|
41
41
|
},
|
|
42
|
+
clock_time_get: (clockId, _precision, outPtr) => {
|
|
43
|
+
// See <https://github.com/rust-lang/rust/blob/master/library/std/src/sys/wasi/time.rs>
|
|
44
|
+
// and <docs.rs/wasi/> for help.
|
|
45
|
+
const instance = config.instance;
|
|
46
|
+
const mem = new Uint8Array(instance.exports.memory.buffer);
|
|
47
|
+
outPtr >>>= 0;
|
|
48
|
+
// We ignore the precision, as it can't be implemented anyway.
|
|
49
|
+
switch (clockId) {
|
|
50
|
+
case 0: {
|
|
51
|
+
// Realtime clock.
|
|
52
|
+
const now = BigInt(Math.floor(Date.now())) * BigInt(1000000);
|
|
53
|
+
buffer.writeUInt64LE(mem, outPtr, now);
|
|
54
|
+
// Success.
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
case 1: {
|
|
58
|
+
// Monotonic clock.
|
|
59
|
+
const nowMs = config.performanceNow();
|
|
60
|
+
const nowMsInt = Math.floor(nowMs);
|
|
61
|
+
const now = BigInt(nowMsInt) * BigInt(1000000) +
|
|
62
|
+
BigInt(Math.floor(((nowMs - nowMsInt) * 1000000)));
|
|
63
|
+
buffer.writeUInt64LE(mem, outPtr, now);
|
|
64
|
+
// Success.
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
// Return an `EINVAL` error.
|
|
69
|
+
return 28;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
42
72
|
// Writing to a file descriptor is used in order to write to stdout/stderr.
|
|
43
73
|
fd_write: (fd, addr, num, outPtr) => {
|
|
44
74
|
const instance = config.instance;
|
|
@@ -8,3 +8,4 @@ export declare function readUInt32LE(buffer: Uint8Array, offset: number): number
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function writeUInt8(buffer: Uint8Array, offset: number, value: number): void;
|
|
10
10
|
export declare function writeUInt32LE(buffer: Uint8Array, offset: number, value: number): void;
|
|
11
|
+
export declare function writeUInt64LE(buffer: Uint8Array, offset: number, value: bigint): void;
|
|
@@ -38,6 +38,17 @@ export function writeUInt32LE(buffer, offset, value) {
|
|
|
38
38
|
buffer[offset + 1] = (value >>> 8) & 0xff;
|
|
39
39
|
buffer[offset] = value & 0xff;
|
|
40
40
|
}
|
|
41
|
+
export function writeUInt64LE(buffer, offset, value) {
|
|
42
|
+
checkRange(buffer, offset, 8);
|
|
43
|
+
buffer[offset + 7] = Number((value >> BigInt(56)) & BigInt(0xff));
|
|
44
|
+
buffer[offset + 6] = Number((value >> BigInt(48)) & BigInt(0xff));
|
|
45
|
+
buffer[offset + 5] = Number((value >> BigInt(40)) & BigInt(0xff));
|
|
46
|
+
buffer[offset + 4] = Number((value >> BigInt(32)) & BigInt(0xff));
|
|
47
|
+
buffer[offset + 3] = Number((value >> BigInt(24)) & BigInt(0xff));
|
|
48
|
+
buffer[offset + 2] = Number((value >> BigInt(16)) & BigInt(0xff));
|
|
49
|
+
buffer[offset + 1] = Number((value >> BigInt(8)) & BigInt(0xff));
|
|
50
|
+
buffer[offset] = Number(value & BigInt(0xff));
|
|
51
|
+
}
|
|
41
52
|
function checkRange(buffer, offset, length) {
|
|
42
53
|
if (!Number.isInteger(offset) || offset < 0)
|
|
43
54
|
throw new RangeError();
|
|
@@ -34,7 +34,7 @@ export function startInstance(config, platformBindings) {
|
|
|
34
34
|
let killAll;
|
|
35
35
|
const bufferIndices = new Array;
|
|
36
36
|
// Used to bind with the smoldot-light bindings. See the `bindings-smoldot-light.js` file.
|
|
37
|
-
const smoldotJsConfig = Object.assign({ bufferIndices,
|
|
37
|
+
const smoldotJsConfig = Object.assign({ bufferIndices, connect: platformBindings.connect, onPanic: (message) => {
|
|
38
38
|
killAll();
|
|
39
39
|
config.onWasmPanic(message);
|
|
40
40
|
throw new Error();
|
|
@@ -43,6 +43,7 @@ export function startInstance(config, platformBindings) {
|
|
|
43
43
|
const wasiConfig = {
|
|
44
44
|
envVars: [],
|
|
45
45
|
getRandomValues: platformBindings.getRandomValues,
|
|
46
|
+
performanceNow: platformBindings.performanceNow,
|
|
46
47
|
onProcExit: (retCode) => {
|
|
47
48
|
killAll();
|
|
48
49
|
config.onWasmPanic(`proc_exit called: ${retCode}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smoldot",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Light client that connects to Polkadot and Substrate-based blockchains",
|
|
5
5
|
"author": "Parity Technologies <admin@parity.io>",
|
|
6
6
|
"license": "GPL-3.0-or-later WITH Classpath-exception-2.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/ws": "^8.5.3",
|
|
47
47
|
"ava": "^5.0.1",
|
|
48
48
|
"dtslint": "^4.0.6",
|
|
49
|
-
"rimraf": "^
|
|
49
|
+
"rimraf": "^5.0.0",
|
|
50
50
|
"typedoc": "^0.24.1",
|
|
51
51
|
"typescript": "^5.0.2"
|
|
52
52
|
}
|