Skip to content

Commit c93b18c

Browse files
committed
Manually create multiplex in executor
1 parent 39c6f7a commit c93b18c

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"branches": 81.08,
3-
"functions": 89.54,
4-
"lines": 90.92,
5-
"statements": 89.95
2+
"branches": 79.86,
3+
"functions": 88.96,
4+
"lines": 90.55,
5+
"statements": 89.61
66
}

packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment
22
/// <reference path="../../../../node_modules/ses/types.d.ts" />
33
import { createIdRemapMiddleware } from '@metamask/json-rpc-engine';
4+
import ObjectMultiplex from '@metamask/object-multiplex';
45
import type { RequestArguments, StreamProvider } from '@metamask/providers';
56
import { errorCodes, rpcErrors, serializeError } from '@metamask/rpc-errors';
67
import type { SnapsEthereumProvider, SnapsProvider } from '@metamask/snaps-sdk';
@@ -33,6 +34,7 @@ import {
3334
JsonRpcIdStruct,
3435
} from '@metamask/utils';
3536
import type { Duplex } from 'readable-stream';
37+
import { pipeline } from 'readable-stream';
3638

3739
import { log } from '../logging';
3840
import type { CommandMethodsMapping } from './commands';
@@ -369,11 +371,20 @@ export class BaseSnapExecutor {
369371
});
370372
};
371373

372-
const provider = new SnapProvider(this.rpcStream, {
373-
jsonRpcStreamName: 'metamask-provider',
374-
rpcMiddleware: [createIdRemapMiddleware()],
374+
const multiplex = new ObjectMultiplex();
375+
pipeline(this.rpcStream, multiplex, this.rpcStream, (error) => {
376+
if (error) {
377+
logError(`Provider stream failure.`, error);
378+
}
375379
});
376380

381+
const provider = new SnapProvider(
382+
multiplex.createStream('metamask-provider'),
383+
{
384+
rpcMiddleware: [createIdRemapMiddleware()],
385+
},
386+
);
387+
377388
provider.initializeSync();
378389

379390
const snap = this.createSnapGlobal(provider);

packages/snaps-execution-environments/src/common/test-utils/endowments.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export function getMockedStreamProvider(): SnapsEthereumProvider {
4444
const rpcStream = mux.createStream(SNAP_STREAM_NAMES.JSON_RPC);
4545

4646
const provider = new StreamProvider(rpcStream, {
47-
jsonRpcStreamName: 'metamask-provider',
4847
rpcMiddleware: [createIdRemapMiddleware()],
4948
logger: SILENT_LOGGER,
5049
});

0 commit comments

Comments
 (0)