@novasamatech/host-container 0.5.4-5 → 0.5.4-7
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/createContainer.js +17 -9
- package/dist/types.d.ts +3 -3
- package/package.json +2 -2
package/dist/createContainer.js
CHANGED
|
@@ -257,35 +257,43 @@ export function createContainer(provider) {
|
|
|
257
257
|
.unwrapOr(enumValue(version, resultErr(error)));
|
|
258
258
|
});
|
|
259
259
|
},
|
|
260
|
-
|
|
260
|
+
handleChainConnection(factory) {
|
|
261
261
|
init();
|
|
262
|
-
return transport.handleSubscription('jsonrpc_message_subscribe', (params, send) => {
|
|
262
|
+
return transport.handleSubscription('jsonrpc_message_subscribe', (params, send, interrupt) => {
|
|
263
263
|
assertEnumVariant(params, 'v1', UNSUPPORTED_MESSAGE_FORMAT_ERROR);
|
|
264
|
-
|
|
264
|
+
const genesisHash = params.value;
|
|
265
|
+
const provider = factory(params.value);
|
|
266
|
+
if (provider === null) {
|
|
265
267
|
return () => {
|
|
266
268
|
// empty subscription, we don't want to react to foreign chain subscription request
|
|
267
269
|
};
|
|
268
270
|
}
|
|
269
271
|
const connection = provider(message => send(enumValue('v1', message)));
|
|
272
|
+
const unsubscribeDestroy = transport.onDestroy(() => {
|
|
273
|
+
unsubRequests();
|
|
274
|
+
unsubscribeDestroy();
|
|
275
|
+
connection.disconnect();
|
|
276
|
+
interrupt();
|
|
277
|
+
});
|
|
270
278
|
const unsubRequests = transport.handleRequest('jsonrpc_message_send', async (message) => {
|
|
271
279
|
assertEnumVariant(message, 'v1', UNSUPPORTED_MESSAGE_FORMAT_ERROR);
|
|
272
280
|
const [requestedGenesisHash, payload] = message.value;
|
|
273
|
-
if (requestedGenesisHash
|
|
274
|
-
|
|
281
|
+
if (requestedGenesisHash === genesisHash) {
|
|
282
|
+
connection.send(payload);
|
|
275
283
|
}
|
|
276
|
-
connection.send(payload);
|
|
277
284
|
return enumValue('v1', resultOk(undefined));
|
|
278
285
|
});
|
|
279
286
|
return () => {
|
|
280
287
|
unsubRequests();
|
|
281
|
-
|
|
288
|
+
unsubscribeDestroy();
|
|
289
|
+
connection.disconnect();
|
|
282
290
|
};
|
|
283
291
|
});
|
|
284
292
|
},
|
|
285
293
|
isReady() {
|
|
286
294
|
return transport.isReady();
|
|
287
295
|
},
|
|
288
|
-
|
|
296
|
+
subscribeProductConnectionStatus(callback) {
|
|
289
297
|
// this specific order exists because container should report all connection statuses including "disconnected",
|
|
290
298
|
// which immediately got changed to "connecting" after init() call.
|
|
291
299
|
const unsubscribe = transport.onConnectionStatusChange(callback);
|
|
@@ -293,7 +301,7 @@ export function createContainer(provider) {
|
|
|
293
301
|
return unsubscribe;
|
|
294
302
|
},
|
|
295
303
|
dispose() {
|
|
296
|
-
transport.
|
|
304
|
+
transport.destroy();
|
|
297
305
|
},
|
|
298
306
|
};
|
|
299
307
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Codec, CodecType, ConnectionStatus, HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from '@novasamatech/host-api';
|
|
1
|
+
import type { Codec, CodecType, ConnectionStatus, HexString, HostApiProtocol, VersionedProtocolRequest, VersionedProtocolSubscription } from '@novasamatech/host-api';
|
|
2
2
|
import type { JsonRpcProvider } from '@polkadot-api/json-rpc-provider';
|
|
3
3
|
import type { ResultAsync, errAsync } from 'neverthrow';
|
|
4
4
|
import { okAsync } from 'neverthrow';
|
|
@@ -70,9 +70,9 @@ export type Container = {
|
|
|
70
70
|
handleStatementStoreSubscribe: InferHandler<'v1', HostApiProtocol['statement_store_subscribe']>;
|
|
71
71
|
handleStatementStoreCreateProof: InferHandler<'v1', HostApiProtocol['statement_store_create_proof']>;
|
|
72
72
|
handleStatementStoreSubmit: InferHandler<'v1', HostApiProtocol['statement_store_submit']>;
|
|
73
|
-
|
|
73
|
+
handleChainConnection: (factory: (genesisHash: HexString) => JsonRpcProvider | null) => VoidFunction;
|
|
74
74
|
isReady(): Promise<boolean>;
|
|
75
75
|
dispose(): void;
|
|
76
|
-
|
|
76
|
+
subscribeProductConnectionStatus(callback: (connectionStatus: ConnectionStatus) => void): VoidFunction;
|
|
77
77
|
};
|
|
78
78
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/host-container",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.4-
|
|
4
|
+
"version": "0.5.4-7",
|
|
5
5
|
"description": "Host container for hosting and managing products within the Polkadot ecosystem.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@polkadot-api/utils": "^0.2.0",
|
|
30
30
|
"@polkadot-api/json-rpc-provider": "^0.0.4",
|
|
31
|
-
"@novasamatech/host-api": "0.5.4-
|
|
31
|
+
"@novasamatech/host-api": "0.5.4-7",
|
|
32
32
|
"nanoid": "5.1.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|