You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add context parameter to InternalProvider and JsonRpcServer methods (#7061)
## Explanation
Adds a `MiddlewareContext` parameter to `InternalProvider.request()` and
`JsonRpcServer.handle()`. This is essentially a missing feature from the
`JsonRpcEngineV2` implementation / migration, since callers are no
longer able to add non-JSON-RPC properties to request objects and
instead need to use the `context` object.
As part of this, permit specifying a plain object as the context to
avoid forcing callers to import `MiddlewareContext` whenever they want
to make a JSON-RPC call with some particular context. Also
opportunistically fixes a bug with the static `isInstance` methods of V2
engine classes, where we wouldn't walk the prototype chain when checking
for the symbol property.
## References
- Related to #6327
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- ~I've prepared draft pull requests for clients and consumer packages
to resolve any breaking changes~
- These changes are non-breaking, and will in any event be exhaustively
covered via preview builds through #7065.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds a context option to
`InternalProvider.request()`/`JsonRpcServer.handle()`, enables passing
plain-object contexts across the V2 engine, makes `PollingBlockTracker`
context-generic, and narrows Network Controller’s `Provider` type;
updates tests/docs accordingly.
>
> - **JSON-RPC Engine (v2)**:
> - Add `HandleOptions` with `context` (accepts `MiddlewareContext` or
plain object) and forward it through `handle()` and
`JsonRpcServer.handle()`.
> - Enhance `MiddlewareContext` (construct from KeyValues object,
`isInstance`) and export `InferKeyValues`; add shared `isInstance` util;
minor server refactor (static request coercion).
> - Update README and tests for context passing and utils.
> - **eth-json-rpc-provider**:
> - Make `InternalProvider` generic over `Context`; `request()` accepts
`{ context }` and forwards to engine.
> - Update tests and CHANGELOG.
> - **eth-block-tracker**:
> - Genericize `PollingBlockTracker` with `Context`; type provider as
`InternalProvider<Context>`; update CHANGELOG.
> - **Network Controller**:
> - Narrow `Provider` to `InternalProvider<MiddlewareContext<{ origin:
string; skipCache: boolean } & Record<string, unknown>>>`.
> - Type updates in `create-network-client`, tests, and helpers; update
CHANGELOG.
> - **Tests/Utilities**:
> - Update fakes (`FakeProvider`, `FakeBlockTracker`) and consumers to
new generic/context types.
> - Bridge controller test now uses `@metamask/network-controller`
`Provider`.
> - **Deps**:
> - Add `@metamask/network-controller` to root `package.json`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c853283. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
0 commit comments