@metamask-previews/network-controller 22.2.1-preview-a1eb992b → 22.2.1-preview-dbdf1da
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -7
- package/dist/NetworkController.cjs +1 -5
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +0 -4
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +0 -4
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +1 -5
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/create-network-client.cjs +12 -12
- package/dist/create-network-client.cjs.map +1 -1
- package/dist/create-network-client.d.cts.map +1 -1
- package/dist/create-network-client.d.mts.map +1 -1
- package/dist/create-network-client.mjs +12 -12
- package/dist/create-network-client.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -11
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -11
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ const eth_json_rpc_infura_1 = require("@metamask/eth-json-rpc-infura");
|
|
|
7
7
|
const eth_json_rpc_middleware_1 = require("@metamask/eth-json-rpc-middleware");
|
|
8
8
|
const eth_json_rpc_provider_1 = require("@metamask/eth-json-rpc-provider");
|
|
9
9
|
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
10
|
-
const
|
|
10
|
+
const rpc_service_1 = require("./rpc-service/rpc-service.cjs");
|
|
11
11
|
const types_1 = require("./types.cjs");
|
|
12
12
|
const SECOND = 1000;
|
|
13
13
|
/**
|
|
@@ -22,17 +22,17 @@ const SECOND = 1000;
|
|
|
22
22
|
* @returns The network client.
|
|
23
23
|
*/
|
|
24
24
|
function createNetworkClient({ configuration, fetch: givenFetch, btoa: givenBtoa, }) {
|
|
25
|
-
const
|
|
26
|
-
?
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const rpcService = configuration.type === types_1.NetworkClientType.Infura
|
|
26
|
+
? new rpc_service_1.RpcService({
|
|
27
|
+
fetch: givenFetch,
|
|
28
|
+
btoa: givenBtoa,
|
|
29
|
+
endpointUrl: `https://${configuration.network}.infura.io/v3/${configuration.infuraProjectId}`,
|
|
30
|
+
})
|
|
31
|
+
: new rpc_service_1.RpcService({
|
|
32
|
+
fetch: givenFetch,
|
|
33
|
+
btoa: givenBtoa,
|
|
34
|
+
endpointUrl: configuration.rpcUrl,
|
|
35
|
+
});
|
|
36
36
|
const rpcApiMiddleware = configuration.type === types_1.NetworkClientType.Infura
|
|
37
37
|
? (0, eth_json_rpc_infura_1.createInfuraMiddleware)({
|
|
38
38
|
rpcService,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-network-client.cjs","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AACrD,mEAAkE;AAClE,uEAAuE;AACvE,+EAQ2C;AAE3C,2EAGyC;AACzC,+DAKmC;AAInC,2EAAkE;AAMlE,uCAA4C;AAE5C,MAAM,MAAM,GAAG,IAAI,CAAC;AAapB;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAKhB;IACC,MAAM,kBAAkB,GACtB,aAAa,CAAC,IAAI,KAAK,yBAAiB,CAAC,MAAM;QAC7C,CAAC,CAAC,WAAW,aAAa,CAAC,OAAO,iBAAiB,aAAa,CAAC,eAAe,EAAE;QAClF,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC;IAC3B,MAAM,oBAAoB,GACxB,aAAa,CAAC,IAAI,KAAK,yBAAiB,CAAC,MAAM;QAC7C,CAAC,CAAC,aAAa,CAAC,oBAAoB;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AAG,CAAC,MAAM,GAAG,OAAO,CAAC;YACrB,OAAO,GAAG,EAAE,CAAC;SACd;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAS,6BAA6B,CAAC,EACrC,YAAY,EACZ,OAAO,EACP,gBAAgB,GAKjB;IACC,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO;QACzC,CAAC,CAAC,CAAC,oCAAoC,EAAE,CAAC;QAC1C,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,IAAA,iCAAe,EAAC;QACrB,GAAG,eAAe;QAClB,uBAAuB,CAAC,OAAO,CAAC;QAChC,IAAA,yDAA+B,EAAC,EAAE,YAAY,EAAE,CAAC;QACjD,IAAA,oDAA0B,EAAC,EAAE,YAAY,EAAE,CAAC;QAC5C,IAAA,uDAA6B,GAAE;QAC/B,IAAA,+DAAqC,EAAC,EAAE,YAAY,EAAE,CAAC;QACvD,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,oCAAoC;IAC3C,OAAO,IAAA,uCAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QAClD,IAAI,GAAG,CAAC,MAAM,KAAK,iBAAiB,EAAE;YACpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;SACjE;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport { ChainId } from '@metamask/controller-utils';\nimport { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport { createInfuraMiddleware } from '@metamask/eth-json-rpc-infura';\nimport {\n createBlockCacheMiddleware,\n createBlockRefMiddleware,\n createBlockRefRewriteMiddleware,\n createBlockTrackerInspectorMiddleware,\n createInflightCacheMiddleware,\n createFetchMiddleware,\n createRetryOnEmptyMiddleware,\n} from '@metamask/eth-json-rpc-middleware';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport {\n providerFromEngine,\n providerFromMiddleware,\n} from '@metamask/eth-json-rpc-provider';\nimport {\n createAsyncMiddleware,\n createScaffoldMiddleware,\n JsonRpcEngine,\n mergeMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Hex, Json, JsonRpcParams } from '@metamask/utils';\n\nimport { RpcServiceChain } from './rpc-service/rpc-service-chain';\nimport type {\n BlockTracker,\n NetworkClientConfiguration,\n Provider,\n} from './types';\nimport { NetworkClientType } from './types';\n\nconst SECOND = 1000;\n\n/**\n * The pair of provider / block tracker that can be used to interface with the\n * network and respond to new activity.\n */\nexport type NetworkClient = {\n configuration: NetworkClientConfiguration;\n provider: Provider;\n blockTracker: BlockTracker;\n destroy: () => void;\n};\n\n/**\n * Create a JSON RPC network client for a specific network.\n *\n * @param args - The arguments.\n * @param args.configuration - The network configuration.\n * @param args.fetch - A function that can be used to make an HTTP request,\n * compatible with the Fetch API.\n * @param args.btoa - A function that can be used to convert a binary string\n * into base-64.\n * @returns The network client.\n */\nexport function createNetworkClient({\n configuration,\n fetch: givenFetch,\n btoa: givenBtoa,\n}: {\n configuration: NetworkClientConfiguration;\n fetch: typeof fetch;\n btoa: typeof btoa;\n}): NetworkClient {\n const primaryEndpointUrl =\n configuration.type === NetworkClientType.Infura\n ? `https://${configuration.network}.infura.io/v3/${configuration.infuraProjectId}`\n : configuration.rpcUrl;\n const failoverEndpointUrls =\n configuration.type === NetworkClientType.Infura\n ? configuration.failoverEndpointUrls\n : [];\n const rpcService = new RpcServiceChain({\n fetch: givenFetch,\n btoa: givenBtoa,\n serviceConfigurations: [primaryEndpointUrl, ...failoverEndpointUrls].map(\n (endpointUrl) => ({ endpointUrl }),\n ),\n });\n\n const rpcApiMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraMiddleware({\n rpcService,\n options: {\n source: 'metamask',\n },\n })\n : createFetchMiddleware({ rpcService });\n\n const rpcProvider = providerFromMiddleware(rpcApiMiddleware);\n\n const blockTrackerOpts =\n process.env.IN_TEST && configuration.type === NetworkClientType.Custom\n ? { pollingInterval: SECOND }\n : {};\n const blockTracker = new PollingBlockTracker({\n ...blockTrackerOpts,\n provider: rpcProvider,\n });\n\n const networkMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraNetworkMiddleware({\n blockTracker,\n network: configuration.network,\n rpcProvider,\n rpcApiMiddleware,\n })\n : createCustomNetworkMiddleware({\n blockTracker,\n chainId: configuration.chainId,\n rpcApiMiddleware,\n });\n\n const engine = new JsonRpcEngine();\n\n engine.push(networkMiddleware);\n\n const provider = providerFromEngine(engine);\n\n const destroy = () => {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n blockTracker.destroy();\n };\n\n return { configuration, provider, blockTracker, destroy };\n}\n\n/**\n * Create middleware for infura.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.network - The Infura network to use.\n * @param args.rpcProvider - The RPC provider to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createInfuraNetworkMiddleware({\n blockTracker,\n network,\n rpcProvider,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n network: InfuraNetworkType;\n rpcProvider: SafeEventEmitterProvider;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}) {\n return mergeMiddleware([\n createNetworkAndChainIdMiddleware({ network }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockRefMiddleware({ blockTracker, provider: rpcProvider }),\n createRetryOnEmptyMiddleware({ blockTracker, provider: rpcProvider }),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * Creates static method middleware.\n *\n * @param args - The Arguments.\n * @param args.network - The Infura network to use.\n * @returns The middleware that implements the eth_chainId method.\n */\nfunction createNetworkAndChainIdMiddleware({\n network,\n}: {\n network: InfuraNetworkType;\n}) {\n return createScaffoldMiddleware({\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_chainId: ChainId[network],\n });\n}\n\nconst createChainIdMiddleware = (\n chainId: Hex,\n): JsonRpcMiddleware<JsonRpcParams, Json> => {\n return (req, res, next, end) => {\n if (req.method === 'eth_chainId') {\n res.result = chainId;\n return end();\n }\n return next();\n };\n};\n\n/**\n * Creates custom middleware.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.chainId - The chain id to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createCustomNetworkMiddleware({\n blockTracker,\n chainId,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n chainId: Hex;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n const testMiddlewares = process.env.IN_TEST\n ? [createEstimateGasDelayTestMiddleware()]\n : [];\n\n return mergeMiddleware([\n ...testMiddlewares,\n createChainIdMiddleware(chainId),\n createBlockRefRewriteMiddleware({ blockTracker }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * For use in tests only.\n * Adds a delay to `eth_estimateGas` calls.\n *\n * @returns The middleware for delaying gas estimation calls by 2 seconds when in test.\n */\nfunction createEstimateGasDelayTestMiddleware() {\n return createAsyncMiddleware(async (req, _, next) => {\n if (req.method === 'eth_estimateGas') {\n await new Promise((resolve) => setTimeout(resolve, SECOND * 2));\n }\n return next();\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-network-client.cjs","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":";;;AACA,iEAAqD;AACrD,mEAAkE;AAClE,uEAAuE;AACvE,+EAQ2C;AAE3C,2EAGyC;AACzC,+DAKmC;AAInC,+DAAuD;AAMvD,uCAA4C;AAE5C,MAAM,MAAM,GAAG,IAAI,CAAC;AAapB;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAKhB;IACC,MAAM,UAAU,GACd,aAAa,CAAC,IAAI,KAAK,yBAAiB,CAAC,MAAM;QAC7C,CAAC,CAAC,IAAI,wBAAU,CAAC;YACb,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,WAAW,aAAa,CAAC,OAAO,iBAAiB,aAAa,CAAC,eAAe,EAAE;SAC9F,CAAC;QACJ,CAAC,CAAC,IAAI,wBAAU,CAAC;YACb,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,aAAa,CAAC,MAAM;SAClC,CAAC,CAAC;IAET,MAAM,gBAAgB,GACpB,aAAa,CAAC,IAAI,KAAK,yBAAiB,CAAC,MAAM;QAC7C,CAAC,CAAC,IAAA,4CAAsB,EAAC;YACrB,UAAU;YACV,OAAO,EAAE;gBACP,MAAM,EAAE,UAAU;aACnB;SACF,CAAC;QACJ,CAAC,CAAC,IAAA,+CAAqB,EAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAE5C,MAAM,WAAW,GAAG,IAAA,8CAAsB,EAAC,gBAAgB,CAAC,CAAC;IAE7D,MAAM,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,aAAa,CAAC,IAAI,KAAK,yBAAiB,CAAC,MAAM;QACpE,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE;QAC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,EAAE,IAAI,EAAE,EAAE;QAClD,IAAI,GAAG,CAAC,MAAM,KAAK,iBAAiB,EAAE;YACpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;SACjE;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport { ChainId } from '@metamask/controller-utils';\nimport { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport { createInfuraMiddleware } from '@metamask/eth-json-rpc-infura';\nimport {\n createBlockCacheMiddleware,\n createBlockRefMiddleware,\n createBlockRefRewriteMiddleware,\n createBlockTrackerInspectorMiddleware,\n createInflightCacheMiddleware,\n createFetchMiddleware,\n createRetryOnEmptyMiddleware,\n} from '@metamask/eth-json-rpc-middleware';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport {\n providerFromEngine,\n providerFromMiddleware,\n} from '@metamask/eth-json-rpc-provider';\nimport {\n createAsyncMiddleware,\n createScaffoldMiddleware,\n JsonRpcEngine,\n mergeMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Hex, Json, JsonRpcParams } from '@metamask/utils';\n\nimport { RpcService } from './rpc-service/rpc-service';\nimport type {\n BlockTracker,\n NetworkClientConfiguration,\n Provider,\n} from './types';\nimport { NetworkClientType } from './types';\n\nconst SECOND = 1000;\n\n/**\n * The pair of provider / block tracker that can be used to interface with the\n * network and respond to new activity.\n */\nexport type NetworkClient = {\n configuration: NetworkClientConfiguration;\n provider: Provider;\n blockTracker: BlockTracker;\n destroy: () => void;\n};\n\n/**\n * Create a JSON RPC network client for a specific network.\n *\n * @param args - The arguments.\n * @param args.configuration - The network configuration.\n * @param args.fetch - A function that can be used to make an HTTP request,\n * compatible with the Fetch API.\n * @param args.btoa - A function that can be used to convert a binary string\n * into base-64.\n * @returns The network client.\n */\nexport function createNetworkClient({\n configuration,\n fetch: givenFetch,\n btoa: givenBtoa,\n}: {\n configuration: NetworkClientConfiguration;\n fetch: typeof fetch;\n btoa: typeof btoa;\n}): NetworkClient {\n const rpcService =\n configuration.type === NetworkClientType.Infura\n ? new RpcService({\n fetch: givenFetch,\n btoa: givenBtoa,\n endpointUrl: `https://${configuration.network}.infura.io/v3/${configuration.infuraProjectId}`,\n })\n : new RpcService({\n fetch: givenFetch,\n btoa: givenBtoa,\n endpointUrl: configuration.rpcUrl,\n });\n\n const rpcApiMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraMiddleware({\n rpcService,\n options: {\n source: 'metamask',\n },\n })\n : createFetchMiddleware({ rpcService });\n\n const rpcProvider = providerFromMiddleware(rpcApiMiddleware);\n\n const blockTrackerOpts =\n process.env.IN_TEST && configuration.type === NetworkClientType.Custom\n ? { pollingInterval: SECOND }\n : {};\n const blockTracker = new PollingBlockTracker({\n ...blockTrackerOpts,\n provider: rpcProvider,\n });\n\n const networkMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraNetworkMiddleware({\n blockTracker,\n network: configuration.network,\n rpcProvider,\n rpcApiMiddleware,\n })\n : createCustomNetworkMiddleware({\n blockTracker,\n chainId: configuration.chainId,\n rpcApiMiddleware,\n });\n\n const engine = new JsonRpcEngine();\n\n engine.push(networkMiddleware);\n\n const provider = providerFromEngine(engine);\n\n const destroy = () => {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n blockTracker.destroy();\n };\n\n return { configuration, provider, blockTracker, destroy };\n}\n\n/**\n * Create middleware for infura.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.network - The Infura network to use.\n * @param args.rpcProvider - The RPC provider to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createInfuraNetworkMiddleware({\n blockTracker,\n network,\n rpcProvider,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n network: InfuraNetworkType;\n rpcProvider: SafeEventEmitterProvider;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}) {\n return mergeMiddleware([\n createNetworkAndChainIdMiddleware({ network }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockRefMiddleware({ blockTracker, provider: rpcProvider }),\n createRetryOnEmptyMiddleware({ blockTracker, provider: rpcProvider }),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * Creates static method middleware.\n *\n * @param args - The Arguments.\n * @param args.network - The Infura network to use.\n * @returns The middleware that implements the eth_chainId method.\n */\nfunction createNetworkAndChainIdMiddleware({\n network,\n}: {\n network: InfuraNetworkType;\n}) {\n return createScaffoldMiddleware({\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_chainId: ChainId[network],\n });\n}\n\nconst createChainIdMiddleware = (\n chainId: Hex,\n): JsonRpcMiddleware<JsonRpcParams, Json> => {\n return (req, res, next, end) => {\n if (req.method === 'eth_chainId') {\n res.result = chainId;\n return end();\n }\n return next();\n };\n};\n\n/**\n * Creates custom middleware.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.chainId - The chain id to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createCustomNetworkMiddleware({\n blockTracker,\n chainId,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n chainId: Hex;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n const testMiddlewares = process.env.IN_TEST\n ? [createEstimateGasDelayTestMiddleware()]\n : [];\n\n return mergeMiddleware([\n ...testMiddlewares,\n createChainIdMiddleware(chainId),\n createBlockRefRewriteMiddleware({ blockTracker }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * For use in tests only.\n * Adds a delay to `eth_estimateGas` calls.\n *\n * @returns The middleware for delaying gas estimation calls by 2 seconds when in test.\n */\nfunction createEstimateGasDelayTestMiddleware() {\n return createAsyncMiddleware(async (req, _, next) => {\n if (req.method === 'eth_estimateGas') {\n await new Promise((resolve) => setTimeout(resolve, SECOND * 2));\n }\n return next();\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-network-client.d.cts","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,YAAY,EACZ,0BAA0B,EAC1B,QAAQ,EACT,oBAAgB;AAKjB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAChB,EAAE;IACD,aAAa,EAAE,0BAA0B,CAAC;IAC1C,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,IAAI,EAAE,OAAO,IAAI,CAAC;CACnB,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"create-network-client.d.cts","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,YAAY,EACZ,0BAA0B,EAC1B,QAAQ,EACT,oBAAgB;AAKjB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAChB,EAAE;IACD,aAAa,EAAE,0BAA0B,CAAC;IAC1C,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,IAAI,EAAE,OAAO,IAAI,CAAC;CACnB,GAAG,aAAa,CA8DhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-network-client.d.mts","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,YAAY,EACZ,0BAA0B,EAC1B,QAAQ,EACT,oBAAgB;AAKjB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAChB,EAAE;IACD,aAAa,EAAE,0BAA0B,CAAC;IAC1C,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,IAAI,EAAE,OAAO,IAAI,CAAC;CACnB,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"create-network-client.d.mts","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,YAAY,EACZ,0BAA0B,EAC1B,QAAQ,EACT,oBAAgB;AAKjB;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAChB,EAAE;IACD,aAAa,EAAE,0BAA0B,CAAC;IAC1C,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,IAAI,EAAE,OAAO,IAAI,CAAC;CACnB,GAAG,aAAa,CA8DhB"}
|
|
@@ -4,7 +4,7 @@ import { createInfuraMiddleware } from "@metamask/eth-json-rpc-infura";
|
|
|
4
4
|
import { createBlockCacheMiddleware, createBlockRefMiddleware, createBlockRefRewriteMiddleware, createBlockTrackerInspectorMiddleware, createInflightCacheMiddleware, createFetchMiddleware, createRetryOnEmptyMiddleware } from "@metamask/eth-json-rpc-middleware";
|
|
5
5
|
import { providerFromEngine, providerFromMiddleware } from "@metamask/eth-json-rpc-provider";
|
|
6
6
|
import { createAsyncMiddleware, createScaffoldMiddleware, JsonRpcEngine, mergeMiddleware } from "@metamask/json-rpc-engine";
|
|
7
|
-
import {
|
|
7
|
+
import { RpcService } from "./rpc-service/rpc-service.mjs";
|
|
8
8
|
import { NetworkClientType } from "./types.mjs";
|
|
9
9
|
const SECOND = 1000;
|
|
10
10
|
/**
|
|
@@ -19,17 +19,17 @@ const SECOND = 1000;
|
|
|
19
19
|
* @returns The network client.
|
|
20
20
|
*/
|
|
21
21
|
export function createNetworkClient({ configuration, fetch: givenFetch, btoa: givenBtoa, }) {
|
|
22
|
-
const
|
|
23
|
-
?
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
const rpcService = configuration.type === NetworkClientType.Infura
|
|
23
|
+
? new RpcService({
|
|
24
|
+
fetch: givenFetch,
|
|
25
|
+
btoa: givenBtoa,
|
|
26
|
+
endpointUrl: `https://${configuration.network}.infura.io/v3/${configuration.infuraProjectId}`,
|
|
27
|
+
})
|
|
28
|
+
: new RpcService({
|
|
29
|
+
fetch: givenFetch,
|
|
30
|
+
btoa: givenBtoa,
|
|
31
|
+
endpointUrl: configuration.rpcUrl,
|
|
32
|
+
});
|
|
33
33
|
const rpcApiMiddleware = configuration.type === NetworkClientType.Infura
|
|
34
34
|
? createInfuraMiddleware({
|
|
35
35
|
rpcService,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-network-client.mjs","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AACrD,OAAO,EAAE,mBAAmB,EAAE,oCAAoC;AAClE,OAAO,EAAE,sBAAsB,EAAE,sCAAsC;AACvE,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,+BAA+B,EAC/B,qCAAqC,EACrC,6BAA6B,EAC7B,qBAAqB,EACrB,4BAA4B,EAC7B,0CAA0C;AAE3C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACvB,wCAAwC;AACzC,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,eAAe,EAChB,kCAAkC;AAInC,OAAO,EAAE,eAAe,EAAE,4CAAwC;AAMlE,OAAO,EAAE,iBAAiB,EAAE,oBAAgB;AAE5C,MAAM,MAAM,GAAG,IAAI,CAAC;AAapB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAKhB;IACC,MAAM,kBAAkB,GACtB,aAAa,CAAC,IAAI,KAAK,iBAAiB,CAAC,MAAM;QAC7C,CAAC,CAAC,WAAW,aAAa,CAAC,OAAO,iBAAiB,aAAa,CAAC,eAAe,EAAE;QAClF,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC;IAC3B,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aAAa,EAAE;YAChC,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC;YACrB,OAAO,GAAG,EAAE,CAAC;SACd;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAS,6BAA6B,CAAC,EACrC,YAAY,EACZ,OAAO,EACP,gBAAgB,GAKjB;IACC,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO;QACzC,CAAC,CAAC,CAAC,oCAAoC,EAAE,CAAC;QAC1C,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,eAAe,CAAC;QACrB,GAAG,eAAe;QAClB,uBAAuB,CAAC,OAAO,CAAC;QAChC,+BAA+B,CAAC,EAAE,YAAY,EAAE,CAAC;QACjD,0BAA0B,CAAC,EAAE,YAAY,EAAE,CAAC;QAC5C,6BAA6B,EAAE;QAC/B,qCAAqC,CAAC,EAAE,YAAY,EAAE,CAAC;QACvD,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,oCAAoC;IAC3C,OAAO,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QAClD,IAAI,GAAG,CAAC,MAAM,KAAK,iBAAiB,EAAE;YACpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;SACjE;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport { ChainId } from '@metamask/controller-utils';\nimport { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport { createInfuraMiddleware } from '@metamask/eth-json-rpc-infura';\nimport {\n createBlockCacheMiddleware,\n createBlockRefMiddleware,\n createBlockRefRewriteMiddleware,\n createBlockTrackerInspectorMiddleware,\n createInflightCacheMiddleware,\n createFetchMiddleware,\n createRetryOnEmptyMiddleware,\n} from '@metamask/eth-json-rpc-middleware';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport {\n providerFromEngine,\n providerFromMiddleware,\n} from '@metamask/eth-json-rpc-provider';\nimport {\n createAsyncMiddleware,\n createScaffoldMiddleware,\n JsonRpcEngine,\n mergeMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Hex, Json, JsonRpcParams } from '@metamask/utils';\n\nimport { RpcServiceChain } from './rpc-service/rpc-service-chain';\nimport type {\n BlockTracker,\n NetworkClientConfiguration,\n Provider,\n} from './types';\nimport { NetworkClientType } from './types';\n\nconst SECOND = 1000;\n\n/**\n * The pair of provider / block tracker that can be used to interface with the\n * network and respond to new activity.\n */\nexport type NetworkClient = {\n configuration: NetworkClientConfiguration;\n provider: Provider;\n blockTracker: BlockTracker;\n destroy: () => void;\n};\n\n/**\n * Create a JSON RPC network client for a specific network.\n *\n * @param args - The arguments.\n * @param args.configuration - The network configuration.\n * @param args.fetch - A function that can be used to make an HTTP request,\n * compatible with the Fetch API.\n * @param args.btoa - A function that can be used to convert a binary string\n * into base-64.\n * @returns The network client.\n */\nexport function createNetworkClient({\n configuration,\n fetch: givenFetch,\n btoa: givenBtoa,\n}: {\n configuration: NetworkClientConfiguration;\n fetch: typeof fetch;\n btoa: typeof btoa;\n}): NetworkClient {\n const primaryEndpointUrl =\n configuration.type === NetworkClientType.Infura\n ? `https://${configuration.network}.infura.io/v3/${configuration.infuraProjectId}`\n : configuration.rpcUrl;\n const failoverEndpointUrls =\n configuration.type === NetworkClientType.Infura\n ? configuration.failoverEndpointUrls\n : [];\n const rpcService = new RpcServiceChain({\n fetch: givenFetch,\n btoa: givenBtoa,\n serviceConfigurations: [primaryEndpointUrl, ...failoverEndpointUrls].map(\n (endpointUrl) => ({ endpointUrl }),\n ),\n });\n\n const rpcApiMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraMiddleware({\n rpcService,\n options: {\n source: 'metamask',\n },\n })\n : createFetchMiddleware({ rpcService });\n\n const rpcProvider = providerFromMiddleware(rpcApiMiddleware);\n\n const blockTrackerOpts =\n process.env.IN_TEST && configuration.type === NetworkClientType.Custom\n ? { pollingInterval: SECOND }\n : {};\n const blockTracker = new PollingBlockTracker({\n ...blockTrackerOpts,\n provider: rpcProvider,\n });\n\n const networkMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraNetworkMiddleware({\n blockTracker,\n network: configuration.network,\n rpcProvider,\n rpcApiMiddleware,\n })\n : createCustomNetworkMiddleware({\n blockTracker,\n chainId: configuration.chainId,\n rpcApiMiddleware,\n });\n\n const engine = new JsonRpcEngine();\n\n engine.push(networkMiddleware);\n\n const provider = providerFromEngine(engine);\n\n const destroy = () => {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n blockTracker.destroy();\n };\n\n return { configuration, provider, blockTracker, destroy };\n}\n\n/**\n * Create middleware for infura.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.network - The Infura network to use.\n * @param args.rpcProvider - The RPC provider to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createInfuraNetworkMiddleware({\n blockTracker,\n network,\n rpcProvider,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n network: InfuraNetworkType;\n rpcProvider: SafeEventEmitterProvider;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}) {\n return mergeMiddleware([\n createNetworkAndChainIdMiddleware({ network }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockRefMiddleware({ blockTracker, provider: rpcProvider }),\n createRetryOnEmptyMiddleware({ blockTracker, provider: rpcProvider }),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * Creates static method middleware.\n *\n * @param args - The Arguments.\n * @param args.network - The Infura network to use.\n * @returns The middleware that implements the eth_chainId method.\n */\nfunction createNetworkAndChainIdMiddleware({\n network,\n}: {\n network: InfuraNetworkType;\n}) {\n return createScaffoldMiddleware({\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_chainId: ChainId[network],\n });\n}\n\nconst createChainIdMiddleware = (\n chainId: Hex,\n): JsonRpcMiddleware<JsonRpcParams, Json> => {\n return (req, res, next, end) => {\n if (req.method === 'eth_chainId') {\n res.result = chainId;\n return end();\n }\n return next();\n };\n};\n\n/**\n * Creates custom middleware.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.chainId - The chain id to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createCustomNetworkMiddleware({\n blockTracker,\n chainId,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n chainId: Hex;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n const testMiddlewares = process.env.IN_TEST\n ? [createEstimateGasDelayTestMiddleware()]\n : [];\n\n return mergeMiddleware([\n ...testMiddlewares,\n createChainIdMiddleware(chainId),\n createBlockRefRewriteMiddleware({ blockTracker }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * For use in tests only.\n * Adds a delay to `eth_estimateGas` calls.\n *\n * @returns The middleware for delaying gas estimation calls by 2 seconds when in test.\n */\nfunction createEstimateGasDelayTestMiddleware() {\n return createAsyncMiddleware(async (req, _, next) => {\n if (req.method === 'eth_estimateGas') {\n await new Promise((resolve) => setTimeout(resolve, SECOND * 2));\n }\n return next();\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-network-client.mjs","sourceRoot":"","sources":["../src/create-network-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AACrD,OAAO,EAAE,mBAAmB,EAAE,oCAAoC;AAClE,OAAO,EAAE,sBAAsB,EAAE,sCAAsC;AACvE,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,+BAA+B,EAC/B,qCAAqC,EACrC,6BAA6B,EAC7B,qBAAqB,EACrB,4BAA4B,EAC7B,0CAA0C;AAE3C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACvB,wCAAwC;AACzC,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,eAAe,EAChB,kCAAkC;AAInC,OAAO,EAAE,UAAU,EAAE,sCAAkC;AAMvD,OAAO,EAAE,iBAAiB,EAAE,oBAAgB;AAE5C,MAAM,MAAM,GAAG,IAAI,CAAC;AAapB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,aAAa,EACb,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GAKhB;IACC,MAAM,UAAU,GACd,aAAa,CAAC,IAAI,KAAK,iBAAiB,CAAC,MAAM;QAC7C,CAAC,CAAC,IAAI,UAAU,CAAC;YACb,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,WAAW,aAAa,CAAC,OAAO,iBAAiB,aAAa,CAAC,eAAe,EAAE;SAC9F,CAAC;QACJ,CAAC,CAAC,IAAI,UAAU,CAAC;YACb,KAAK,EAAE,UAAU;YACjB,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,aAAa,CAAC,MAAM;SAClC,CAAC,CAAC;IAET,MAAM,gBAAgB,GACpB,aAAa,CAAC,IAAI,KAAK,iBAAiB,CAAC,MAAM;QAC7C,CAAC,CAAC,sBAAsB,CAAC;YACrB,UAAU;YACV,OAAO,EAAE;gBACP,MAAM,EA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AC;QAC5C,6BAA6B,EAAE;QAC/B,qCAAqC,CAAC,EAAE,YAAY,EAAE,CAAC;QACvD,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,oCAAoC;IAC3C,OAAO,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QAClD,IAAI,GAAG,CAAC,MAAM,KAAK,iBAAiB,EAAE;YACpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;SACjE;QACD,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport { ChainId } from '@metamask/controller-utils';\nimport { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport { createInfuraMiddleware } from '@metamask/eth-json-rpc-infura';\nimport {\n createBlockCacheMiddleware,\n createBlockRefMiddleware,\n createBlockRefRewriteMiddleware,\n createBlockTrackerInspectorMiddleware,\n createInflightCacheMiddleware,\n createFetchMiddleware,\n createRetryOnEmptyMiddleware,\n} from '@metamask/eth-json-rpc-middleware';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport {\n providerFromEngine,\n providerFromMiddleware,\n} from '@metamask/eth-json-rpc-provider';\nimport {\n createAsyncMiddleware,\n createScaffoldMiddleware,\n JsonRpcEngine,\n mergeMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Hex, Json, JsonRpcParams } from '@metamask/utils';\n\nimport { RpcService } from './rpc-service/rpc-service';\nimport type {\n BlockTracker,\n NetworkClientConfiguration,\n Provider,\n} from './types';\nimport { NetworkClientType } from './types';\n\nconst SECOND = 1000;\n\n/**\n * The pair of provider / block tracker that can be used to interface with the\n * network and respond to new activity.\n */\nexport type NetworkClient = {\n configuration: NetworkClientConfiguration;\n provider: Provider;\n blockTracker: BlockTracker;\n destroy: () => void;\n};\n\n/**\n * Create a JSON RPC network client for a specific network.\n *\n * @param args - The arguments.\n * @param args.configuration - The network configuration.\n * @param args.fetch - A function that can be used to make an HTTP request,\n * compatible with the Fetch API.\n * @param args.btoa - A function that can be used to convert a binary string\n * into base-64.\n * @returns The network client.\n */\nexport function createNetworkClient({\n configuration,\n fetch: givenFetch,\n btoa: givenBtoa,\n}: {\n configuration: NetworkClientConfiguration;\n fetch: typeof fetch;\n btoa: typeof btoa;\n}): NetworkClient {\n const rpcService =\n configuration.type === NetworkClientType.Infura\n ? new RpcService({\n fetch: givenFetch,\n btoa: givenBtoa,\n endpointUrl: `https://${configuration.network}.infura.io/v3/${configuration.infuraProjectId}`,\n })\n : new RpcService({\n fetch: givenFetch,\n btoa: givenBtoa,\n endpointUrl: configuration.rpcUrl,\n });\n\n const rpcApiMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraMiddleware({\n rpcService,\n options: {\n source: 'metamask',\n },\n })\n : createFetchMiddleware({ rpcService });\n\n const rpcProvider = providerFromMiddleware(rpcApiMiddleware);\n\n const blockTrackerOpts =\n process.env.IN_TEST && configuration.type === NetworkClientType.Custom\n ? { pollingInterval: SECOND }\n : {};\n const blockTracker = new PollingBlockTracker({\n ...blockTrackerOpts,\n provider: rpcProvider,\n });\n\n const networkMiddleware =\n configuration.type === NetworkClientType.Infura\n ? createInfuraNetworkMiddleware({\n blockTracker,\n network: configuration.network,\n rpcProvider,\n rpcApiMiddleware,\n })\n : createCustomNetworkMiddleware({\n blockTracker,\n chainId: configuration.chainId,\n rpcApiMiddleware,\n });\n\n const engine = new JsonRpcEngine();\n\n engine.push(networkMiddleware);\n\n const provider = providerFromEngine(engine);\n\n const destroy = () => {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n blockTracker.destroy();\n };\n\n return { configuration, provider, blockTracker, destroy };\n}\n\n/**\n * Create middleware for infura.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.network - The Infura network to use.\n * @param args.rpcProvider - The RPC provider to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createInfuraNetworkMiddleware({\n blockTracker,\n network,\n rpcProvider,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n network: InfuraNetworkType;\n rpcProvider: SafeEventEmitterProvider;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}) {\n return mergeMiddleware([\n createNetworkAndChainIdMiddleware({ network }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockRefMiddleware({ blockTracker, provider: rpcProvider }),\n createRetryOnEmptyMiddleware({ blockTracker, provider: rpcProvider }),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * Creates static method middleware.\n *\n * @param args - The Arguments.\n * @param args.network - The Infura network to use.\n * @returns The middleware that implements the eth_chainId method.\n */\nfunction createNetworkAndChainIdMiddleware({\n network,\n}: {\n network: InfuraNetworkType;\n}) {\n return createScaffoldMiddleware({\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n eth_chainId: ChainId[network],\n });\n}\n\nconst createChainIdMiddleware = (\n chainId: Hex,\n): JsonRpcMiddleware<JsonRpcParams, Json> => {\n return (req, res, next, end) => {\n if (req.method === 'eth_chainId') {\n res.result = chainId;\n return end();\n }\n return next();\n };\n};\n\n/**\n * Creates custom middleware.\n *\n * @param args - The arguments.\n * @param args.blockTracker - The block tracker to use.\n * @param args.chainId - The chain id to use.\n * @param args.rpcApiMiddleware - Additional middleware.\n * @returns The collection of middleware that makes up the Infura client.\n */\nfunction createCustomNetworkMiddleware({\n blockTracker,\n chainId,\n rpcApiMiddleware,\n}: {\n blockTracker: PollingBlockTracker;\n chainId: Hex;\n rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n const testMiddlewares = process.env.IN_TEST\n ? [createEstimateGasDelayTestMiddleware()]\n : [];\n\n return mergeMiddleware([\n ...testMiddlewares,\n createChainIdMiddleware(chainId),\n createBlockRefRewriteMiddleware({ blockTracker }),\n createBlockCacheMiddleware({ blockTracker }),\n createInflightCacheMiddleware(),\n createBlockTrackerInspectorMiddleware({ blockTracker }),\n rpcApiMiddleware,\n ]);\n}\n\n/**\n * For use in tests only.\n * Adds a delay to `eth_estimateGas` calls.\n *\n * @returns The middleware for delaying gas estimation calls by 2 seconds when in test.\n */\nfunction createEstimateGasDelayTestMiddleware() {\n return createAsyncMiddleware(async (req, _, next) => {\n if (req.method === 'eth_estimateGas') {\n await new Promise((resolve) => setTimeout(resolve, SECOND * 2));\n }\n return next();\n });\n}\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAWA;;GAEG;AACH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,sCAAiB,CAAA;AACnB,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport type { Hex } from '@metamask/utils';\n\nexport type Provider = SafeEventEmitterProvider;\n\nexport type BlockTracker = BaseBlockTracker & {\n checkForLatestBlock(): Promise<string>;\n};\n\n/**\n * The type of network client that can be created.\n */\nexport enum NetworkClientType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * A configuration object that can be used to create a client for a network.\n */\
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAWA;;GAEG;AACH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,sCAAiB,CAAA;AACnB,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport type { Hex } from '@metamask/utils';\n\nexport type Provider = SafeEventEmitterProvider;\n\nexport type BlockTracker = BaseBlockTracker & {\n checkForLatestBlock(): Promise<string>;\n};\n\n/**\n * The type of network client that can be created.\n */\nexport enum NetworkClientType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * A configuration object that can be used to create a client for a custom\n * network.\n */\nexport type CustomNetworkClientConfiguration = {\n chainId: Hex;\n rpcUrl: string;\n ticker: string;\n type: NetworkClientType.Custom;\n};\n\n/**\n * A configuration object that can be used to create a client for an Infura\n * network.\n */\nexport type InfuraNetworkClientConfiguration = {\n chainId: Hex;\n network: InfuraNetworkType;\n infuraProjectId: string;\n ticker: string;\n type: NetworkClientType.Infura;\n};\n\n/**\n * A configuration object that can be used to create a client for a network.\n */\nexport type NetworkClientConfiguration =\n | CustomNetworkClientConfiguration\n | InfuraNetworkClientConfiguration;\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -13,34 +13,29 @@ export declare enum NetworkClientType {
|
|
|
13
13
|
Custom = "custom",
|
|
14
14
|
Infura = "infura"
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* A configuration object that can be used to create a client for a network.
|
|
18
|
-
*/
|
|
19
|
-
type CommonNetworkClientConfiguration = {
|
|
20
|
-
chainId: Hex;
|
|
21
|
-
ticker: string;
|
|
22
|
-
};
|
|
23
16
|
/**
|
|
24
17
|
* A configuration object that can be used to create a client for a custom
|
|
25
18
|
* network.
|
|
26
19
|
*/
|
|
27
|
-
export type CustomNetworkClientConfiguration =
|
|
20
|
+
export type CustomNetworkClientConfiguration = {
|
|
21
|
+
chainId: Hex;
|
|
28
22
|
rpcUrl: string;
|
|
23
|
+
ticker: string;
|
|
29
24
|
type: NetworkClientType.Custom;
|
|
30
25
|
};
|
|
31
26
|
/**
|
|
32
27
|
* A configuration object that can be used to create a client for an Infura
|
|
33
28
|
* network.
|
|
34
29
|
*/
|
|
35
|
-
export type InfuraNetworkClientConfiguration =
|
|
30
|
+
export type InfuraNetworkClientConfiguration = {
|
|
31
|
+
chainId: Hex;
|
|
36
32
|
network: InfuraNetworkType;
|
|
37
33
|
infuraProjectId: string;
|
|
38
|
-
|
|
34
|
+
ticker: string;
|
|
39
35
|
type: NetworkClientType.Infura;
|
|
40
36
|
};
|
|
41
37
|
/**
|
|
42
38
|
* A configuration object that can be used to create a client for a network.
|
|
43
39
|
*/
|
|
44
40
|
export type NetworkClientConfiguration = CustomNetworkClientConfiguration | InfuraNetworkClientConfiguration;
|
|
45
|
-
export {};
|
|
46
41
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mCAAmC;AACpE,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,oCAAoC;AACpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,wCAAwC;AAChF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,MAAM,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mCAAmC;AACpE,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,oCAAoC;AACpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,wCAAwC;AAChF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,MAAM,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,iBAAiB,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAClC,gCAAgC,GAChC,gCAAgC,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -13,34 +13,29 @@ export declare enum NetworkClientType {
|
|
|
13
13
|
Custom = "custom",
|
|
14
14
|
Infura = "infura"
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* A configuration object that can be used to create a client for a network.
|
|
18
|
-
*/
|
|
19
|
-
type CommonNetworkClientConfiguration = {
|
|
20
|
-
chainId: Hex;
|
|
21
|
-
ticker: string;
|
|
22
|
-
};
|
|
23
16
|
/**
|
|
24
17
|
* A configuration object that can be used to create a client for a custom
|
|
25
18
|
* network.
|
|
26
19
|
*/
|
|
27
|
-
export type CustomNetworkClientConfiguration =
|
|
20
|
+
export type CustomNetworkClientConfiguration = {
|
|
21
|
+
chainId: Hex;
|
|
28
22
|
rpcUrl: string;
|
|
23
|
+
ticker: string;
|
|
29
24
|
type: NetworkClientType.Custom;
|
|
30
25
|
};
|
|
31
26
|
/**
|
|
32
27
|
* A configuration object that can be used to create a client for an Infura
|
|
33
28
|
* network.
|
|
34
29
|
*/
|
|
35
|
-
export type InfuraNetworkClientConfiguration =
|
|
30
|
+
export type InfuraNetworkClientConfiguration = {
|
|
31
|
+
chainId: Hex;
|
|
36
32
|
network: InfuraNetworkType;
|
|
37
33
|
infuraProjectId: string;
|
|
38
|
-
|
|
34
|
+
ticker: string;
|
|
39
35
|
type: NetworkClientType.Infura;
|
|
40
36
|
};
|
|
41
37
|
/**
|
|
42
38
|
* A configuration object that can be used to create a client for a network.
|
|
43
39
|
*/
|
|
44
40
|
export type NetworkClientConfiguration = CustomNetworkClientConfiguration | InfuraNetworkClientConfiguration;
|
|
45
|
-
export {};
|
|
46
41
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mCAAmC;AACpE,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,oCAAoC;AACpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,wCAAwC;AAChF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,MAAM,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mCAAmC;AACpE,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,oCAAoC;AACpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,wCAAwC;AAChF,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,MAAM,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG;IAC5C,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,GAAG,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,iBAAiB,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAClC,gCAAgC,GAChC,gCAAgC,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,sCAAiB,CAAA;AACnB,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport type { Hex } from '@metamask/utils';\n\nexport type Provider = SafeEventEmitterProvider;\n\nexport type BlockTracker = BaseBlockTracker & {\n checkForLatestBlock(): Promise<string>;\n};\n\n/**\n * The type of network client that can be created.\n */\nexport enum NetworkClientType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * A configuration object that can be used to create a client for a network.\n */\
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,sCAAiB,CAAA;AACnB,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B","sourcesContent":["import type { InfuraNetworkType } from '@metamask/controller-utils';\nimport type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker';\nimport type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';\nimport type { Hex } from '@metamask/utils';\n\nexport type Provider = SafeEventEmitterProvider;\n\nexport type BlockTracker = BaseBlockTracker & {\n checkForLatestBlock(): Promise<string>;\n};\n\n/**\n * The type of network client that can be created.\n */\nexport enum NetworkClientType {\n Custom = 'custom',\n Infura = 'infura',\n}\n\n/**\n * A configuration object that can be used to create a client for a custom\n * network.\n */\nexport type CustomNetworkClientConfiguration = {\n chainId: Hex;\n rpcUrl: string;\n ticker: string;\n type: NetworkClientType.Custom;\n};\n\n/**\n * A configuration object that can be used to create a client for an Infura\n * network.\n */\nexport type InfuraNetworkClientConfiguration = {\n chainId: Hex;\n network: InfuraNetworkType;\n infuraProjectId: string;\n ticker: string;\n type: NetworkClientType.Infura;\n};\n\n/**\n * A configuration object that can be used to create a client for a network.\n */\nexport type NetworkClientConfiguration =\n | CustomNetworkClientConfiguration\n | InfuraNetworkClientConfiguration;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/network-controller",
|
|
3
|
-
"version": "22.2.1-preview-
|
|
3
|
+
"version": "22.2.1-preview-dbdf1da",
|
|
4
4
|
"description": "Provides an interface to the currently selected network via a MetaMask-compatible provider object",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|