Skip to content

Commit

Permalink
Remove providerFromEngine and providerFromMiddleware
Browse files Browse the repository at this point in the history
The two provider construction functions have been removed. These
functions are instead availabile from the new package
`eth-json-rpc-provider`.
  • Loading branch information
Gudahtt committed Feb 11, 2023
1 parent ce20d95 commit 2729334
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 87 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
},
"dependencies": {
"@metamask/eth-sig-util": "^5.0.0",
"@metamask/safe-event-emitter": "^2.0.0",
"@metamask/utils": "^3.0.3",
"clone": "^2.1.1",
"eth-block-tracker": "^6.1.0",
Expand All @@ -46,6 +45,7 @@
"@metamask/eslint-config-jest": "^8.0.0",
"@metamask/eslint-config-nodejs": "^8.0.0",
"@metamask/eslint-config-typescript": "^8.0.0",
"@metamask/eth-json-rpc-provider": "^1.0.0",
"@types/btoa": "^1.2.3",
"@types/clone": "^2.1.0",
"@types/jest": "^27.4.1",
Expand Down
3 changes: 2 additions & 1 deletion src/block-cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { PollingBlockTracker, Provider } from 'eth-block-tracker';
import { JsonRpcEngine } from 'json-rpc-engine';
import pify from 'pify';
import { providerFromEngine } from '@metamask/eth-json-rpc-provider';
import createHitTrackerMiddleware from '../test/util/createHitTrackerMiddleware';
import { providerFromEngine, createBlockCacheMiddleware } from '.';
import { createBlockCacheMiddleware } from '.';

function createTestSetup() {
// raw data source
Expand Down
8 changes: 3 additions & 5 deletions src/block-ref.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { PollingBlockTracker, Provider } from 'eth-block-tracker';
import { JsonRpcEngine, JsonRpcMiddleware } from 'json-rpc-engine';
import { providerFromEngine } from '@metamask/eth-json-rpc-provider';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
import {
buildMockParamsWithBlockParamAt,
stubProviderRequests,
Expand All @@ -9,11 +11,7 @@ import {
buildMockParamsWithoutBlockParamAt,
expectProviderRequestNotToHaveBeenMade,
} from '../test/util/helpers';
import {
SafeEventEmitterProvider,
providerFromEngine,
createBlockRefMiddleware,
} from '.';
import { createBlockRefMiddleware } from '.';

/**
* Objects used in each test.
Expand Down
3 changes: 2 additions & 1 deletion src/block-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
} from 'json-rpc-engine';
import clone from 'clone';
import pify from 'pify';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
import { projectLogger, createModuleLogger } from './logging-utils';
import { blockTagParamIndex } from './utils/cache';
import type { Block, SafeEventEmitterProvider } from './types';
import type { Block } from './types';

interface BlockRefMiddlewareOptions {
blockTracker?: PollingBlockTracker;
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ export * from './block-tracker-inspector';
export * from './fetch';
export * from './inflight-cache';
export * from './providerAsMiddleware';
export * from './providerFromEngine';
export * from './providerFromMiddleware';
export * from './retryOnEmpty';
export type { SafeEventEmitterProvider } from './types';
export * from './wallet';
8 changes: 5 additions & 3 deletions src/providerAsMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonRpcMiddleware, PendingJsonRpcResponse } from 'json-rpc-engine';
import type { SafeEventEmitterProvider } from './types';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';

export function providerAsMiddleware(
provider: SafeEventEmitterProvider,
Expand Down Expand Up @@ -28,10 +28,12 @@ export function ethersProviderAsMiddleware(
// send request to provider
provider.send(
req,
(err: Error, providerRes: PendingJsonRpcResponse<any>) => {
(err: unknown, providerRes: PendingJsonRpcResponse<any>) => {
// forward any error
if (err) {
return end(err);
// TODO: Remove this cast when next major `json-rpc-engine` release is out
// The next release changes how errors are propogated.
return end(err as Error);
}
// copy provider response onto original response
Object.assign(res, providerRes);
Expand Down
32 changes: 0 additions & 32 deletions src/providerFromEngine.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/providerFromMiddleware.ts

This file was deleted.

8 changes: 3 additions & 5 deletions src/retryOnEmpty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
JsonRpcMiddleware,
JsonRpcRequest,
} from 'json-rpc-engine';
import { providerFromEngine } from '@metamask/eth-json-rpc-provider';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
import {
buildFinalMiddlewareWithDefaultResponse,
buildMockParamsWithBlockParamAt,
Expand All @@ -15,11 +17,7 @@ import {
requestMatches,
stubProviderRequests,
} from '../test/util/helpers';
import {
providerFromEngine,
createRetryOnEmptyMiddleware,
SafeEventEmitterProvider,
} from '.';
import { createRetryOnEmptyMiddleware } from '.';

/**
* Objects used in each test.
Expand Down
3 changes: 2 additions & 1 deletion src/retryOnEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import {
JsonRpcMiddleware,
PendingJsonRpcResponse,
} from 'json-rpc-engine';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
import pify from 'pify';
import { projectLogger, createModuleLogger } from './logging-utils';
import { blockTagParamIndex } from './utils/cache';
import { Block, SafeEventEmitterProvider } from './types';
import { Block } from './types';

//
// RetryOnEmptyMiddleware will retry any request with an empty response that has
Expand Down
22 changes: 1 addition & 21 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
JsonRpcMiddleware,
JsonRpcRequest,
JsonRpcResponse,
} from 'json-rpc-engine';
import SafeEventEmitter from '@metamask/safe-event-emitter';
import { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine';

export interface JsonRpcRequestToCache<T> extends JsonRpcRequest<T> {
skipCache?: boolean;
Expand All @@ -23,18 +18,3 @@ export type Block = Record<string, BlockData>;
export type BlockCache = Record<string, Block>;

export type Cache = Record<number, BlockCache>;

export type SendAsyncCallBack<T> = (
err: unknown,
providerRes: JsonRpcResponse<T>,
) => void;

export type SendCallBack = (
err: any,
providerRes: JsonRpcResponse<any>,
) => void;

export interface SafeEventEmitterProvider extends SafeEventEmitter {
sendAsync: <T, U>(req: JsonRpcRequest<T>, cb: SendAsyncCallBack<U>) => void;
send: (req: JsonRpcRequest<any>, callback: SendCallBack) => void;
}
2 changes: 1 addition & 1 deletion test/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
JsonRpcResponse,
JsonRpcMiddleware,
} from 'json-rpc-engine';
import { SafeEventEmitterProvider } from '../../src';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';

/**
* An object that can be used to assign a canned response to a request made via
Expand Down
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,8 @@ __metadata:
"@metamask/eslint-config-jest": ^8.0.0
"@metamask/eslint-config-nodejs": ^8.0.0
"@metamask/eslint-config-typescript": ^8.0.0
"@metamask/eth-json-rpc-provider": ^1.0.0
"@metamask/eth-sig-util": ^5.0.0
"@metamask/safe-event-emitter": ^2.0.0
"@metamask/utils": ^3.0.3
"@types/btoa": ^1.2.3
"@types/clone": ^2.1.0
Expand Down Expand Up @@ -889,6 +889,16 @@ __metadata:
languageName: unknown
linkType: soft

"@metamask/eth-json-rpc-provider@npm:^1.0.0":
version: 1.0.0
resolution: "@metamask/eth-json-rpc-provider@npm:1.0.0"
dependencies:
"@metamask/safe-event-emitter": ^2.0.0
json-rpc-engine: ^6.1.0
checksum: 27865d84d90030db1a9e5a66bc0b0ae079706fb7be635ec1e9bd4f64771e819aae78f0a026c6629d3a1a2eb277fcd51977315c049c47a70df1dd95d1d4106982
languageName: node
linkType: hard

"@metamask/eth-sig-util@npm:^5.0.0":
version: 5.0.2
resolution: "@metamask/eth-sig-util@npm:5.0.2"
Expand Down

0 comments on commit 2729334

Please sign in to comment.