@parity/truapi-provider 0.2.1 → 0.2.3-dev-20260928.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/README.md CHANGED
@@ -63,6 +63,26 @@ syncs from the checkpoint in the chain spec on every run.
63
63
  anything the client would load for it. `saveDatabase(genesisHash)` forces a write
64
64
  at a moment the host chooses.
65
65
 
66
+ A light-client connection holds its requests until the chain first syncs, then
67
+ sends them in order. Chain-spec queries, statement-store and Bitswap calls are
68
+ answered at once. To show sync
69
+ progress, watch the chain once something is connected to it:
70
+
71
+ ```js
72
+ const watch = provider.lifecycle(chains.relay);
73
+ for (let state; (state = await watch.next()); ) {
74
+ // state.phase: { kind: "connecting" } | { kind: "syncing", at, target } | { kind: "ready" }
75
+ // state.peers: connected peer count
76
+ // state.health: { kind: "ok" } | { kind: "stalled", reason: "noPeers" | "noProgress" }
77
+ }
78
+ ```
79
+
80
+ The first `next()` resolves with the current state, and each later one with the
81
+ next change. It resolves `undefined` after `watch.close()` or once nothing holds
82
+ the chain. A parachain goes from `connecting` straight to `ready`, so watch its
83
+ relay for warp sync progress. `lifecycle` throws for a chain nothing is
84
+ connected to.
85
+
66
86
  ## Native hosts
67
87
 
68
88
  Android and iOS do not consume this package. The same `truapi-provider` crate is
@@ -1,6 +1,18 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /** What the light client is doing on one chain. */
5
+ export interface ChainLifecycle {
6
+ phase:
7
+ | { kind: "connecting" }
8
+ | { kind: "syncing"; at: number; target: number }
9
+ | { kind: "ready" };
10
+ peers: number;
11
+ health: { kind: "ok" } | { kind: "stalled"; reason: "noPeers" | "noProgress" };
12
+ }
13
+
14
+
15
+
4
16
  /**
5
17
  * Collects genesis-hash to chain-source registrations from JS.
6
18
  */
