Skip to content
Merged
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
2 changes: 2 additions & 0 deletions packages/network-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated

- `NetworkControllerGetNetworkConfigurationByNetworkClientId` type is deprecated in favor of `NetworkControllerGetNetworkConfigurationByNetworkClientIdAction` ([#8350](https://github.com/MetaMask/core/pull/8350))
- Deprecate `AbstractRpcService` and `RpcServiceRequestable` ([#8475](https://github.com/MetaMask/core/pull/8475))
- There are no equivalents to these interfaces. If you need to take an "RPC-service-like" argument, it's best to declare which properties you're interested in rather than accepting the entire RPC service interface.

## [30.0.1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import type { RpcServiceRequestable } from './rpc-service-requestable';
/**
* The interface for a service class responsible for making a request to an RPC
* endpoint or a group of RPC endpoints.
*
* @deprecated Don't use this interface (it will be removed in an upcoming major
* version). If you need to take an "RPC-service-like" argument, it's best to
* declare which properties you're interested in rather than accepting the
* entire RPC service interface.
*/
export type AbstractRpcService = RpcServiceRequestable & {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import type {
* The interface for a service class responsible for making a request to a
* target, whether that is a single RPC endpoint or an RPC endpoint in an RPC
* service chain.
*
* @deprecated Don't use this interface (it will be removed in an upcoming major
* version). If you need to take an "RPC-service-like" argument, it's best to
* declare which properties you're interested in rather than accepting the
* entire RPC service interface.
*/
export type RpcServiceRequestable = {
/**
Expand Down
46 changes: 36 additions & 10 deletions packages/network-controller/src/rpc-service/rpc-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ import type {
JsonRpcRequest,
JsonRpcResponse,
} from '@metamask/utils';
import { CircuitState, IDisposable } from 'cockatiel';
import { CircuitState } from 'cockatiel';
import deepmerge from 'deepmerge';
import type { Logger } from 'loglevel';

import { projectLogger, createModuleLogger } from '../logger';
import type { AbstractRpcService } from './abstract-rpc-service';
import type { FetchOptions } from './shared';
import type {
CockatielEventToEventListenerWithData,
ExcludeCockatielEventData,
ExtendCockatielEventData,
ExtractCockatielEventData,
FetchOptions,
} from './shared';

/**
* Options for the RpcService constructor.
Expand Down Expand Up @@ -274,7 +279,7 @@ function stripCredentialsFromUrl(url: URL): URL {
* failures, retrying requests using exponential backoff. It also offers a hook
* which can used to respond to slow requests.
*/
export class RpcService implements AbstractRpcService {
export class RpcService {
Comment thread
cursor[bot] marked this conversation as resolved.
/**
* The URL of the RPC endpoint.
*/
Expand Down Expand Up @@ -395,7 +400,12 @@ export class RpcService implements AbstractRpcService {
* @returns What {@link ServicePolicy.onRetry} returns.
* @see {@link createServicePolicy}
*/
onRetry(listener: Parameters<AbstractRpcService['onRetry']>[0]): IDisposable {
onRetry(
listener: CockatielEventToEventListenerWithData<
ServicePolicy['onRetry'],
{ endpointUrl: string }
>,
): ReturnType<ServicePolicy['onRetry']> {
return this.#policy.onRetry((data) => {
listener({ ...data, endpointUrl: this.endpointUrl.toString() });
});
Expand All @@ -409,7 +419,17 @@ export class RpcService implements AbstractRpcService {
* @returns What {@link ServicePolicy.onBreak} returns.
* @see {@link createServicePolicy}
*/
onBreak(listener: Parameters<AbstractRpcService['onBreak']>[0]): IDisposable {
onBreak(
listener: (
data: ExcludeCockatielEventData<
ExtendCockatielEventData<
ExtractCockatielEventData<ServicePolicy['onBreak']>,
{ endpointUrl: string }
>,
'isolated'
>,
) => void,
): ReturnType<ServicePolicy['onBreak']> {
return this.#policy.onBreak((data) => {
// `{ isolated: true }` is a special object that shows up when `isolate`
// is called on the circuit breaker. Usually `isolate` is used to hold the
Expand Down Expand Up @@ -440,8 +460,11 @@ export class RpcService implements AbstractRpcService {
* @see {@link createServicePolicy}
*/
onDegraded(
listener: Parameters<AbstractRpcService['onDegraded']>[0],
): IDisposable {
listener: CockatielEventToEventListenerWithData<
ServicePolicy['onDegraded'],
{ endpointUrl: string; rpcMethodName: string }
>,
): ReturnType<ServicePolicy['onDegraded']> {
return this.#policy.onDegraded((data) => {
if (data === undefined) {
listener({
Expand All @@ -466,8 +489,11 @@ export class RpcService implements AbstractRpcService {
* @see {@link createServicePolicy}
*/
onAvailable(
listener: Parameters<AbstractRpcService['onAvailable']>[0],
): IDisposable {
listener: CockatielEventToEventListenerWithData<
ServicePolicy['onAvailable'],
{ endpointUrl: string }
>,
): ReturnType<ServicePolicy['onAvailable']> {
return this.#policy.onAvailable(() => {
listener({ endpointUrl: this.endpointUrl.toString() });
});
Expand Down
Loading