Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/eth-json-rpc-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add new function `providerAsMiddlewareV2` for converting an `InternalProvider` into a `JsonRpcEngine` v2-compatible middleware ([#7138](https://github.com/MetaMask/core/pull/7138))

### Changed

- **BREAKING:** Migrate to `JsonRpcEngineV2` ([#7065](https://github.com/MetaMask/core/pull/7065))
- Migrates all middleware from `JsonRpcEngine` to `JsonRpcEngineV2`.
- Signatures of various middleware dependencies, e.g. `processTransaction` of `createWalletMiddleware`, have changed
and must be updated by consumers.
- Be advised that request objects are now deeply frozen, and cannot be mutated.
- **BREAKING:** Migrate all middleware from `JsonRpcEngine` to `JsonRpcEngineV2` ([#7065](https://github.com/MetaMask/core/pull/7065))
- To continue using this package with the legacy `JsonRpcEngine`, use the `asLegacyMiddleware` backwards compatibility function.
- **BREAKING:** Change the signatures of hooks for `createWalletMiddleware` ([#7065](https://github.com/MetaMask/core/pull/7065))
- To wit:
- `getAccounts` takes an origin argument (`string`) instead of a `JsonRpcRequest`
- `processDecryptMessage` and `processEncryptionPublicKey` take a `MessageRequest` from `@metamask/message-manager` instead of `JsonRpcRequest`
- `processPersonalMessage`, `processTransaction`, `processSignTransaction`, `processTypedMessage`, `processTypedMessageV3` and `processTypedMessageV4` take a `context` as the third argument, before any other arguments
- Be advised that request objects are now deeply frozen, and cannot be mutated.
- **BREAKING:** Use `InternalProvider` instead of `SafeEventEmitterProvider` ([#6796](https://github.com/MetaMask/core/pull/6796))
- Wherever a `SafeEventEmitterProvider` was expected, an `InternalProvider` is now expected instead.
- **BREAKING:** Stop retrying `undefined` results for methods that include a block tag parameter ([#7001](https://github.com/MetaMask/core/pull/7001))
- The `retryOnEmpty` middleware will now throw an error if it encounters an `undefined` result when dispatching
a request with a later block number than the originally requested block number.
- In practice, this should happen rarely if ever.
- Migrate all uses of `interface` to `type` ([#6885](https://github.com/MetaMask/core/pull/6885))
- **BREAKING:** Migrate all uses of `interface` to `type` ([#6885](https://github.com/MetaMask/core/pull/6885))

## [21.0.0]

Expand Down
19 changes: 11 additions & 8 deletions packages/eth-json-rpc-middleware/src/inflight-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
import { projectLogger, createModuleLogger } from './logging-utils';
import { cacheIdentifierForRequest } from './utils/cache';

type RequestHandler = [(result: Json) => void, (error: Error) => void];
type RequestHandler = [
(result: Readonly<Json>) => void,
(error: unknown) => void,
];

type InflightRequest = {
[cacheId: string]: RequestHandler[];
Expand Down Expand Up @@ -64,7 +67,7 @@ export function createInflightCacheMiddleware(): JsonRpcMiddleware<
// allow request to be handled normally
log('Carrying original request forward %o', request);
try {
const result = (await next()) as Json;
const result = (await next()) as Readonly<Json>;
log(
'Running %i collected handler(s) for successful request %o',
activeRequestHandlers.length,
Expand All @@ -78,7 +81,7 @@ export function createInflightCacheMiddleware(): JsonRpcMiddleware<
activeRequestHandlers.length,
request,
);
runRequestHandlers({ error: error as Error }, activeRequestHandlers);
runRequestHandlers({ error }, activeRequestHandlers);
throw error;
} finally {
delete inflightRequests[cacheId];
Expand All @@ -94,11 +97,11 @@ export function createInflightCacheMiddleware(): JsonRpcMiddleware<
*/
function createActiveRequestHandler(
activeRequestHandlers: RequestHandler[],
): Promise<Json> {
const { resolve, promise, reject } = createDeferredPromise<Json>();
): Promise<Readonly<Json>> {
const { resolve, promise, reject } = createDeferredPromise<Readonly<Json>>();
activeRequestHandlers.push([
(result: Json) => resolve(result),
(error: Error) => reject(error),
(result: Readonly<Json>) => resolve(result),
(error: unknown) => reject(error),
]);
return promise;
}
Expand All @@ -110,7 +113,7 @@ function createActiveRequestHandler(
* @param activeRequestHandlers - The active request handlers.
*/
function runRequestHandlers(
resultOrError: { result: Json } | { error: Error },
resultOrError: { result: Readonly<Json> } | { error: unknown },
activeRequestHandlers: RequestHandler[],
): void {
// use setTimeout so we can handle the original request first
Expand Down
5 changes: 5 additions & 0 deletions packages/message-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Rename `OriginalRequest` type to `MessageRequest` and permit string `id` values ([#7065](https://github.com/MetaMask/core/pull/7065))
- Previously, only number values were permitted for the `id` property.
- `OriginalRequest` is kept for backward compatibility.

### Deprecated

- Deprecate `OriginalRequest`; use `MessageRequest` instead ([#7138](https://github.com/MetaMask/core/pull/7138))

## [14.0.0]

Expand Down
7 changes: 7 additions & 0 deletions packages/message-manager/src/AbstractMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export type MessageRequest = {
securityAlertResponse?: Record<string, Json>;
};

/**
* Represents the request adding a message.
*
* @deprecated Please use `MessageRequest` instead.
*/
export type OriginalRequest = MessageRequest;

/**
* @type AbstractMessage
*
Expand Down
1 change: 1 addition & 0 deletions packages/network-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- In practice, this should happen rarely if ever.
- **BREAKING:** Migrate `NetworkClient` to `JsonRpcEngineV2` ([#7065](https://github.com/MetaMask/core/pull/7065))
- This ought to be unobservable, but we mark it as breaking out of an abundance of caution.
- **BREAKING:** Update signature of `request` in `AbstractRpcService` and `RpcServiceRequestable` so that the JSON-RPC request must be frozen ([#7138](https://github.com/MetaMask/core/pull/7138))
- Bump `@metamask/controller-utils` from `^11.14.1` to `^11.15.0` ([#7003](https://github.com/MetaMask/core/pull/7003))

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export class RpcServiceChain implements RpcServiceRequestable {
* @throws A "parse" error if the response is not valid JSON.
*/
async request<Params extends JsonRpcParams, Result extends Json>(
jsonRpcRequest: JsonRpcRequest<Params> & { method: 'eth_getBlockByNumber' },
jsonRpcRequest: Readonly<JsonRpcRequest<Params>> & {
method: 'eth_getBlockByNumber';
},
fetchOptions?: FetchOptions,
): Promise<JsonRpcResponse<Result> | JsonRpcResponse<null>>;

Expand All @@ -129,12 +131,12 @@ export class RpcServiceChain implements RpcServiceRequestable {
* @throws A "parse" error if the response is not valid JSON.
*/
async request<Params extends JsonRpcParams, Result extends Json>(
jsonRpcRequest: JsonRpcRequest<Params>,
jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,
fetchOptions?: FetchOptions,
): Promise<JsonRpcResponse<Result>>;

async request<Params extends JsonRpcParams, Result extends Json>(
jsonRpcRequest: JsonRpcRequest<Params>,
jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,
fetchOptions: FetchOptions = {},
): Promise<JsonRpcResponse<Result | null>> {
return this.#services[0].request(jsonRpcRequest, fetchOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type RpcServiceRequestable = {
* Makes a request to the target.
*/
request<Params extends JsonRpcParams, Result extends Json>(
jsonRpcRequest: JsonRpcRequest<Params>,
jsonRpcRequest: Readonly<JsonRpcRequest<Params>>,
fetchOptions?: FetchOptions,
): Promise<JsonRpcResponse<Result | null>>;
};
Loading