@@ -82,6 +94,14 @@ export class ChainProviderHandle {
82
94
  * the light client already holds as many connections as it allows.
83
95
  */
84
96
  connect(genesis_hash: string): Promise<Connection>;
97
+ /**
98
+ * Watch what the light client is doing on the chain identified by the
99
+ * `0x`-prefixed genesis hash. Throws when nothing is connected to it.
100
+ *
101
+ * A parachain goes from `connecting` straight to `ready`; watch its relay
102
+ * for warp sync progress.
103
+ */
104
+ lifecycle(genesis_hash: string): LifecycleWatch;
85
105
  /**
86
106
  * Read the stored blob for the `0x`-prefixed genesis hash into this
87
107
  * provider, so the next [`connect`](ChainProviderHandle::connect) to that
@@ -133,6 +153,26 @@ export class Connection {
133
153
  send(request: string): void;
134
154
  }
135
155
 
156
+ /**
157
+ * A live watch on one chain's lifecycle, from
158
+ * [`ChainProviderHandle::lifecycle`].
159
+ */
160
+ export class LifecycleWatch {
161
+ private constructor();
162
+ free(): void;
163
+ [Symbol.dispose](): void;
164
+ /**
165
+ * Stop the watch; pending `next()` calls resolve to `undefined`.
166
+ */
167
+ close(): void;
168
+ /**
169
+ * Resolve with the current state on the first call and with the next
170
+ * change after that, or with `undefined` once the watch is closed or the
171
+ * chain stops running.
172
+ */
173
+ next(): Promise<ChainLifecycle | undefined>;
174
+ }
175
+
136
176
  /**
137
177
  * The genesis hashes of a network registered via
138
178
  * [`ChainProviderBuilder::add_network`], as `0x`-prefixed hex strings.
@@ -174,6 +214,7 @@ export interface InitOutput {
174
214
  readonly __wbg_chainproviderbuilder_free: (a: number, b: number) => void;
175
215
  readonly __wbg_chainproviderhandle_free: (a: number, b: number) => void;
176
216
  readonly __wbg_connection_free: (a: number, b: number) => void;
217
+ readonly __wbg_lifecyclewatch_free: (a: number, b: number) => void;
177
218
  readonly __wbg_networkchains_free: (a: number, b: number) => void;
178
219
  readonly chainproviderbuilder_addLightChain: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
179
220
  readonly chainproviderbuilder_addNetwork: (a: number, b: number, c: number, d: number) => void;
@@ -183,22 +224,25 @@ export interface InitOutput {
183
224
  readonly chainproviderbuilder_setDatabaseContent: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
184
225
  readonly chainproviderbuilder_setStorage: (a: number, b: number, c: number) => void;
185
226
  readonly chainproviderhandle_connect: (a: number, b: number, c: number) => number;
227
+ readonly chainproviderhandle_lifecycle: (a: number, b: number, c: number, d: number) => void;
186
228
  readonly chainproviderhandle_loadDatabase: (a: number, b: number, c: number) => number;
187
229
  readonly chainproviderhandle_saveDatabase: (a: number, b: number, c: number) => number;
188
230
  readonly connection_close: (a: number) => void;
189
231
  readonly connection_nextResponse: (a: number) => number;
190
232
  readonly connection_send: (a: number, b: number, c: number) => void;
233
+ readonly lifecyclewatch_close: (a: number) => void;
234
+ readonly lifecyclewatch_next: (a: number) => number;
191
235
  readonly networkchains_assethub: (a: number, b: number) => void;
192
236
  readonly networkchains_bulletin: (a: number, b: number) => void;
193
237
  readonly networkchains_people: (a: number, b: number) => void;
194
238
  readonly networkchains_relay: (a: number, b: number) => void;
195
239
  readonly setLogLevel: (a: number, b: number) => void;
196
- readonly __wasm_bindgen_func_elem_20031: (a: number, b: number, c: number, d: number) => void;
197
- readonly __wasm_bindgen_func_elem_20033: (a: number, b: number, c: number, d: number) => void;
198
- readonly __wasm_bindgen_func_elem_3926: (a: number, b: number, c: number) => void;
199
- readonly __wasm_bindgen_func_elem_3926_2: (a: number, b: number, c: number) => void;
200
- readonly __wasm_bindgen_func_elem_3926_3: (a: number, b: number, c: number) => void;
201
- readonly __wasm_bindgen_func_elem_7481: (a: number, b: number) => void;
240
+ readonly __wasm_bindgen_func_elem_20550: (a: number, b: number, c: number, d: number) => void;
241
+ readonly __wasm_bindgen_func_elem_20552: (a: number, b: number, c: number, d: number) => void;
242
+ readonly __wasm_bindgen_func_elem_3964: (a: number, b: number, c: number) => void;
243
+ readonly __wasm_bindgen_func_elem_3964_2: (a: number, b: number, c: number) => void;
244
+ readonly __wasm_bindgen_func_elem_3964_3: (a: number, b: number, c: number) => void;
245
+ readonly __wasm_bindgen_func_elem_7556: (a: number, b: number) => void;
202
246
  readonly __wbindgen_export: (a: number, b: number) => number;
203
247
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
204
248
  readonly __wbindgen_export3: (a: number) => void;
@@ -215,6 +215,32 @@ export class ChainProviderHandle {
215
215
  const ret = wasm.chainproviderhandle_connect(this.__wbg_ptr, ptr0, len0);
216
216
  return takeObject(ret);
217
217
  }
218
+ /**
219
+ * Watch what the light client is doing on the chain identified by the
220
+ * `0x`-prefixed genesis hash. Throws when nothing is connected to it.
221
+ *
222
+ * A parachain goes from `connecting` straight to `ready`; watch its relay
223
+ * for warp sync progress.
224
+ * @param {string} genesis_hash
225
+ * @returns {LifecycleWatch}
226
+ */
227
+ lifecycle(genesis_hash) {
228
+ try {
229
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
230
+ const ptr0 = passStringToWasm0(genesis_hash, wasm.__wbindgen_export, wasm.__wbindgen_export2);
231
+ const len0 = WASM_VECTOR_LEN;
232
+ wasm.chainproviderhandle_lifecycle(retptr, this.__wbg_ptr, ptr0, len0);
233
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
234
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
235
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
236
+ if (r2) {
237
+ throw takeObject(r1);
238
+ }
239
+ return LifecycleWatch.__wrap(r0);
240
+ } finally {
241
+ wasm.__wbindgen_add_to_stack_pointer(16);
242
+ }
243
+ }
218
244
  /**
219
245
  * Read the stored blob for the `0x`-prefixed genesis hash into this
220
246
  * provider, so the next [`connect`](ChainProviderHandle::connect) to that
@@ -306,6 +332,46 @@ export class Connection {
306
332
  }
307
333
  if (Symbol.dispose) Connection.prototype[Symbol.dispose] = Connection.prototype.free;
308
334
 
335
+ /**
336
+ * A live watch on one chain's lifecycle, from
337
+ * [`ChainProviderHandle::lifecycle`].
338
+ */
339
+ export class LifecycleWatch {
340
+ static __wrap(ptr) {
341
+ const obj = Object.create(LifecycleWatch.prototype);
342
+ obj.__wbg_ptr = ptr;
343
+ LifecycleWatchFinalization.register(obj, obj.__wbg_ptr, obj);
344
+ return obj;
345
+ }
346
+ __destroy_into_raw() {
347
+ const ptr = this.__wbg_ptr;
348
+ this.__wbg_ptr = 0;
349
+ LifecycleWatchFinalization.unregister(this);
350
+ return ptr;
351
+ }
352
+ free() {
353
+ const ptr = this.__destroy_into_raw();
354
+ wasm.__wbg_lifecyclewatch_free(ptr, 0);
355
+ }
356
+ /**
357
+ * Stop the watch; pending `next()` calls resolve to `undefined`.
358
+ */
359
+ close() {
360
+ wasm.lifecyclewatch_close(this.__wbg_ptr);
361
+ }
362
+ /**
363
+ * Resolve with the current state on the first call and with the next
364
+ * change after that, or with `undefined` once the watch is closed or the
365
+ * chain stops running.
366
+ * @returns {ChainLifecycle | undefined}
367
+ */
368
+ next() {
369
+ const ret = wasm.lifecyclewatch_next(this.__wbg_ptr);
370
+ return takeObject(ret);
371
+ }
372
+ }
373
+ if (Symbol.dispose) LifecycleWatch.prototype[Symbol.dispose] = LifecycleWatch.prototype.free;
374
+
309
375
  /**
310
376
  * The genesis hashes of a network registered via
311
377
  * [`ChainProviderBuilder::add_network`], as `0x`-prefixed hex strings.
@@ -551,7 +617,7 @@ function __wbg_get_imports() {
551
617
  const a = state0.a;
552
618
  state0.a = 0;
553
619
  try {
554
- return __wasm_bindgen_func_elem_20033(a, state0.b, arg0, arg1);
620
+ return __wasm_bindgen_func_elem_20552(a, state0.b, arg0, arg1);
555
621
  } finally {
556
622
  state0.a = a;
557
623
  }
@@ -578,6 +644,10 @@ function __wbg_get_imports() {
578
644
  const ret = getObject(arg0).now();
579
645
  return ret;
580
646
  },
647
+ __wbg_parse_1c0d8a8656d7e016: function() { return handleError(function (arg0, arg1) {
648
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
649
+ return addHeapObject(ret);
650
+ }, arguments); },
581
651
  __wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
582
652
  const ret = getObject(arg0).performance;
583
653
  return addHeapObject(ret);
@@ -672,28 +742,28 @@ function __wbg_get_imports() {
672
742
  console.warn(getObject(arg0));
673
743
  },
674
744
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
675
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1864, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
676
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_20031);
745
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1891, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
746
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_20550);
677
747
  return addHeapObject(ret);
678
748
  },
679
749
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
680
750
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx: 20, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
681
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3926);
751
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3964);
682
752
  return addHeapObject(ret);
683
753
  },
684
754
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
685
755
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 20, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
686
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3926_2);
756
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3964_2);
687
757
  return addHeapObject(ret);
688
758
  },
689
759
  __wbindgen_cast_0000000000000004: function(arg0, arg1) {
690
760
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 20, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
691
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3926_3);
761
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3964_3);
692
762
  return addHeapObject(ret);
693
763
  },
694
764
  __wbindgen_cast_0000000000000005: function(arg0, arg1) {
695
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 714, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
696
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_7481);
765
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 726, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
766
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_7556);
697
767
  return addHeapObject(ret);
698
768
  },
699
769
  __wbindgen_cast_0000000000000006: function(arg0, arg1) {
@@ -720,26 +790,26 @@ function __wbg_get_imports() {
720
790
  };
721
791
  }
722
792
 
723
- function __wasm_bindgen_func_elem_7481(arg0, arg1) {
724
- wasm.__wasm_bindgen_func_elem_7481(arg0, arg1);
793
+ function __wasm_bindgen_func_elem_7556(arg0, arg1) {
794
+ wasm.__wasm_bindgen_func_elem_7556(arg0, arg1);
725
795
  }
726
796
 
727
- function __wasm_bindgen_func_elem_3926(arg0, arg1, arg2) {
728
- wasm.__wasm_bindgen_func_elem_3926(arg0, arg1, addHeapObject(arg2));
797
+ function __wasm_bindgen_func_elem_3964(arg0, arg1, arg2) {
798
+ wasm.__wasm_bindgen_func_elem_3964(arg0, arg1, addHeapObject(arg2));
729
799
  }
730
800
 
731
- function __wasm_bindgen_func_elem_3926_2(arg0, arg1, arg2) {
732
- wasm.__wasm_bindgen_func_elem_3926_2(arg0, arg1, addHeapObject(arg2));
801
+ function __wasm_bindgen_func_elem_3964_2(arg0, arg1, arg2) {
802
+ wasm.__wasm_bindgen_func_elem_3964_2(arg0, arg1, addHeapObject(arg2));
733
803
  }
734
804
 
735
- function __wasm_bindgen_func_elem_3926_3(arg0, arg1, arg2) {
736
- wasm.__wasm_bindgen_func_elem_3926_3(arg0, arg1, addHeapObject(arg2));
805
+ function __wasm_bindgen_func_elem_3964_3(arg0, arg1, arg2) {
806
+ wasm.__wasm_bindgen_func_elem_3964_3(arg0, arg1, addHeapObject(arg2));
737
807
  }
738
808
 
739
- function __wasm_bindgen_func_elem_20031(arg0, arg1, arg2) {
809
+ function __wasm_bindgen_func_elem_20550(arg0, arg1, arg2) {
740
810
  try {
741
811
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
742
- wasm.__wasm_bindgen_func_elem_20031(retptr, arg0, arg1, addHeapObject(arg2));
812
+ wasm.__wasm_bindgen_func_elem_20550(retptr, arg0, arg1, addHeapObject(arg2));
743
813
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
744
814
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
745
815
  if (r1) {
@@ -750,8 +820,8 @@ function __wasm_bindgen_func_elem_20031(arg0, arg1, arg2) {
750
820
  }
751
821
  }
752
822
 
753
- function __wasm_bindgen_func_elem_20033(arg0, arg1, arg2, arg3) {
754
- wasm.__wasm_bindgen_func_elem_20033(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
823
+ function __wasm_bindgen_func_elem_20552(arg0, arg1, arg2, arg3) {
824
+ wasm.__wasm_bindgen_func_elem_20552(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
755
825
  }
756
826
 
757
827
 
@@ -765,6 +835,9 @@ const ChainProviderHandleFinalization = (typeof FinalizationRegistry === 'undefi
765
835
  const ConnectionFinalization = (typeof FinalizationRegistry === 'undefined')
766
836
  ? { register: () => {}, unregister: () => {} }
767
837
  : new FinalizationRegistry(ptr => wasm.__wbg_connection_free(ptr, 1));
838
+ const LifecycleWatchFinalization = (typeof FinalizationRegistry === 'undefined')
839
+ ? { register: () => {}, unregister: () => {} }
840
+ : new FinalizationRegistry(ptr => wasm.__wbg_lifecyclewatch_free(ptr, 1));
768
841
  const NetworkChainsFinalization = (typeof FinalizationRegistry === 'undefined')
769
842
  ? { register: () => {}, unregister: () => {} }
770
843
  : new FinalizationRegistry(ptr => wasm.__wbg_networkchains_free(ptr, 1));
Binary file
@@ -4,6 +4,7 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_chainproviderbuilder_free: (a: number, b: number) => void;
5
5
  export const __wbg_chainproviderhandle_free: (a: number, b: number) => void;
6
6
  export const __wbg_connection_free: (a: number, b: number) => void;
7
+ export const __wbg_lifecyclewatch_free: (a: number, b: number) => void;
7
8
  export const __wbg_networkchains_free: (a: number, b: number) => void;
8
9
  export const chainproviderbuilder_addLightChain: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
9
10
  export const chainproviderbuilder_addNetwork: (a: number, b: number, c: number, d: number) => void;
@@ -13,22 +14,25 @@ export const chainproviderbuilder_new: () => number;
13
14
  export const chainproviderbuilder_setDatabaseContent: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
14
15
  export const chainproviderbuilder_setStorage: (a: number, b: number, c: number) => void;
15
16
  export const chainproviderhandle_connect: (a: number, b: number, c: number) => number;
17
+ export const chainproviderhandle_lifecycle: (a: number, b: number, c: number, d: number) => void;
16
18
  export const chainproviderhandle_loadDatabase: (a: number, b: number, c: number) => number;
17
19
  export const chainproviderhandle_saveDatabase: (a: number, b: number, c: number) => number;
18
20
  export const connection_close: (a: number) => void;
19
21
  export const connection_nextResponse: (a: number) => number;
20
22
  export const connection_send: (a: number, b: number, c: number) => void;
23
+ export const lifecyclewatch_close: (a: number) => void;
24
+ export const lifecyclewatch_next: (a: number) => number;
21
25
  export const networkchains_assethub: (a: number, b: number) => void;
22
26
  export const networkchains_bulletin: (a: number, b: number) => void;
23
27
  export const networkchains_people: (a: number, b: number) => void;
24
28
  export const networkchains_relay: (a: number, b: number) => void;
25
29
  export const setLogLevel: (a: number, b: number) => void;
26
- export const __wasm_bindgen_func_elem_20031: (a: number, b: number, c: number, d: number) => void;
27
- export const __wasm_bindgen_func_elem_20033: (a: number, b: number, c: number, d: number) => void;
28
- export const __wasm_bindgen_func_elem_3926: (a: number, b: number, c: number) => void;
29
- export const __wasm_bindgen_func_elem_3926_2: (a: number, b: number, c: number) => void;
30
- export const __wasm_bindgen_func_elem_3926_3: (a: number, b: number, c: number) => void;
31
- export const __wasm_bindgen_func_elem_7481: (a: number, b: number) => void;
30
+ export const __wasm_bindgen_func_elem_20550: (a: number, b: number, c: number, d: number) => void;
31
+ export const __wasm_bindgen_func_elem_20552: (a: number, b: number, c: number, d: number) => void;
32
+ export const __wasm_bindgen_func_elem_3964: (a: number, b: number, c: number) => void;
33
+ export const __wasm_bindgen_func_elem_3964_2: (a: number, b: number, c: number) => void;
34
+ export const __wasm_bindgen_func_elem_3964_3: (a: number, b: number, c: number) => void;
35
+ export const __wasm_bindgen_func_elem_7556: (a: number, b: number) => void;
32
36
  export const __wbindgen_export: (a: number, b: number) => number;
33
37
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
34
38
  export const __wbindgen_export3: (a: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parity/truapi-provider",
3
- "version": "0.2.1",
3
+ "version": "0.2.3-dev-20260928.0",
4
4
  "description": "Network provider backends for the TrUAPI ChainProvider: an embedded smoldot light client and remote WebSocket JSON-RPC nodes, compiled to WebAssembly for browser hosts",
5
5
  "license": "MIT AND Apache-2.0",
6
6
  "author": "Parity Technologies <admin@parity.io>",