@metamask-previews/eth-json-rpc-middleware 21.0.0-preview-c96ff8f → 21.0.0-preview-b289ac1c
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 +0 -3
- package/dist/block-cache.cjs +27 -15
- package/dist/block-cache.cjs.map +1 -1
- package/dist/block-cache.d.cts +3 -5
- package/dist/block-cache.d.cts.map +1 -1
- package/dist/block-cache.d.mts +3 -5
- package/dist/block-cache.d.mts.map +1 -1
- package/dist/block-cache.mjs +27 -15
- package/dist/block-cache.mjs.map +1 -1
- package/dist/block-ref-rewrite.cjs +8 -12
- package/dist/block-ref-rewrite.cjs.map +1 -1
- package/dist/block-ref-rewrite.d.cts +3 -3
- package/dist/block-ref-rewrite.d.cts.map +1 -1
- package/dist/block-ref-rewrite.d.mts +3 -3
- package/dist/block-ref-rewrite.d.mts.map +1 -1
- package/dist/block-ref-rewrite.mjs +8 -12
- package/dist/block-ref-rewrite.mjs.map +1 -1
- package/dist/block-ref.cjs +10 -17
- package/dist/block-ref.cjs.map +1 -1
- package/dist/block-ref.d.cts +3 -12
- package/dist/block-ref.d.cts.map +1 -1
- package/dist/block-ref.d.mts +3 -12
- package/dist/block-ref.d.mts.map +1 -1
- package/dist/block-ref.mjs +10 -17
- package/dist/block-ref.mjs.map +1 -1
- package/dist/block-tracker-inspector.cjs +25 -28
- package/dist/block-tracker-inspector.cjs.map +1 -1
- package/dist/block-tracker-inspector.d.cts +3 -3
- package/dist/block-tracker-inspector.d.cts.map +1 -1
- package/dist/block-tracker-inspector.d.mts +3 -3
- package/dist/block-tracker-inspector.d.mts.map +1 -1
- package/dist/block-tracker-inspector.mjs +25 -28
- package/dist/block-tracker-inspector.mjs.map +1 -1
- package/dist/fetch.cjs +12 -8
- package/dist/fetch.cjs.map +1 -1
- package/dist/fetch.d.cts +3 -5
- package/dist/fetch.d.cts.map +1 -1
- package/dist/fetch.d.mts +3 -5
- package/dist/fetch.d.mts.map +1 -1
- package/dist/fetch.mjs +12 -8
- package/dist/fetch.mjs.map +1 -1
- package/dist/inflight-cache.cjs +45 -61
- package/dist/inflight-cache.cjs.map +1 -1
- package/dist/inflight-cache.d.cts +3 -12
- package/dist/inflight-cache.d.cts.map +1 -1
- package/dist/inflight-cache.d.mts +3 -12
- package/dist/inflight-cache.d.mts.map +1 -1
- package/dist/inflight-cache.mjs +45 -61
- package/dist/inflight-cache.mjs.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.cjs +9 -11
- package/dist/methods/wallet-request-execution-permissions.cjs.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.d.cts +3 -5
- package/dist/methods/wallet-request-execution-permissions.d.cts.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.d.mts +3 -5
- package/dist/methods/wallet-request-execution-permissions.d.mts.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.mjs +7 -9
- package/dist/methods/wallet-request-execution-permissions.mjs.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.cjs +11 -14
- package/dist/methods/wallet-revoke-execution-permission.cjs.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.d.cts +5 -10
- package/dist/methods/wallet-revoke-execution-permission.d.cts.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.d.mts +5 -10
- package/dist/methods/wallet-revoke-execution-permission.d.mts.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.mjs +8 -11
- package/dist/methods/wallet-revoke-execution-permission.mjs.map +1 -1
- package/dist/providerAsMiddleware.cjs +1 -5
- package/dist/providerAsMiddleware.cjs.map +1 -1
- package/dist/providerAsMiddleware.d.cts +3 -5
- package/dist/providerAsMiddleware.d.cts.map +1 -1
- package/dist/providerAsMiddleware.d.mts +3 -5
- package/dist/providerAsMiddleware.d.mts.map +1 -1
- package/dist/providerAsMiddleware.mjs +0 -3
- package/dist/providerAsMiddleware.mjs.map +1 -1
- package/dist/retryOnEmpty.cjs +11 -8
- package/dist/retryOnEmpty.cjs.map +1 -1
- package/dist/retryOnEmpty.d.cts +3 -3
- package/dist/retryOnEmpty.d.cts.map +1 -1
- package/dist/retryOnEmpty.d.mts +3 -3
- package/dist/retryOnEmpty.d.mts.map +1 -1
- package/dist/retryOnEmpty.mjs +11 -8
- package/dist/retryOnEmpty.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +5 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +5 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/validation.cjs +2 -2
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.cts +3 -6
- package/dist/utils/validation.d.cts.map +1 -1
- package/dist/utils/validation.d.mts +3 -6
- package/dist/utils/validation.d.mts.map +1 -1
- package/dist/utils/validation.mjs +2 -2
- package/dist/utils/validation.mjs.map +1 -1
- package/dist/wallet.cjs +92 -87
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +5 -8
- package/dist/wallet.d.cts.map +1 -1
- package/dist/wallet.d.mts +5 -8
- package/dist/wallet.d.mts.map +1 -1
- package/dist/wallet.mjs +93 -88
- package/dist/wallet.mjs.map +1 -1
- package/package.json +1 -1
package/dist/block-ref.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-ref.cjs","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"block-ref.cjs","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":";;;AAGA,+DAAkE;AAElE,qCAAmC;AAEnC,uDAAoE;AAEpE,6CAAmD;AAOnD,MAAM,GAAG,GAAG,IAAA,kCAAkB,EAAC,6BAAa,EAAE,WAAW,CAAC,CAAC;AAE3D,SAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,MACiB,EAAE;IAC/B,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,KAAK,CAAC,8DAA8D,CAAC,CAAC;KAC7E;IAED,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,KAAK,CACT,kEAAkE,CACnE,CAAC;KACH;IAED,OAAO,IAAA,uCAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,MAAM,aAAa,GAAG,IAAA,0BAAkB,EAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAErD,2CAA2C;QAC3C,IAAI,aAAa,KAAK,SAAS,EAAE;YAC/B,OAAO,IAAI,EAAE,CAAC;SACf;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;YACxC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAC;YACzC,CAAC,CAAC,QAAQ,CAAC;QAEb,uBAAuB;QACvB,IAAI,QAAQ,KAAK,QAAQ,EAAE;YACzB,GAAG,CAAC,oDAAoD,CAAC,CAAC;YAC1D,OAAO,IAAI,EAAE,CAAC;SACf;QAED,sBAAsB;QACtB,MAAM,iBAAiB,GAAG,MAAM,YAAY,CAAC,cAAc,EAAE,CAAC;QAC9D,GAAG,CACD,uCAAuC,aAAa,oBAAoB,iBAAiB,EAAE,CAC5F,CAAC;QAEF,+CAA+C;QAC/C,MAAM,YAAY,GAAG,IAAA,YAAK,EAAC,GAAG,CAAC,CAAC;QAEhC,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YACtC,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,iBAAiB,CAAC;SACxD;QAED,wBAAwB;QACxB,GAAG,CAAC,+BAA+B,EAAE,YAAY,CAAC,CAAC;QACnD,2CAA2C;QAC3C,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAuB,YAAY,CAAC,CAAC;QAExE,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AApDD,4DAoDC","sourcesContent":["import type { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport type { InternalProvider } from '@metamask/eth-json-rpc-provider';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\nimport { klona } from 'klona/full';\n\nimport { projectLogger, createModuleLogger } from './logging-utils';\nimport type { Block } from './types';\nimport { blockTagParamIndex } from './utils/cache';\n\ntype BlockRefMiddlewareOptions = {\n blockTracker?: PollingBlockTracker;\n provider?: InternalProvider;\n};\n\nconst log = createModuleLogger(projectLogger, 'block-ref');\n\nexport function createBlockRefMiddleware({\n provider,\n blockTracker,\n}: BlockRefMiddlewareOptions = {}): JsonRpcMiddleware<JsonRpcParams, Json> {\n if (!provider) {\n throw Error('BlockRefMiddleware - mandatory \"provider\" option is missing.');\n }\n\n if (!blockTracker) {\n throw Error(\n 'BlockRefMiddleware - mandatory \"blockTracker\" option is missing.',\n );\n }\n\n return createAsyncMiddleware(async (req, res, next) => {\n const blockRefIndex = blockTagParamIndex(req.method);\n\n // skip if method does not include blockRef\n if (blockRefIndex === undefined) {\n return next();\n }\n\n const blockRef = Array.isArray(req.params)\n ? (req.params[blockRefIndex] ?? 'latest')\n : 'latest';\n\n // skip if not \"latest\"\n if (blockRef !== 'latest') {\n log('blockRef is not \"latest\", carrying request forward');\n return next();\n }\n\n // lookup latest block\n const latestBlockNumber = await blockTracker.getLatestBlock();\n log(\n `blockRef is \"latest\", setting param ${blockRefIndex} to latest block ${latestBlockNumber}`,\n );\n\n // create child request with specific block-ref\n const childRequest = klona(req);\n\n if (Array.isArray(childRequest.params)) {\n childRequest.params[blockRefIndex] = latestBlockNumber;\n }\n\n // perform child request\n log('Performing another request %o', childRequest);\n // copy child result onto original response\n res.result = await provider.request<JsonRpcParams, Block>(childRequest);\n\n return undefined;\n });\n}\n"]}
|
package/dist/block-ref.d.cts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import type { PollingBlockTracker } from "@metamask/eth-block-tracker";
|
|
2
2
|
import type { InternalProvider } from "@metamask/eth-json-rpc-provider";
|
|
3
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine
|
|
4
|
-
import type { Json,
|
|
3
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
4
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
5
5
|
type BlockRefMiddlewareOptions = {
|
|
6
6
|
blockTracker?: PollingBlockTracker;
|
|
7
7
|
provider?: InternalProvider;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
* Creates a middleware that rewrites "latest" block references to the known
|
|
11
|
-
* latest block number from a block tracker.
|
|
12
|
-
*
|
|
13
|
-
* @param options - The options for the middleware.
|
|
14
|
-
* @param options.provider - The provider to use.
|
|
15
|
-
* @param options.blockTracker - The block tracker to use.
|
|
16
|
-
* @returns The middleware.
|
|
17
|
-
*/
|
|
18
|
-
export declare function createBlockRefMiddleware({ provider, blockTracker, }?: BlockRefMiddlewareOptions): JsonRpcMiddleware<JsonRpcRequest, Json>;
|
|
9
|
+
export declare function createBlockRefMiddleware({ provider, blockTracker, }?: BlockRefMiddlewareOptions): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
19
10
|
export {};
|
|
20
11
|
//# sourceMappingURL=block-ref.d.cts.map
|
package/dist/block-ref.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-ref.d.cts","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"block-ref.d.cts","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAO3D,KAAK,yBAAyB,GAAG;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B,CAAC;AAIF,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,GACb,GAAE,yBAA8B,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAiDzE"}
|
package/dist/block-ref.d.mts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import type { PollingBlockTracker } from "@metamask/eth-block-tracker";
|
|
2
2
|
import type { InternalProvider } from "@metamask/eth-json-rpc-provider";
|
|
3
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine
|
|
4
|
-
import type { Json,
|
|
3
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
4
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
5
5
|
type BlockRefMiddlewareOptions = {
|
|
6
6
|
blockTracker?: PollingBlockTracker;
|
|
7
7
|
provider?: InternalProvider;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
* Creates a middleware that rewrites "latest" block references to the known
|
|
11
|
-
* latest block number from a block tracker.
|
|
12
|
-
*
|
|
13
|
-
* @param options - The options for the middleware.
|
|
14
|
-
* @param options.provider - The provider to use.
|
|
15
|
-
* @param options.blockTracker - The block tracker to use.
|
|
16
|
-
* @returns The middleware.
|
|
17
|
-
*/
|
|
18
|
-
export declare function createBlockRefMiddleware({ provider, blockTracker, }?: BlockRefMiddlewareOptions): JsonRpcMiddleware<JsonRpcRequest, Json>;
|
|
9
|
+
export declare function createBlockRefMiddleware({ provider, blockTracker, }?: BlockRefMiddlewareOptions): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
19
10
|
export {};
|
|
20
11
|
//# sourceMappingURL=block-ref.d.mts.map
|
package/dist/block-ref.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-ref.d.mts","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"block-ref.d.mts","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAO3D,KAAK,yBAAyB,GAAG;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B,CAAC;AAIF,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,GACb,GAAE,yBAA8B,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAiDzE"}
|
package/dist/block-ref.mjs
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAsyncMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { klona } from "klona/full";
|
|
2
3
|
import { projectLogger, createModuleLogger } from "./logging-utils.mjs";
|
|
3
4
|
import { blockTagParamIndex } from "./utils/cache.mjs";
|
|
4
5
|
const log = createModuleLogger(projectLogger, 'block-ref');
|
|
5
|
-
/**
|
|
6
|
-
* Creates a middleware that rewrites "latest" block references to the known
|
|
7
|
-
* latest block number from a block tracker.
|
|
8
|
-
*
|
|
9
|
-
* @param options - The options for the middleware.
|
|
10
|
-
* @param options.provider - The provider to use.
|
|
11
|
-
* @param options.blockTracker - The block tracker to use.
|
|
12
|
-
* @returns The middleware.
|
|
13
|
-
*/
|
|
14
6
|
export function createBlockRefMiddleware({ provider, blockTracker, } = {}) {
|
|
15
7
|
if (!provider) {
|
|
16
8
|
throw Error('BlockRefMiddleware - mandatory "provider" option is missing.');
|
|
@@ -18,14 +10,14 @@ export function createBlockRefMiddleware({ provider, blockTracker, } = {}) {
|
|
|
18
10
|
if (!blockTracker) {
|
|
19
11
|
throw Error('BlockRefMiddleware - mandatory "blockTracker" option is missing.');
|
|
20
12
|
}
|
|
21
|
-
return async (
|
|
22
|
-
const blockRefIndex = blockTagParamIndex(
|
|
13
|
+
return createAsyncMiddleware(async (req, res, next) => {
|
|
14
|
+
const blockRefIndex = blockTagParamIndex(req.method);
|
|
23
15
|
// skip if method does not include blockRef
|
|
24
16
|
if (blockRefIndex === undefined) {
|
|
25
17
|
return next();
|
|
26
18
|
}
|
|
27
|
-
const blockRef = Array.isArray(
|
|
28
|
-
? (
|
|
19
|
+
const blockRef = Array.isArray(req.params)
|
|
20
|
+
? (req.params[blockRefIndex] ?? 'latest')
|
|
29
21
|
: 'latest';
|
|
30
22
|
// skip if not "latest"
|
|
31
23
|
if (blockRef !== 'latest') {
|
|
@@ -36,14 +28,15 @@ export function createBlockRefMiddleware({ provider, blockTracker, } = {}) {
|
|
|
36
28
|
const latestBlockNumber = await blockTracker.getLatestBlock();
|
|
37
29
|
log(`blockRef is "latest", setting param ${blockRefIndex} to latest block ${latestBlockNumber}`);
|
|
38
30
|
// create child request with specific block-ref
|
|
39
|
-
const childRequest = klona(
|
|
31
|
+
const childRequest = klona(req);
|
|
40
32
|
if (Array.isArray(childRequest.params)) {
|
|
41
33
|
childRequest.params[blockRefIndex] = latestBlockNumber;
|
|
42
34
|
}
|
|
43
35
|
// perform child request
|
|
44
36
|
log('Performing another request %o', childRequest);
|
|
45
37
|
// copy child result onto original response
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
res.result = await provider.request(childRequest);
|
|
39
|
+
return undefined;
|
|
40
|
+
});
|
|
48
41
|
}
|
|
49
42
|
//# sourceMappingURL=block-ref.mjs.map
|
package/dist/block-ref.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-ref.mjs","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"block-ref.mjs","sourceRoot":"","sources":["../src/block-ref.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,kCAAkC;AAElE,OAAO,EAAE,KAAK,EAAE,mBAAmB;AAEnC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,4BAAwB;AAEpE,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AAOnD,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAE3D,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,EACR,YAAY,MACiB,EAAE;IAC/B,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,KAAK,CAAC,8DAA8D,CAAC,CAAC;KAC7E;IAED,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,KAAK,CACT,kEAAkE,CACnE,CAAC;KACH;IAED,OAAO,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAErD,2CAA2C;QAC3C,IAAI,aAAa,KAAK,SAAS,EAAE;YAC/B,OAAO,IAAI,EAAE,CAAC;SACf;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;YACxC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,QAAQ,CAAC;YACzC,CAAC,CAAC,QAAQ,CAAC;QAEb,uBAAuB;QACvB,IAAI,QAAQ,KAAK,QAAQ,EAAE;YACzB,GAAG,CAAC,oDAAoD,CAAC,CAAC;YAC1D,OAAO,IAAI,EAAE,CAAC;SACf;QAED,sBAAsB;QACtB,MAAM,iBAAiB,GAAG,MAAM,YAAY,CAAC,cAAc,EAAE,CAAC;QAC9D,GAAG,CACD,uCAAuC,aAAa,oBAAoB,iBAAiB,EAAE,CAC5F,CAAC;QAEF,+CAA+C;QAC/C,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QAEhC,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YACtC,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,iBAAiB,CAAC;SACxD;QAED,wBAAwB;QACxB,GAAG,CAAC,+BAA+B,EAAE,YAAY,CAAC,CAAC;QACnD,2CAA2C;QAC3C,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAuB,YAAY,CAAC,CAAC;QAExE,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport type { InternalProvider } from '@metamask/eth-json-rpc-provider';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\nimport { klona } from 'klona/full';\n\nimport { projectLogger, createModuleLogger } from './logging-utils';\nimport type { Block } from './types';\nimport { blockTagParamIndex } from './utils/cache';\n\ntype BlockRefMiddlewareOptions = {\n blockTracker?: PollingBlockTracker;\n provider?: InternalProvider;\n};\n\nconst log = createModuleLogger(projectLogger, 'block-ref');\n\nexport function createBlockRefMiddleware({\n provider,\n blockTracker,\n}: BlockRefMiddlewareOptions = {}): JsonRpcMiddleware<JsonRpcParams, Json> {\n if (!provider) {\n throw Error('BlockRefMiddleware - mandatory \"provider\" option is missing.');\n }\n\n if (!blockTracker) {\n throw Error(\n 'BlockRefMiddleware - mandatory \"blockTracker\" option is missing.',\n );\n }\n\n return createAsyncMiddleware(async (req, res, next) => {\n const blockRefIndex = blockTagParamIndex(req.method);\n\n // skip if method does not include blockRef\n if (blockRefIndex === undefined) {\n return next();\n }\n\n const blockRef = Array.isArray(req.params)\n ? (req.params[blockRefIndex] ?? 'latest')\n : 'latest';\n\n // skip if not \"latest\"\n if (blockRef !== 'latest') {\n log('blockRef is not \"latest\", carrying request forward');\n return next();\n }\n\n // lookup latest block\n const latestBlockNumber = await blockTracker.getLatestBlock();\n log(\n `blockRef is \"latest\", setting param ${blockRefIndex} to latest block ${latestBlockNumber}`,\n );\n\n // create child request with specific block-ref\n const childRequest = klona(req);\n\n if (Array.isArray(childRequest.params)) {\n childRequest.params[blockRefIndex] = latestBlockNumber;\n }\n\n // perform child request\n log('Performing another request %o', childRequest);\n // copy child result onto original response\n res.result = await provider.request<JsonRpcParams, Block>(childRequest);\n\n return undefined;\n });\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createBlockTrackerInspectorMiddleware = void 0;
|
|
4
|
+
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
4
5
|
const utils_1 = require("@metamask/utils");
|
|
5
6
|
const logging_utils_1 = require("./logging-utils.cjs");
|
|
6
7
|
const log = (0, logging_utils_1.createModuleLogger)(logging_utils_1.projectLogger, 'block-tracker-inspector');
|
|
@@ -17,43 +18,39 @@ const futureBlockRefRequests = [
|
|
|
17
18
|
* @returns The middleware.
|
|
18
19
|
*/
|
|
19
20
|
function createBlockTrackerInspectorMiddleware({ blockTracker, }) {
|
|
20
|
-
return async (
|
|
21
|
-
if (!futureBlockRefRequests.includes(
|
|
21
|
+
return (0, json_rpc_engine_1.createAsyncMiddleware)(async (req, res, next) => {
|
|
22
|
+
if (!futureBlockRefRequests.includes(req.method)) {
|
|
22
23
|
return next();
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
const responseBlockNumber = getResultBlockNumber(
|
|
26
|
-
if (responseBlockNumber) {
|
|
27
|
-
|
|
28
|
-
// If number is higher, suggest block-tracker check for a new block
|
|
29
|
-
const blockNumber = Number.parseInt(responseBlockNumber, 16);
|
|
30
|
-
const currentBlockNumber = Number.parseInt(
|
|
31
|
-
// Typecast: If getCurrentBlock returns null, currentBlockNumber will be NaN, which is fine.
|
|
32
|
-
blockTracker.getCurrentBlock(), 16);
|
|
33
|
-
if (blockNumber > currentBlockNumber) {
|
|
34
|
-
log('blockNumber from response is greater than current block number, refreshing current block number');
|
|
35
|
-
await blockTracker.checkForLatestBlock();
|
|
36
|
-
}
|
|
25
|
+
await next();
|
|
26
|
+
const responseBlockNumber = getResultBlockNumber(res);
|
|
27
|
+
if (!responseBlockNumber) {
|
|
28
|
+
return undefined;
|
|
37
29
|
}
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
log('res.result.blockNumber exists, proceeding. res = %o', res);
|
|
31
|
+
// If number is higher, suggest block-tracker check for a new block
|
|
32
|
+
const blockNumber = Number.parseInt(responseBlockNumber, 16);
|
|
33
|
+
const currentBlockNumber = Number.parseInt(
|
|
34
|
+
// Typecast: If getCurrentBlock returns null, currentBlockNumber will be NaN, which is fine.
|
|
35
|
+
blockTracker.getCurrentBlock(), 16);
|
|
36
|
+
if (blockNumber > currentBlockNumber) {
|
|
37
|
+
log('blockNumber from response is greater than current block number, refreshing current block number');
|
|
38
|
+
await blockTracker.checkForLatestBlock();
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
});
|
|
40
42
|
}
|
|
41
43
|
exports.createBlockTrackerInspectorMiddleware = createBlockTrackerInspectorMiddleware;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
* @param result - The result to extract the block number from.
|
|
46
|
-
* @returns The block number, or undefined if the result is not an object with a
|
|
47
|
-
* `blockNumber` property.
|
|
48
|
-
*/
|
|
49
|
-
function getResultBlockNumber(result) {
|
|
44
|
+
function getResultBlockNumber(response) {
|
|
45
|
+
const { result } = response;
|
|
50
46
|
if (!result ||
|
|
51
47
|
typeof result !== 'object' ||
|
|
52
48
|
!(0, utils_1.hasProperty)(result, 'blockNumber')) {
|
|
53
49
|
return undefined;
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
if (typeof result.blockNumber === 'string') {
|
|
52
|
+
return result.blockNumber;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
58
55
|
}
|
|
59
56
|
//# sourceMappingURL=block-tracker-inspector.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-tracker-inspector.cjs","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":";;;AAEA,2CAA8C;
|
|
1
|
+
{"version":3,"file":"block-tracker-inspector.cjs","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":";;;AAEA,+DAAkE;AAClE,2CAA8C;AAO9C,uDAAoE;AAEpE,MAAM,GAAG,GAAG,IAAA,kCAAkB,EAAC,6BAAa,EAAE,yBAAyB,CAAC,CAAC;AACzE,MAAM,sBAAsB,GAAsB;IAChD,0BAA0B;IAC1B,2BAA2B;CAC5B,CAAC;AAEF;;;;;;;GAOG;AACH,SAAgB,qCAAqC,CAAC,EACpD,YAAY,GAGb;IACC,OAAO,IAAA,uCAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAChD,OAAO,IAAI,EAAE,CAAC;SACf;QACD,MAAM,IAAI,EAAE,CAAC;QAEb,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;QACtD,IAAI,CAAC,mBAAmB,EAAE;YACxB,OAAO,SAAS,CAAC;SAClB;QAED,GAAG,CAAC,qDAAqD,EAAE,GAAG,CAAC,CAAC;QAEhE,mEAAmE;QACnE,MAAM,WAAW,GAAW,MAAM,CAAC,QAAQ,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,kBAAkB,GAAW,MAAM,CAAC,QAAQ;QAChD,4FAA4F;QAC5F,YAAY,CAAC,eAAe,EAAY,EACxC,EAAE,CACH,CAAC;QACF,IAAI,WAAW,GAAG,kBAAkB,EAAE;YACpC,GAAG,CACD,iGAAiG,CAClG,CAAC;YACF,MAAM,YAAY,CAAC,mBAAmB,EAAE,CAAC;SAC1C;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAjCD,sFAiCC;AAED,SAAS,oBAAoB,CAC3B,QAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAC5B,IACE,CAAC,MAAM;QACP,OAAO,MAAM,KAAK,QAAQ;QAC1B,CAAC,IAAA,mBAAW,EAAC,MAAM,EAAE,aAAa,CAAC,EACnC;QACA,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ,EAAE;QAC1C,OAAO,MAAM,CAAC,WAAW,CAAC;KAC3B;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport { hasProperty } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcParams,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport { projectLogger, createModuleLogger } from './logging-utils';\n\nconst log = createModuleLogger(projectLogger, 'block-tracker-inspector');\nconst futureBlockRefRequests: readonly string[] = [\n 'eth_getTransactionByHash',\n 'eth_getTransactionReceipt',\n];\n\n/**\n * Creates a middleware that checks whether response block references are higher than the current block.\n * If the block reference is higher, the middleware will make the block tracker check for a new block.\n *\n * @param options - The options for the middleware.\n * @param options.blockTracker - The block tracker to use.\n * @returns The middleware.\n */\nexport function createBlockTrackerInspectorMiddleware({\n blockTracker,\n}: {\n blockTracker: PollingBlockTracker;\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n return createAsyncMiddleware(async (req, res, next) => {\n if (!futureBlockRefRequests.includes(req.method)) {\n return next();\n }\n await next();\n\n const responseBlockNumber = getResultBlockNumber(res);\n if (!responseBlockNumber) {\n return undefined;\n }\n\n log('res.result.blockNumber exists, proceeding. res = %o', res);\n\n // If number is higher, suggest block-tracker check for a new block\n const blockNumber: number = Number.parseInt(responseBlockNumber, 16);\n const currentBlockNumber: number = Number.parseInt(\n // Typecast: If getCurrentBlock returns null, currentBlockNumber will be NaN, which is fine.\n blockTracker.getCurrentBlock() as string,\n 16,\n );\n if (blockNumber > currentBlockNumber) {\n log(\n 'blockNumber from response is greater than current block number, refreshing current block number',\n );\n await blockTracker.checkForLatestBlock();\n }\n return undefined;\n });\n}\n\nfunction getResultBlockNumber(\n response: PendingJsonRpcResponse,\n): string | undefined {\n const { result } = response;\n if (\n !result ||\n typeof result !== 'object' ||\n !hasProperty(result, 'blockNumber')\n ) {\n return undefined;\n }\n\n if (typeof result.blockNumber === 'string') {\n return result.blockNumber;\n }\n return undefined;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PollingBlockTracker } from "@metamask/eth-block-tracker";
|
|
2
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine
|
|
3
|
-
import type { Json,
|
|
2
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a middleware that checks whether response block references are higher than the current block.
|
|
6
6
|
* If the block reference is higher, the middleware will make the block tracker check for a new block.
|
|
@@ -11,5 +11,5 @@ import type { Json, JsonRpcRequest } from "@metamask/utils";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function createBlockTrackerInspectorMiddleware({ blockTracker, }: {
|
|
13
13
|
blockTracker: PollingBlockTracker;
|
|
14
|
-
}): JsonRpcMiddleware<
|
|
14
|
+
}): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
15
15
|
//# sourceMappingURL=block-tracker-inspector.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-tracker-inspector.d.cts","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"block-tracker-inspector.d.cts","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAGnE,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EAEd,wBAAwB;AAUzB;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CAAC,EACpD,YAAY,GACb,EAAE;IACD,YAAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CA6BzC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PollingBlockTracker } from "@metamask/eth-block-tracker";
|
|
2
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine
|
|
3
|
-
import type { Json,
|
|
2
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a middleware that checks whether response block references are higher than the current block.
|
|
6
6
|
* If the block reference is higher, the middleware will make the block tracker check for a new block.
|
|
@@ -11,5 +11,5 @@ import type { Json, JsonRpcRequest } from "@metamask/utils";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function createBlockTrackerInspectorMiddleware({ blockTracker, }: {
|
|
13
13
|
blockTracker: PollingBlockTracker;
|
|
14
|
-
}): JsonRpcMiddleware<
|
|
14
|
+
}): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
15
15
|
//# sourceMappingURL=block-tracker-inspector.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-tracker-inspector.d.mts","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"block-tracker-inspector.d.mts","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAGnE,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EAEd,wBAAwB;AAUzB;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CAAC,EACpD,YAAY,GACb,EAAE;IACD,YAAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CA6BzC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createAsyncMiddleware } from "@metamask/json-rpc-engine";
|
|
1
2
|
import { hasProperty } from "@metamask/utils";
|
|
2
3
|
import { projectLogger, createModuleLogger } from "./logging-utils.mjs";
|
|
3
4
|
const log = createModuleLogger(projectLogger, 'block-tracker-inspector');
|
|
@@ -14,42 +15,38 @@ const futureBlockRefRequests = [
|
|
|
14
15
|
* @returns The middleware.
|
|
15
16
|
*/
|
|
16
17
|
export function createBlockTrackerInspectorMiddleware({ blockTracker, }) {
|
|
17
|
-
return async (
|
|
18
|
-
if (!futureBlockRefRequests.includes(
|
|
18
|
+
return createAsyncMiddleware(async (req, res, next) => {
|
|
19
|
+
if (!futureBlockRefRequests.includes(req.method)) {
|
|
19
20
|
return next();
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
const responseBlockNumber = getResultBlockNumber(
|
|
23
|
-
if (responseBlockNumber) {
|
|
24
|
-
|
|
25
|
-
// If number is higher, suggest block-tracker check for a new block
|
|
26
|
-
const blockNumber = Number.parseInt(responseBlockNumber, 16);
|
|
27
|
-
const currentBlockNumber = Number.parseInt(
|
|
28
|
-
// Typecast: If getCurrentBlock returns null, currentBlockNumber will be NaN, which is fine.
|
|
29
|
-
blockTracker.getCurrentBlock(), 16);
|
|
30
|
-
if (blockNumber > currentBlockNumber) {
|
|
31
|
-
log('blockNumber from response is greater than current block number, refreshing current block number');
|
|
32
|
-
await blockTracker.checkForLatestBlock();
|
|
33
|
-
}
|
|
22
|
+
await next();
|
|
23
|
+
const responseBlockNumber = getResultBlockNumber(res);
|
|
24
|
+
if (!responseBlockNumber) {
|
|
25
|
+
return undefined;
|
|
34
26
|
}
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
log('res.result.blockNumber exists, proceeding. res = %o', res);
|
|
28
|
+
// If number is higher, suggest block-tracker check for a new block
|
|
29
|
+
const blockNumber = Number.parseInt(responseBlockNumber, 16);
|
|
30
|
+
const currentBlockNumber = Number.parseInt(
|
|
31
|
+
// Typecast: If getCurrentBlock returns null, currentBlockNumber will be NaN, which is fine.
|
|
32
|
+
blockTracker.getCurrentBlock(), 16);
|
|
33
|
+
if (blockNumber > currentBlockNumber) {
|
|
34
|
+
log('blockNumber from response is greater than current block number, refreshing current block number');
|
|
35
|
+
await blockTracker.checkForLatestBlock();
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
});
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
* @param result - The result to extract the block number from.
|
|
42
|
-
* @returns The block number, or undefined if the result is not an object with a
|
|
43
|
-
* `blockNumber` property.
|
|
44
|
-
*/
|
|
45
|
-
function getResultBlockNumber(result) {
|
|
40
|
+
function getResultBlockNumber(response) {
|
|
41
|
+
const { result } = response;
|
|
46
42
|
if (!result ||
|
|
47
43
|
typeof result !== 'object' ||
|
|
48
44
|
!hasProperty(result, 'blockNumber')) {
|
|
49
45
|
return undefined;
|
|
50
46
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
if (typeof result.blockNumber === 'string') {
|
|
48
|
+
return result.blockNumber;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
54
51
|
}
|
|
55
52
|
//# sourceMappingURL=block-tracker-inspector.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-tracker-inspector.mjs","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"block-tracker-inspector.mjs","sourceRoot":"","sources":["../src/block-tracker-inspector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,kCAAkC;AAClE,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAO9C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,4BAAwB;AAEpE,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;AACzE,MAAM,sBAAsB,GAAsB;IAChD,0BAA0B;IAC1B,2BAA2B;CAC5B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,qCAAqC,CAAC,EACpD,YAAY,GAGb;IACC,OAAO,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACpD,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAChD,OAAO,IAAI,EAAE,CAAC;SACf;QACD,MAAM,IAAI,EAAE,CAAC;QAEb,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;QACtD,IAAI,CAAC,mBAAmB,EAAE;YACxB,OAAO,SAAS,CAAC;SAClB;QAED,GAAG,CAAC,qDAAqD,EAAE,GAAG,CAAC,CAAC;QAEhE,mEAAmE;QACnE,MAAM,WAAW,GAAW,MAAM,CAAC,QAAQ,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,kBAAkB,GAAW,MAAM,CAAC,QAAQ;QAChD,4FAA4F;QAC5F,YAAY,CAAC,eAAe,EAAY,EACxC,EAAE,CACH,CAAC;QACF,IAAI,WAAW,GAAG,kBAAkB,EAAE;YACpC,GAAG,CACD,iGAAiG,CAClG,CAAC;YACF,MAAM,YAAY,CAAC,mBAAmB,EAAE,CAAC;SAC1C;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,oBAAoB,CAC3B,QAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAC5B,IACE,CAAC,MAAM;QACP,OAAO,MAAM,KAAK,QAAQ;QAC1B,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,EACnC;QACA,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ,EAAE;QAC1C,OAAO,MAAM,CAAC,WAAW,CAAC;KAC3B;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport { hasProperty } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcParams,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport { projectLogger, createModuleLogger } from './logging-utils';\n\nconst log = createModuleLogger(projectLogger, 'block-tracker-inspector');\nconst futureBlockRefRequests: readonly string[] = [\n 'eth_getTransactionByHash',\n 'eth_getTransactionReceipt',\n];\n\n/**\n * Creates a middleware that checks whether response block references are higher than the current block.\n * If the block reference is higher, the middleware will make the block tracker check for a new block.\n *\n * @param options - The options for the middleware.\n * @param options.blockTracker - The block tracker to use.\n * @returns The middleware.\n */\nexport function createBlockTrackerInspectorMiddleware({\n blockTracker,\n}: {\n blockTracker: PollingBlockTracker;\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n return createAsyncMiddleware(async (req, res, next) => {\n if (!futureBlockRefRequests.includes(req.method)) {\n return next();\n }\n await next();\n\n const responseBlockNumber = getResultBlockNumber(res);\n if (!responseBlockNumber) {\n return undefined;\n }\n\n log('res.result.blockNumber exists, proceeding. res = %o', res);\n\n // If number is higher, suggest block-tracker check for a new block\n const blockNumber: number = Number.parseInt(responseBlockNumber, 16);\n const currentBlockNumber: number = Number.parseInt(\n // Typecast: If getCurrentBlock returns null, currentBlockNumber will be NaN, which is fine.\n blockTracker.getCurrentBlock() as string,\n 16,\n );\n if (blockNumber > currentBlockNumber) {\n log(\n 'blockNumber from response is greater than current block number, refreshing current block number',\n );\n await blockTracker.checkForLatestBlock();\n }\n return undefined;\n });\n}\n\nfunction getResultBlockNumber(\n response: PendingJsonRpcResponse,\n): string | undefined {\n const { result } = response;\n if (\n !result ||\n typeof result !== 'object' ||\n !hasProperty(result, 'blockNumber')\n ) {\n return undefined;\n }\n\n if (typeof result.blockNumber === 'string') {\n return result.blockNumber;\n }\n return undefined;\n}\n"]}
|
package/dist/fetch.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFetchMiddleware = void 0;
|
|
4
|
+
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
4
5
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
|
-
const klona_1 = require("klona");
|
|
6
6
|
/**
|
|
7
7
|
* Creates middleware for sending a JSON-RPC request through the given RPC
|
|
8
8
|
* service.
|
|
@@ -16,14 +16,18 @@ const klona_1 = require("klona");
|
|
|
16
16
|
* @returns The fetch middleware.
|
|
17
17
|
*/
|
|
18
18
|
function createFetchMiddleware({ rpcService, options = {}, }) {
|
|
19
|
-
return async (
|
|
20
|
-
const origin = context.get('origin');
|
|
19
|
+
return (0, json_rpc_engine_1.createAsyncMiddleware)(async (req, res) => {
|
|
21
20
|
const headers = 'originHttpHeaderKey' in options &&
|
|
22
21
|
options.originHttpHeaderKey !== undefined &&
|
|
23
|
-
origin !== undefined
|
|
24
|
-
? { [options.originHttpHeaderKey]: origin }
|
|
22
|
+
req.origin !== undefined
|
|
23
|
+
? { [options.originHttpHeaderKey]: req.origin }
|
|
25
24
|
: {};
|
|
26
|
-
const jsonRpcResponse = await rpcService.request(
|
|
25
|
+
const jsonRpcResponse = await rpcService.request({
|
|
26
|
+
id: req.id,
|
|
27
|
+
jsonrpc: req.jsonrpc,
|
|
28
|
+
method: req.method,
|
|
29
|
+
params: req.params,
|
|
30
|
+
}, {
|
|
27
31
|
headers,
|
|
28
32
|
});
|
|
29
33
|
// NOTE: We intentionally do not test to see if `jsonRpcResponse.error` is
|
|
@@ -37,8 +41,8 @@ function createFetchMiddleware({ rpcService, options = {}, }) {
|
|
|
37
41
|
}
|
|
38
42
|
// Discard the `id` and `jsonrpc` fields in the response body
|
|
39
43
|
// (the JSON-RPC engine will fill those in)
|
|
40
|
-
|
|
41
|
-
};
|
|
44
|
+
res.result = jsonRpcResponse.result;
|
|
45
|
+
});
|
|
42
46
|
}
|
|
43
47
|
exports.createFetchMiddleware = createFetchMiddleware;
|
|
44
48
|
//# sourceMappingURL=fetch.cjs.map
|
package/dist/fetch.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.cjs","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fetch.cjs","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;AACA,+DAAkE;AAClE,qDAAiD;AAcjD;;;;;;;;;;;GAWG;AACH,SAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,OAAO,GAAG,EAAE,GAMb;IACC,OAAO,IAAA,uCAAqB,EAC1B,KAAK,EAAE,GAA4C,EAAE,GAAG,EAAE,EAAE;QAC1D,MAAM,OAAO,GACX,qBAAqB,IAAI,OAAO;YAChC,OAAO,CAAC,mBAAmB,KAAK,SAAS;YACzC,GAAG,CAAC,MAAM,KAAK,SAAS;YACtB,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QAET,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,OAAO,CAC9C;YACE,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,MAAM,EAAE,GAAG,CAAC,MAAM;SACnB,EACD;YACE,OAAO;SACR,CACF,CAAC;QAEF,0EAA0E;QAC1E,4CAA4C;QAC5C,sEAAsE;QACtE,uEAAuE;QACvE,IAAI,OAAO,IAAI,eAAe,EAAE;YAC9B,MAAM,sBAAS,CAAC,QAAQ,CAAC;gBACvB,IAAI,EAAE,eAAe,CAAC,KAAK;aAC5B,CAAC,CAAC;SACJ;QAED,6DAA6D;QAC7D,2CAA2C;QAC3C,GAAG,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IACtC,CAAC,CACF,CAAC;AACJ,CAAC;AA7CD,sDA6CC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport type { AbstractRpcServiceLike } from './types';\n\n/**\n * Like a JSON-RPC request, but includes an optional `origin` property.\n * This will be included in the request as a header if specified.\n */\ntype JsonRpcRequestWithOrigin<Params extends JsonRpcParams> =\n JsonRpcRequest<Params> & {\n origin?: string;\n };\n\n/**\n * Creates middleware for sending a JSON-RPC request through the given RPC\n * service.\n *\n * @param args - The arguments to this function.\n * @param args.rpcService - The RPC service to use.\n * @param args.options - Options.\n * @param args.options.originHttpHeaderKey - If provided, the origin field for\n * each JSON-RPC request will be attached to each outgoing fetch request under\n * this header.\n * @returns The fetch middleware.\n */\nexport function createFetchMiddleware({\n rpcService,\n options = {},\n}: {\n rpcService: AbstractRpcServiceLike;\n options?: {\n originHttpHeaderKey?: string;\n };\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n return createAsyncMiddleware(\n async (req: JsonRpcRequestWithOrigin<JsonRpcParams>, res) => {\n const headers =\n 'originHttpHeaderKey' in options &&\n options.originHttpHeaderKey !== undefined &&\n req.origin !== undefined\n ? { [options.originHttpHeaderKey]: req.origin }\n : {};\n\n const jsonRpcResponse = await rpcService.request(\n {\n id: req.id,\n jsonrpc: req.jsonrpc,\n method: req.method,\n params: req.params,\n },\n {\n headers,\n },\n );\n\n // NOTE: We intentionally do not test to see if `jsonRpcResponse.error` is\n // strictly a JSON-RPC error response as per\n // <https://www.jsonrpc.org/specification#error_object> to account for\n // Ganache returning error objects with extra properties such as `name`\n if ('error' in jsonRpcResponse) {\n throw rpcErrors.internal({\n data: jsonRpcResponse.error,\n });\n }\n\n // Discard the `id` and `jsonrpc` fields in the response body\n // (the JSON-RPC engine will fill those in)\n res.result = jsonRpcResponse.result;\n },\n );\n}\n"]}
|
package/dist/fetch.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware
|
|
2
|
-
import type { Json,
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
3
|
import type { AbstractRpcServiceLike } from "./types.cjs";
|
|
4
4
|
/**
|
|
5
5
|
* Creates middleware for sending a JSON-RPC request through the given RPC
|
|
@@ -18,7 +18,5 @@ export declare function createFetchMiddleware({ rpcService, options, }: {
|
|
|
18
18
|
options?: {
|
|
19
19
|
originHttpHeaderKey?: string;
|
|
20
20
|
};
|
|
21
|
-
}): JsonRpcMiddleware<
|
|
22
|
-
origin: string;
|
|
23
|
-
}>>;
|
|
21
|
+
}): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
24
22
|
//# sourceMappingURL=fetch.d.cts.map
|
package/dist/fetch.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.cts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"fetch.d.cts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAGnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAkB,wBAAwB;AAE3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AAWtD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,OAAY,GACb,EAAE;IACD,UAAU,EAAE,sBAAsB,CAAC;IACnC,OAAO,CAAC,EAAE;QACR,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;CACH,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAqCzC"}
|
package/dist/fetch.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware
|
|
2
|
-
import type { Json,
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
3
3
|
import type { AbstractRpcServiceLike } from "./types.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Creates middleware for sending a JSON-RPC request through the given RPC
|
|
@@ -18,7 +18,5 @@ export declare function createFetchMiddleware({ rpcService, options, }: {
|
|
|
18
18
|
options?: {
|
|
19
19
|
originHttpHeaderKey?: string;
|
|
20
20
|
};
|
|
21
|
-
}): JsonRpcMiddleware<
|
|
22
|
-
origin: string;
|
|
23
|
-
}>>;
|
|
21
|
+
}): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
24
22
|
//# sourceMappingURL=fetch.d.mts.map
|
package/dist/fetch.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.mts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"fetch.d.mts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAGnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAkB,wBAAwB;AAE3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AAWtD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,OAAY,GACb,EAAE;IACD,UAAU,EAAE,sBAAsB,CAAC;IACnC,OAAO,CAAC,EAAE;QACR,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;CACH,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAqCzC"}
|
package/dist/fetch.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { createAsyncMiddleware } from "@metamask/json-rpc-engine";
|
|
1
2
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
|
-
import { klona } from "klona";
|
|
3
3
|
/**
|
|
4
4
|
* Creates middleware for sending a JSON-RPC request through the given RPC
|
|
5
5
|
* service.
|
|
@@ -13,14 +13,18 @@ import { klona } from "klona";
|
|
|
13
13
|
* @returns The fetch middleware.
|
|
14
14
|
*/
|
|
15
15
|
export function createFetchMiddleware({ rpcService, options = {}, }) {
|
|
16
|
-
return async (
|
|
17
|
-
const origin = context.get('origin');
|
|
16
|
+
return createAsyncMiddleware(async (req, res) => {
|
|
18
17
|
const headers = 'originHttpHeaderKey' in options &&
|
|
19
18
|
options.originHttpHeaderKey !== undefined &&
|
|
20
|
-
origin !== undefined
|
|
21
|
-
? { [options.originHttpHeaderKey]: origin }
|
|
19
|
+
req.origin !== undefined
|
|
20
|
+
? { [options.originHttpHeaderKey]: req.origin }
|
|
22
21
|
: {};
|
|
23
|
-
const jsonRpcResponse = await rpcService.request(
|
|
22
|
+
const jsonRpcResponse = await rpcService.request({
|
|
23
|
+
id: req.id,
|
|
24
|
+
jsonrpc: req.jsonrpc,
|
|
25
|
+
method: req.method,
|
|
26
|
+
params: req.params,
|
|
27
|
+
}, {
|
|
24
28
|
headers,
|
|
25
29
|
});
|
|
26
30
|
// NOTE: We intentionally do not test to see if `jsonRpcResponse.error` is
|
|
@@ -34,7 +38,7 @@ export function createFetchMiddleware({ rpcService, options = {}, }) {
|
|
|
34
38
|
}
|
|
35
39
|
// Discard the `id` and `jsonrpc` fields in the response body
|
|
36
40
|
// (the JSON-RPC engine will fill those in)
|
|
37
|
-
|
|
38
|
-
};
|
|
41
|
+
res.result = jsonRpcResponse.result;
|
|
42
|
+
});
|
|
39
43
|
}
|
|
40
44
|
//# sourceMappingURL=fetch.mjs.map
|
package/dist/fetch.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.mjs","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.mjs","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,kCAAkC;AAClE,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAcjD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,UAAU,EACV,OAAO,GAAG,EAAE,GAMb;IACC,OAAO,qBAAqB,CAC1B,KAAK,EAAE,GAA4C,EAAE,GAAG,EAAE,EAAE;QAC1D,MAAM,OAAO,GACX,qBAAqB,IAAI,OAAO;YAChC,OAAO,CAAC,mBAAmB,KAAK,SAAS;YACzC,GAAG,CAAC,MAAM,KAAK,SAAS;YACtB,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QAET,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,OAAO,CAC9C;YACE,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,MAAM,EAAE,GAAG,CAAC,MAAM;SACnB,EACD;YACE,OAAO;SACR,CACF,CAAC;QAEF,0EAA0E;QAC1E,4CAA4C;QAC5C,sEAAsE;QACtE,uEAAuE;QACvE,IAAI,OAAO,IAAI,eAAe,EAAE;YAC9B,MAAM,SAAS,CAAC,QAAQ,CAAC;gBACvB,IAAI,EAAE,eAAe,CAAC,KAAK;aAC5B,CAAC,CAAC;SACJ;QAED,6DAA6D;QAC7D,2CAA2C;QAC3C,GAAG,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IACtC,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport type { AbstractRpcServiceLike } from './types';\n\n/**\n * Like a JSON-RPC request, but includes an optional `origin` property.\n * This will be included in the request as a header if specified.\n */\ntype JsonRpcRequestWithOrigin<Params extends JsonRpcParams> =\n JsonRpcRequest<Params> & {\n origin?: string;\n };\n\n/**\n * Creates middleware for sending a JSON-RPC request through the given RPC\n * service.\n *\n * @param args - The arguments to this function.\n * @param args.rpcService - The RPC service to use.\n * @param args.options - Options.\n * @param args.options.originHttpHeaderKey - If provided, the origin field for\n * each JSON-RPC request will be attached to each outgoing fetch request under\n * this header.\n * @returns The fetch middleware.\n */\nexport function createFetchMiddleware({\n rpcService,\n options = {},\n}: {\n rpcService: AbstractRpcServiceLike;\n options?: {\n originHttpHeaderKey?: string;\n };\n}): JsonRpcMiddleware<JsonRpcParams, Json> {\n return createAsyncMiddleware(\n async (req: JsonRpcRequestWithOrigin<JsonRpcParams>, res) => {\n const headers =\n 'originHttpHeaderKey' in options &&\n options.originHttpHeaderKey !== undefined &&\n req.origin !== undefined\n ? { [options.originHttpHeaderKey]: req.origin }\n : {};\n\n const jsonRpcResponse = await rpcService.request(\n {\n id: req.id,\n jsonrpc: req.jsonrpc,\n method: req.method,\n params: req.params,\n },\n {\n headers,\n },\n );\n\n // NOTE: We intentionally do not test to see if `jsonRpcResponse.error` is\n // strictly a JSON-RPC error response as per\n // <https://www.jsonrpc.org/specification#error_object> to account for\n // Ganache returning error objects with extra properties such as `name`\n if ('error' in jsonRpcResponse) {\n throw rpcErrors.internal({\n data: jsonRpcResponse.error,\n });\n }\n\n // Discard the `id` and `jsonrpc` fields in the response body\n // (the JSON-RPC engine will fill those in)\n res.result = jsonRpcResponse.result;\n },\n );\n}\n"]}
|