@metamask-previews/transaction-controller 43.0.0-preview-009eef6b → 43.0.0-preview-bd04b248

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/dist/TransactionController.cjs +27 -3
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts +6 -0
  5. package/dist/TransactionController.d.cts.map +1 -1
  6. package/dist/TransactionController.d.mts +6 -0
  7. package/dist/TransactionController.d.mts.map +1 -1
  8. package/dist/TransactionController.mjs +25 -1
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/helpers/MethodDataHelper.cjs +22 -94
  11. package/dist/helpers/MethodDataHelper.cjs.map +1 -1
  12. package/dist/helpers/MethodDataHelper.d.cts +3 -2
  13. package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
  14. package/dist/helpers/MethodDataHelper.d.mts +3 -2
  15. package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
  16. package/dist/helpers/MethodDataHelper.mjs +22 -94
  17. package/dist/helpers/MethodDataHelper.mjs.map +1 -1
  18. package/dist/{utils/resimulate.cjs → helpers/ResimulateHelper.cjs} +99 -4
  19. package/dist/helpers/ResimulateHelper.cjs.map +1 -0
  20. package/dist/{utils/resimulate.d.cts → helpers/ResimulateHelper.d.cts} +13 -1
  21. package/dist/helpers/ResimulateHelper.d.cts.map +1 -0
  22. package/dist/{utils/resimulate.d.mts → helpers/ResimulateHelper.d.mts} +13 -1
  23. package/dist/helpers/ResimulateHelper.d.mts.map +1 -0
  24. package/dist/{utils/resimulate.mjs → helpers/ResimulateHelper.mjs} +99 -5
  25. package/dist/helpers/ResimulateHelper.mjs.map +1 -0
  26. package/dist/types.cjs.map +1 -1
  27. package/dist/types.d.cts +4 -0
  28. package/dist/types.d.cts.map +1 -1
  29. package/dist/types.d.mts +4 -0
  30. package/dist/types.d.mts.map +1 -1
  31. package/dist/types.mjs.map +1 -1
  32. package/package.json +2 -1
  33. package/dist/utils/resimulate.cjs.map +0 -1
  34. package/dist/utils/resimulate.d.cts.map +0 -1
  35. package/dist/utils/resimulate.d.mts.map +0 -1
  36. package/dist/utils/resimulate.mjs.map +0 -1
@@ -13,96 +13,28 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _MethodDataHelper_instances, _MethodDataHelper_getState, _MethodDataHelper_interfaceByNetworkClientId, _MethodDataHelper_mutex, _MethodDataHelper_interfaceLookup;
16
+ var _MethodDataHelper_instances, _MethodDataHelper_getProvider, _MethodDataHelper_getState, _MethodDataHelper_methodRegistryByNetworkClientId, _MethodDataHelper_mutex, _MethodDataHelper_registryLookup;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MethodDataHelper = void 0;
19
- const abi_1 = require("@ethersproject/abi");
20
19
  const utils_1 = require("@metamask/utils");
21
20
  const async_mutex_1 = require("async-mutex");
21
+ const eth_method_registry_1 = require("eth-method-registry");
22
22
  // This package purposefully relies on Node's EventEmitter module.
23
23
  // eslint-disable-next-line import-x/no-nodejs-modules
24
24
  const events_1 = __importDefault(require("events"));
25
25
  const logger_1 = require("../logger.cjs");
26
26
  const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'method-data');
27
- const methodRegistryAbi = [
28
- {
29
- constant: false,
30
- inputs: [{ name: '_new', type: 'address' }],
31
- name: 'setOwner',
32
- outputs: [],
33
- payable: false,
34
- type: 'function',
35
- },
36
- {
37
- constant: true,
38
- inputs: [],
39
- name: 'totalSignatures',
40
- outputs: [{ name: '', type: 'uint256' }],
41
- payable: false,
42
- type: 'function',
43
- },
44
- {
45
- constant: true,
46
- inputs: [],
47
- name: 'owner',
48
- outputs: [{ name: '', type: 'address' }],
49
- payable: false,
50
- type: 'function',
51
- },
52
- {
53
- constant: false,
54
- inputs: [],
55
- name: 'drain',
56
- outputs: [],
57
- payable: false,
58
- type: 'function',
59
- },
60
- {
61
- constant: true,
62
- inputs: [{ name: '', type: 'bytes4' }],
63
- name: 'entries',
64
- outputs: [{ name: '', type: 'string' }],
65
- payable: false,
66
- type: 'function',
67
- },
68
- {
69
- constant: false,
70
- inputs: [{ name: '_method', type: 'string' }],
71
- name: 'register',
72
- outputs: [{ name: '', type: 'bool' }],
73
- payable: false,
74
- type: 'function',
75
- },
76
- { inputs: [], type: 'constructor' },
77
- {
78
- anonymous: false,
79
- inputs: [
80
- { indexed: true, name: 'creator', type: 'address' },
81
- { indexed: true, name: 'signature', type: 'bytes4' },
82
- { indexed: false, name: 'method', type: 'string' },
83
- ],
84
- name: 'Registered',
85
- type: 'event',
86
- },
87
- {
88
- anonymous: false,
89
- inputs: [
90
- { indexed: true, name: 'old', type: 'address' },
91
- { indexed: true, name: 'current', type: 'address' },
92
- ],
93
- name: 'NewOwner',
94
- type: 'event',
95
- },
96
- ];
97
27
  class MethodDataHelper {
98
- constructor({ getState }) {
28
+ constructor({ getProvider, getState, }) {
99
29
  _MethodDataHelper_instances.add(this);
30
+ _MethodDataHelper_getProvider.set(this, void 0);
100
31
  _MethodDataHelper_getState.set(this, void 0);
101
- _MethodDataHelper_interfaceByNetworkClientId.set(this, void 0);
32
+ _MethodDataHelper_methodRegistryByNetworkClientId.set(this, void 0);
102
33
  _MethodDataHelper_mutex.set(this, new async_mutex_1.Mutex());
103
34
  this.hub = new events_1.default();
35
+ __classPrivateFieldSet(this, _MethodDataHelper_getProvider, getProvider, "f");
104
36
  __classPrivateFieldSet(this, _MethodDataHelper_getState, getState, "f");
105
- __classPrivateFieldSet(this, _MethodDataHelper_interfaceByNetworkClientId, new Map(), "f");
37
+ __classPrivateFieldSet(this, _MethodDataHelper_methodRegistryByNetworkClientId, new Map(), "f");
106
38
  }
107
39
  async lookup(fourBytePrefix, networkClientId) {
108
40
  log('lookup', fourBytePrefix, networkClientId);
@@ -113,13 +45,15 @@ class MethodDataHelper {
113
45
  log('Cached', cachedResult);
114
46
  return cachedResult;
115
47
  }
116
- let iface = __classPrivateFieldGet(this, _MethodDataHelper_interfaceByNetworkClientId, "f").get(networkClientId);
117
- if (!iface) {
118
- iface = new abi_1.Interface(methodRegistryAbi);
119
- __classPrivateFieldGet(this, _MethodDataHelper_interfaceByNetworkClientId, "f").set(networkClientId, iface);
120
- log('Created interface', networkClientId);
48
+ let registry = __classPrivateFieldGet(this, _MethodDataHelper_methodRegistryByNetworkClientId, "f").get(networkClientId);
49
+ if (!registry) {
50
+ const provider = __classPrivateFieldGet(this, _MethodDataHelper_getProvider, "f").call(this, networkClientId);
51
+ // @ts-expect-error Type in eth-method-registry is inappropriate and should be changed
52
+ registry = new eth_method_registry_1.MethodRegistry({ provider });
53
+ __classPrivateFieldGet(this, _MethodDataHelper_methodRegistryByNetworkClientId, "f").set(networkClientId, registry);
54
+ log('Created registry', networkClientId);
121
55
  }
122
- const methodData = await __classPrivateFieldGet(this, _MethodDataHelper_instances, "m", _MethodDataHelper_interfaceLookup).call(this, fourBytePrefix, iface);
56
+ const methodData = await __classPrivateFieldGet(this, _MethodDataHelper_instances, "m", _MethodDataHelper_registryLookup).call(this, fourBytePrefix, registry);
123
57
  log('Result', methodData);
124
58
  this.hub.emit('update', { fourBytePrefix, methodData });
125
59
  return methodData;
@@ -130,23 +64,17 @@ class MethodDataHelper {
130
64
  }
131
65
  }
132
66
  exports.MethodDataHelper = MethodDataHelper;
133
- _MethodDataHelper_getState = new WeakMap(), _MethodDataHelper_interfaceByNetworkClientId = new WeakMap(), _MethodDataHelper_mutex = new WeakMap(), _MethodDataHelper_instances = new WeakSet(), _MethodDataHelper_interfaceLookup = async function _MethodDataHelper_interfaceLookup(fourBytePrefix, iface) {
134
- try {
135
- const functionFragment = iface.getFunction(fourBytePrefix);
136
- return {
137
- registryMethod: functionFragment.format(),
138
- parsedRegistryMethod: {
139
- name: functionFragment.name,
140
- args: functionFragment.inputs.map(({ type }) => ({ type })),
141
- },
142
- };
143
- }
144
- catch {
145
- log('No method found or invalid signature', fourBytePrefix);
67
+ _MethodDataHelper_getProvider = new WeakMap(), _MethodDataHelper_getState = new WeakMap(), _MethodDataHelper_methodRegistryByNetworkClientId = new WeakMap(), _MethodDataHelper_mutex = new WeakMap(), _MethodDataHelper_instances = new WeakSet(), _MethodDataHelper_registryLookup = async function _MethodDataHelper_registryLookup(fourBytePrefix, methodRegistry) {
68
+ const registryMethod = await methodRegistry.lookup(fourBytePrefix);
69
+ if (!registryMethod) {
70
+ log('No method found', fourBytePrefix);
146
71
  return {
147
72
  registryMethod: '',
148
73
  parsedRegistryMethod: { name: undefined, args: undefined },
149
74
  };
150
75
  }
76
+ log('Parsing', registryMethod);
77
+ const parsedRegistryMethod = methodRegistry.parse(registryMethod);
78
+ return { registryMethod, parsedRegistryMethod };
151
79
  };
152
80
  //# sourceMappingURL=MethodDataHelper.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"MethodDataHelper.cjs","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,4CAA+C;AAE/C,2CAAqD;AACrD,6CAAoC;AACpC,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0CAA0C;AAG1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,aAAa,CAAC,CAAC;AAE7D,MAAM,iBAAiB,GAAG;IACxB;QACE,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC3C,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,UAAU;KACjB;IACD;QACE,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,CAAC,EAAE,IAAI,EAA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ientId } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type { MethodData } from '../TransactionController';\n\nconst log = createModuleLogger(projectLogger, 'method-data');\n\nconst methodRegistryAbi = [\n {\n constant: false,\n inputs: [{ name: '_new', type: 'address' }],\n name: 'setOwner',\n outputs: [],\n payable: false,\n type: 'function',\n },\n {\n constant: true,\n inputs: [],\n name: 'totalSignatures',\n outputs: [{ name: '', type: 'uint256' }],\n payable: false,\n type: 'function',\n },\n {\n constant: true,\n inputs: [],\n name: 'owner',\n outputs: [{ name: '', type: 'address' }],\n payable: false,\n type: 'function',\n },\n {\n constant: false,\n inputs: [],\n name: 'drain',\n outputs: [],\n payable: false,\n type: 'function',\n },\n {\n constant: true,\n inputs: [{ name: '', type: 'bytes4' }],\n name: 'entries',\n outputs: [{ name: '', type: 'string' }],\n payable: false,\n type: 'function',\n },\n {\n constant: false,\n inputs: [{ name: '_method', type: 'string' }],\n name: 'register',\n outputs: [{ name: '', type: 'bool' }],\n payable: false,\n type: 'function',\n },\n { inputs: [], type: 'constructor' },\n {\n anonymous: false,\n inputs: [\n { indexed: true, name: 'creator', type: 'address' },\n { indexed: true, name: 'signature', type: 'bytes4' },\n { indexed: false, name: 'method', type: 'string' },\n ],\n name: 'Registered',\n type: 'event',\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, name: 'old', type: 'address' },\n { indexed: true, name: 'current', type: 'address' },\n ],\n name: 'NewOwner',\n type: 'event',\n },\n];\n\nexport class MethodDataHelper {\n hub: EventEmitter;\n\n #getState: () => Record<string, MethodData>;\n\n #interfaceByNetworkClientId: Map<NetworkClientId, Interface>;\n\n #mutex = new Mutex();\n\n constructor({ getState }: { getState: () => Record<string, MethodData> }) {\n this.hub = new EventEmitter();\n\n this.#getState = getState;\n this.#interfaceByNetworkClientId = new Map();\n }\n\n async lookup(\n fourBytePrefix: string,\n networkClientId: NetworkClientId,\n ): Promise<MethodData> {\n log('lookup', fourBytePrefix, networkClientId);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const cachedResult = this.#getState()[fourBytePrefix];\n\n if (cachedResult) {\n log('Cached', cachedResult);\n return cachedResult;\n }\n\n let iface = this.#interfaceByNetworkClientId.get(networkClientId);\n\n if (!iface) {\n iface = new Interface(methodRegistryAbi);\n this.#interfaceByNetworkClientId.set(networkClientId, iface);\n log('Created interface', networkClientId);\n }\n\n const methodData = await this.#interfaceLookup(fourBytePrefix, iface);\n\n log('Result', methodData);\n\n this.hub.emit('update', { fourBytePrefix, methodData });\n\n return methodData;\n } finally {\n releaseLock();\n }\n }\n\n async #interfaceLookup(\n fourBytePrefix: string,\n iface: Interface,\n ): Promise<MethodData> {\n try {\n const functionFragment = iface.getFunction(fourBytePrefix);\n return {\n registryMethod: functionFragment.format(),\n parsedRegistryMethod: {\n name: functionFragment.name,\n args: functionFragment.inputs.map(({ type }) => ({ type })),\n },\n };\n } catch {\n log('No method found or invalid signature', fourBytePrefix);\n return {\n registryMethod: '',\n parsedRegistryMethod: { name: undefined, args: undefined },\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MethodDataHelper.cjs","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,2CAAqD;AACrD,6CAAoC;AACpC,6DAAqD;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAElC,0CAA0C;AAG1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,aAAa,CAAC,CAAC;AAE7D,MAAa,gBAAgB;IAW3B,YAAY,EACV,WAAW,EACX,QAAQ,GAIT;;QAdD,gDAA6D;QAE7D,6CAA4C;QAE5C,oEAAuE;QAEvE,kCAAS,IAAI,mBAAK,EAAE,EAAC;QASnB,IAAI,CAAC,GAAG,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AAE,UAAU,EAAE,CAAC,CAAC;YAExD,OAAO,UAAU,CAAC;SACnB;gBAAS;YACR,WAAW,EAAE,CAAC;SACf;IACH,CAAC;CAuBF;AAvFD,4CAuFC;uRArBC,KAAK,2CACH,cAAsB,EACtB,cAA8B;IAE9B,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEnE,IAAI,CAAC,cAAc,EAAE;QACnB,GAAG,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAEvC,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,oBAAoB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;SAC3D,CAAC;KACH;IAED,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAE/B,MAAM,oBAAoB,GAAG,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAElE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,CAAC;AAClD,CAAC","sourcesContent":["import type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport { MethodRegistry } from 'eth-method-registry';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type { MethodData } from '../TransactionController';\n\nconst log = createModuleLogger(projectLogger, 'method-data');\n\nexport class MethodDataHelper {\n hub: EventEmitter;\n\n #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n #getState: () => Record<string, MethodData>;\n\n #methodRegistryByNetworkClientId: Map<NetworkClientId, MethodRegistry>;\n\n #mutex = new Mutex();\n\n constructor({\n getProvider,\n getState,\n }: {\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getState: () => Record<string, MethodData>;\n }) {\n this.hub = new EventEmitter();\n\n this.#getProvider = getProvider;\n this.#getState = getState;\n this.#methodRegistryByNetworkClientId = new Map();\n }\n\n async lookup(\n fourBytePrefix: string,\n networkClientId: NetworkClientId,\n ): Promise<MethodData> {\n log('lookup', fourBytePrefix, networkClientId);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const cachedResult = this.#getState()[fourBytePrefix];\n\n if (cachedResult) {\n log('Cached', cachedResult);\n return cachedResult;\n }\n\n let registry = this.#methodRegistryByNetworkClientId.get(networkClientId);\n\n if (!registry) {\n const provider = this.#getProvider(networkClientId);\n\n // @ts-expect-error Type in eth-method-registry is inappropriate and should be changed\n registry = new MethodRegistry({ provider });\n\n this.#methodRegistryByNetworkClientId.set(networkClientId, registry);\n\n log('Created registry', networkClientId);\n }\n\n const methodData = await this.#registryLookup(fourBytePrefix, registry);\n\n log('Result', methodData);\n\n this.hub.emit('update', { fourBytePrefix, methodData });\n\n return methodData;\n } finally {\n releaseLock();\n }\n }\n\n async #registryLookup(\n fourBytePrefix: string,\n methodRegistry: MethodRegistry,\n ): Promise<MethodData> {\n const registryMethod = await methodRegistry.lookup(fourBytePrefix);\n\n if (!registryMethod) {\n log('No method found', fourBytePrefix);\n\n return {\n registryMethod: '',\n parsedRegistryMethod: { name: undefined, args: undefined },\n };\n }\n\n log('Parsing', registryMethod);\n\n const parsedRegistryMethod = methodRegistry.parse(registryMethod);\n\n return { registryMethod, parsedRegistryMethod };\n }\n}\n"]}
@@ -1,11 +1,12 @@
1
1
  /// <reference types="node" />
2
- import type { NetworkClientId } from "@metamask/network-controller";
2
+ import type { NetworkClientId, Provider } from "@metamask/network-controller";
3
3
  import EventEmitter from "events";
4
4
  import type { MethodData } from "../TransactionController.cjs";
5
5
  export declare class MethodDataHelper {
6
6
  #private;
7
7
  hub: EventEmitter;
8
- constructor({ getState }: {
8
+ constructor({ getProvider, getState, }: {
9
+ getProvider: (networkClientId: NetworkClientId) => Provider;
9
10
  getState: () => Record<string, MethodData>;
10
11
  });
11
12
  lookup(fourBytePrefix: string, networkClientId: NetworkClientId): Promise<MethodData>;
@@ -1 +1 @@
1
- {"version":3,"file":"MethodDataHelper.d.cts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAKpE,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,qCAAiC;AA2E3D,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAQN,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;KAAE;IAOlE,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CAsDvB"}
1
+ {"version":3,"file":"MethodDataHelper.d.cts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAM9E,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,qCAAiC;AAI3D,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAUN,EACV,WAAW,EACX,QAAQ,GACT,EAAE;QACD,WAAW,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,QAAQ,CAAC;QAC5D,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC5C;IAQK,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CA2DvB"}
@@ -1,11 +1,12 @@
1
1
  /// <reference types="node" />
2
- import type { NetworkClientId } from "@metamask/network-controller";
2
+ import type { NetworkClientId, Provider } from "@metamask/network-controller";
3
3
  import EventEmitter from "events";
4
4
  import type { MethodData } from "../TransactionController.mjs";
5
5
  export declare class MethodDataHelper {
6
6
  #private;
7
7
  hub: EventEmitter;
8
- constructor({ getState }: {
8
+ constructor({ getProvider, getState, }: {
9
+ getProvider: (networkClientId: NetworkClientId) => Provider;
9
10
  getState: () => Record<string, MethodData>;
10
11
  });
11
12
  lookup(fourBytePrefix: string, networkClientId: NetworkClientId): Promise<MethodData>;
@@ -1 +1 @@
1
- {"version":3,"file":"MethodDataHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAKpE,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,qCAAiC;AA2E3D,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAQN,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;KAAE;IAOlE,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CAsDvB"}
1
+ {"version":3,"file":"MethodDataHelper.d.mts","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,qCAAqC;AAM9E,OAAO,YAAY,eAAe;AAGlC,OAAO,KAAK,EAAE,UAAU,EAAE,qCAAiC;AAI3D,qBAAa,gBAAgB;;IAC3B,GAAG,EAAE,YAAY,CAAC;gBAUN,EACV,WAAW,EACX,QAAQ,GACT,EAAE;QACD,WAAW,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,QAAQ,CAAC;QAC5D,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC5C;IAQK,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,UAAU,CAAC;CA2DvB"}
@@ -9,94 +9,26 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _MethodDataHelper_instances, _MethodDataHelper_getState, _MethodDataHelper_interfaceByNetworkClientId, _MethodDataHelper_mutex, _MethodDataHelper_interfaceLookup;
13
- import { Interface } from "@ethersproject/abi";
12
+ var _MethodDataHelper_instances, _MethodDataHelper_getProvider, _MethodDataHelper_getState, _MethodDataHelper_methodRegistryByNetworkClientId, _MethodDataHelper_mutex, _MethodDataHelper_registryLookup;
14
13
  import { createModuleLogger } from "@metamask/utils";
15
14
  import { Mutex } from "async-mutex";
15
+ import { MethodRegistry } from "eth-method-registry";
16
16
  // This package purposefully relies on Node's EventEmitter module.
17
17
  // eslint-disable-next-line import-x/no-nodejs-modules
18
18
  import EventEmitter from "events";
19
19
  import { projectLogger } from "../logger.mjs";
20
20
  const log = createModuleLogger(projectLogger, 'method-data');
21
- const methodRegistryAbi = [
22
- {
23
- constant: false,
24
- inputs: [{ name: '_new', type: 'address' }],
25
- name: 'setOwner',
26
- outputs: [],
27
- payable: false,
28
- type: 'function',
29
- },
30
- {
31
- constant: true,
32
- inputs: [],
33
- name: 'totalSignatures',
34
- outputs: [{ name: '', type: 'uint256' }],
35
- payable: false,
36
- type: 'function',
37
- },
38
- {
39
- constant: true,
40
- inputs: [],
41
- name: 'owner',
42
- outputs: [{ name: '', type: 'address' }],
43
- payable: false,
44
- type: 'function',
45
- },
46
- {
47
- constant: false,
48
- inputs: [],
49
- name: 'drain',
50
- outputs: [],
51
- payable: false,
52
- type: 'function',
53
- },
54
- {
55
- constant: true,
56
- inputs: [{ name: '', type: 'bytes4' }],
57
- name: 'entries',
58
- outputs: [{ name: '', type: 'string' }],
59
- payable: false,
60
- type: 'function',
61
- },
62
- {
63
- constant: false,
64
- inputs: [{ name: '_method', type: 'string' }],
65
- name: 'register',
66
- outputs: [{ name: '', type: 'bool' }],
67
- payable: false,
68
- type: 'function',
69
- },
70
- { inputs: [], type: 'constructor' },
71
- {
72
- anonymous: false,
73
- inputs: [
74
- { indexed: true, name: 'creator', type: 'address' },
75
- { indexed: true, name: 'signature', type: 'bytes4' },
76
- { indexed: false, name: 'method', type: 'string' },
77
- ],
78
- name: 'Registered',
79
- type: 'event',
80
- },
81
- {
82
- anonymous: false,
83
- inputs: [
84
- { indexed: true, name: 'old', type: 'address' },
85
- { indexed: true, name: 'current', type: 'address' },
86
- ],
87
- name: 'NewOwner',
88
- type: 'event',
89
- },
90
- ];
91
21
  export class MethodDataHelper {
92
- constructor({ getState }) {
22
+ constructor({ getProvider, getState, }) {
93
23
  _MethodDataHelper_instances.add(this);
24
+ _MethodDataHelper_getProvider.set(this, void 0);
94
25
  _MethodDataHelper_getState.set(this, void 0);
95
- _MethodDataHelper_interfaceByNetworkClientId.set(this, void 0);
26
+ _MethodDataHelper_methodRegistryByNetworkClientId.set(this, void 0);
96
27
  _MethodDataHelper_mutex.set(this, new Mutex());
97
28
  this.hub = new EventEmitter();
29
+ __classPrivateFieldSet(this, _MethodDataHelper_getProvider, getProvider, "f");
98
30
  __classPrivateFieldSet(this, _MethodDataHelper_getState, getState, "f");
99
- __classPrivateFieldSet(this, _MethodDataHelper_interfaceByNetworkClientId, new Map(), "f");
31
+ __classPrivateFieldSet(this, _MethodDataHelper_methodRegistryByNetworkClientId, new Map(), "f");
100
32
  }
101
33
  async lookup(fourBytePrefix, networkClientId) {
102
34
  log('lookup', fourBytePrefix, networkClientId);
@@ -107,13 +39,15 @@ export class MethodDataHelper {
107
39
  log('Cached', cachedResult);
108
40
  return cachedResult;
109
41
  }
110
- let iface = __classPrivateFieldGet(this, _MethodDataHelper_interfaceByNetworkClientId, "f").get(networkClientId);
111
- if (!iface) {
112
- iface = new Interface(methodRegistryAbi);
113
- __classPrivateFieldGet(this, _MethodDataHelper_interfaceByNetworkClientId, "f").set(networkClientId, iface);
114
- log('Created interface', networkClientId);
42
+ let registry = __classPrivateFieldGet(this, _MethodDataHelper_methodRegistryByNetworkClientId, "f").get(networkClientId);
43
+ if (!registry) {
44
+ const provider = __classPrivateFieldGet(this, _MethodDataHelper_getProvider, "f").call(this, networkClientId);
45
+ // @ts-expect-error Type in eth-method-registry is inappropriate and should be changed
46
+ registry = new MethodRegistry({ provider });
47
+ __classPrivateFieldGet(this, _MethodDataHelper_methodRegistryByNetworkClientId, "f").set(networkClientId, registry);
48
+ log('Created registry', networkClientId);
115
49
  }
116
- const methodData = await __classPrivateFieldGet(this, _MethodDataHelper_instances, "m", _MethodDataHelper_interfaceLookup).call(this, fourBytePrefix, iface);
50
+ const methodData = await __classPrivateFieldGet(this, _MethodDataHelper_instances, "m", _MethodDataHelper_registryLookup).call(this, fourBytePrefix, registry);
117
51
  log('Result', methodData);
118
52
  this.hub.emit('update', { fourBytePrefix, methodData });
119
53
  return methodData;
@@ -123,23 +57,17 @@ export class MethodDataHelper {
123
57
  }
124
58
  }
125
59
  }
126
- _MethodDataHelper_getState = new WeakMap(), _MethodDataHelper_interfaceByNetworkClientId = new WeakMap(), _MethodDataHelper_mutex = new WeakMap(), _MethodDataHelper_instances = new WeakSet(), _MethodDataHelper_interfaceLookup = async function _MethodDataHelper_interfaceLookup(fourBytePrefix, iface) {
127
- try {
128
- const functionFragment = iface.getFunction(fourBytePrefix);
129
- return {
130
- registryMethod: functionFragment.format(),
131
- parsedRegistryMethod: {
132
- name: functionFragment.name,
133
- args: functionFragment.inputs.map(({ type }) => ({ type })),
134
- },
135
- };
136
- }
137
- catch {
138
- log('No method found or invalid signature', fourBytePrefix);
60
+ _MethodDataHelper_getProvider = new WeakMap(), _MethodDataHelper_getState = new WeakMap(), _MethodDataHelper_methodRegistryByNetworkClientId = new WeakMap(), _MethodDataHelper_mutex = new WeakMap(), _MethodDataHelper_instances = new WeakSet(), _MethodDataHelper_registryLookup = async function _MethodDataHelper_registryLookup(fourBytePrefix, methodRegistry) {
61
+ const registryMethod = await methodRegistry.lookup(fourBytePrefix);
62
+ if (!registryMethod) {
63
+ log('No method found', fourBytePrefix);
139
64
  return {
140
65
  registryMethod: '',
141
66
  parsedRegistryMethod: { name: undefined, args: undefined },
142
67
  };
143
68
  }
69
+ log('Parsing', registryMethod);
70
+ const parsedRegistryMethod = methodRegistry.parse(registryMethod);
71
+ return { registryMethod, parsedRegistryMethod };
144
72
  };
145
73
  //# sourceMappingURL=MethodDataHelper.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"MethodDataHelper.mjs","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAE/C,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,KAAK,EAAE,oBAAoB;AACpC,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;AAElC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAG1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE7D,MAAM,iBAAiB,GAAG;IACxB;QACE,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC3C,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,UAAU;KACjB;IACD;QACE,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACxC,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,UAAU;KACjB;IACD;QACE,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE;QACV,IAAI,EAAE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AE,KAAK,CAAC,CAAC;gBAC7D,GAAG,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;aAC3C;YAED,MAAM,UAAU,GAAG,MAAM,uBAAA,IAAI,sEAAiB,MAArB,IAAI,EAAkB,cAAc,EAAE,KAAK,CAAC,CAAC;YAEtE,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAE1B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAC;YAExD,OAAO,UAAU,CAAC;SACnB;gBAAS;YACR,WAAW,EAAE,CAAC;SACf;IACH,CAAC;CAuBF;oOArBC,KAAK,4CACH,cAAsB,EACtB,KAAgB;IAEhB,IAAI;QACF,MAAM,gBAAgB,GAAG,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAC3D,OAAO;YACL,cAAc,EAAE,gBAAgB,CAAC,MAAM,EAAE;YACzC,oBAAoB,EAAE;gBACpB,IAAI,EAAE,gBAAgB,CAAC,IAAI;gBAC3B,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;aAC5D;SACF,CAAC;KACH;IAAC,MAAM;QACN,GAAG,CAAC,sCAAsC,EAAE,cAAc,CAAC,CAAC;QAC5D,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,oBAAoB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;SAC3D,CAAC;KACH;AACH,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type { MethodData } from '../TransactionController';\n\nconst log = createModuleLogger(projectLogger, 'method-data');\n\nconst methodRegistryAbi = [\n {\n constant: false,\n inputs: [{ name: '_new', type: 'address' }],\n name: 'setOwner',\n outputs: [],\n payable: false,\n type: 'function',\n },\n {\n constant: true,\n inputs: [],\n name: 'totalSignatures',\n outputs: [{ name: '', type: 'uint256' }],\n payable: false,\n type: 'function',\n },\n {\n constant: true,\n inputs: [],\n name: 'owner',\n outputs: [{ name: '', type: 'address' }],\n payable: false,\n type: 'function',\n },\n {\n constant: false,\n inputs: [],\n name: 'drain',\n outputs: [],\n payable: false,\n type: 'function',\n },\n {\n constant: true,\n inputs: [{ name: '', type: 'bytes4' }],\n name: 'entries',\n outputs: [{ name: '', type: 'string' }],\n payable: false,\n type: 'function',\n },\n {\n constant: false,\n inputs: [{ name: '_method', type: 'string' }],\n name: 'register',\n outputs: [{ name: '', type: 'bool' }],\n payable: false,\n type: 'function',\n },\n { inputs: [], type: 'constructor' },\n {\n anonymous: false,\n inputs: [\n { indexed: true, name: 'creator', type: 'address' },\n { indexed: true, name: 'signature', type: 'bytes4' },\n { indexed: false, name: 'method', type: 'string' },\n ],\n name: 'Registered',\n type: 'event',\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, name: 'old', type: 'address' },\n { indexed: true, name: 'current', type: 'address' },\n ],\n name: 'NewOwner',\n type: 'event',\n },\n];\n\nexport class MethodDataHelper {\n hub: EventEmitter;\n\n #getState: () => Record<string, MethodData>;\n\n #interfaceByNetworkClientId: Map<NetworkClientId, Interface>;\n\n #mutex = new Mutex();\n\n constructor({ getState }: { getState: () => Record<string, MethodData> }) {\n this.hub = new EventEmitter();\n\n this.#getState = getState;\n this.#interfaceByNetworkClientId = new Map();\n }\n\n async lookup(\n fourBytePrefix: string,\n networkClientId: NetworkClientId,\n ): Promise<MethodData> {\n log('lookup', fourBytePrefix, networkClientId);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const cachedResult = this.#getState()[fourBytePrefix];\n\n if (cachedResult) {\n log('Cached', cachedResult);\n return cachedResult;\n }\n\n let iface = this.#interfaceByNetworkClientId.get(networkClientId);\n\n if (!iface) {\n iface = new Interface(methodRegistryAbi);\n this.#interfaceByNetworkClientId.set(networkClientId, iface);\n log('Created interface', networkClientId);\n }\n\n const methodData = await this.#interfaceLookup(fourBytePrefix, iface);\n\n log('Result', methodData);\n\n this.hub.emit('update', { fourBytePrefix, methodData });\n\n return methodData;\n } finally {\n releaseLock();\n }\n }\n\n async #interfaceLookup(\n fourBytePrefix: string,\n iface: Interface,\n ): Promise<MethodData> {\n try {\n const functionFragment = iface.getFunction(fourBytePrefix);\n return {\n registryMethod: functionFragment.format(),\n parsedRegistryMethod: {\n name: functionFragment.name,\n args: functionFragment.inputs.map(({ type }) => ({ type })),\n },\n };\n } catch {\n log('No method found or invalid signature', fourBytePrefix);\n return {\n registryMethod: '',\n parsedRegistryMethod: { name: undefined, args: undefined },\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MethodDataHelper.mjs","sourceRoot":"","sources":["../../src/helpers/MethodDataHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,KAAK,EAAE,oBAAoB;AACpC,OAAO,EAAE,cAAc,EAAE,4BAA4B;AACrD,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;AAElC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAG1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE7D,MAAM,OAAO,gBAAgB;IAW3B,YAAY,EACV,WAAW,EACX,QAAQ,GAIT;;QAdD,gDAA6D;QAE7D,6CAA4C;QAE5C,oEAAuE;QAEvE,kCAAS,IAAI,KAAK,EAAE,EAAC;QASnB,IAAI,CAAC,GAAG,GAAG,IAAI,YAAY,EAAE,CAAC;QAE9B,uBAAA,IAAI,iCAAgB,WAAW,MAAA,CAAC;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AE,CAAC;SACf;IACH,CAAC;CAuBF;uRArBC,KAAK,2CACH,cAAsB,EACtB,cAA8B;IAE9B,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEnE,IAAI,CAAC,cAAc,EAAE;QACnB,GAAG,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAEvC,OAAO;YACL,cAAc,EAAE,EAAE;YAClB,oBAAoB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;SAC3D,CAAC;KACH;IAED,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAE/B,MAAM,oBAAoB,GAAG,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAElE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,CAAC;AAClD,CAAC","sourcesContent":["import type { NetworkClientId, Provider } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport { MethodRegistry } from 'eth-method-registry';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { projectLogger } from '../logger';\nimport type { MethodData } from '../TransactionController';\n\nconst log = createModuleLogger(projectLogger, 'method-data');\n\nexport class MethodDataHelper {\n hub: EventEmitter;\n\n #getProvider: (networkClientId: NetworkClientId) => Provider;\n\n #getState: () => Record<string, MethodData>;\n\n #methodRegistryByNetworkClientId: Map<NetworkClientId, MethodRegistry>;\n\n #mutex = new Mutex();\n\n constructor({\n getProvider,\n getState,\n }: {\n getProvider: (networkClientId: NetworkClientId) => Provider;\n getState: () => Record<string, MethodData>;\n }) {\n this.hub = new EventEmitter();\n\n this.#getProvider = getProvider;\n this.#getState = getState;\n this.#methodRegistryByNetworkClientId = new Map();\n }\n\n async lookup(\n fourBytePrefix: string,\n networkClientId: NetworkClientId,\n ): Promise<MethodData> {\n log('lookup', fourBytePrefix, networkClientId);\n\n const releaseLock = await this.#mutex.acquire();\n\n try {\n const cachedResult = this.#getState()[fourBytePrefix];\n\n if (cachedResult) {\n log('Cached', cachedResult);\n return cachedResult;\n }\n\n let registry = this.#methodRegistryByNetworkClientId.get(networkClientId);\n\n if (!registry) {\n const provider = this.#getProvider(networkClientId);\n\n // @ts-expect-error Type in eth-method-registry is inappropriate and should be changed\n registry = new MethodRegistry({ provider });\n\n this.#methodRegistryByNetworkClientId.set(networkClientId, registry);\n\n log('Created registry', networkClientId);\n }\n\n const methodData = await this.#registryLookup(fourBytePrefix, registry);\n\n log('Result', methodData);\n\n this.hub.emit('update', { fourBytePrefix, methodData });\n\n return methodData;\n } finally {\n releaseLock();\n }\n }\n\n async #registryLookup(\n fourBytePrefix: string,\n methodRegistry: MethodRegistry,\n ): Promise<MethodData> {\n const registryMethod = await methodRegistry.lookup(fourBytePrefix);\n\n if (!registryMethod) {\n log('No method found', fourBytePrefix);\n\n return {\n registryMethod: '',\n parsedRegistryMethod: { name: undefined, args: undefined },\n };\n }\n\n log('Parsing', registryMethod);\n\n const parsedRegistryMethod = methodRegistry.parse(registryMethod);\n\n return { registryMethod, parsedRegistryMethod };\n }\n}\n"]}
@@ -1,18 +1,107 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _ResimulateHelper_instances, _ResimulateHelper_activeResimulations, _ResimulateHelper_intervalIds, _ResimulateHelper_getTransactions, _ResimulateHelper_updateSimulationData, _ResimulateHelper_start, _ResimulateHelper_stop, _ResimulateHelper_removeListener, _ResimulateHelper_getUnapprovedTransactions;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasSimulationDataChanged = exports.shouldResimulate = exports.BLOCK_TIME_ADDITIONAL_SECONDS = exports.VALUE_COMPARISON_PERCENT_THRESHOLD = exports.BLOCKAID_RESULT_TYPE_MALICIOUS = exports.RESIMULATE_PARAMS = void 0;
15
+ exports.hasSimulationDataChanged = exports.shouldResimulate = exports.ResimulateHelper = exports.RESIMULATE_INTERVAL_MS = exports.BLOCK_TIME_ADDITIONAL_SECONDS = exports.VALUE_COMPARISON_PERCENT_THRESHOLD = exports.BLOCKAID_RESULT_TYPE_MALICIOUS = exports.RESIMULATE_PARAMS = void 0;
4
16
  const utils_1 = require("@metamask/utils");
5
17
  const bn_js_1 = require("bn.js");
6
18
  const lodash_1 = require("lodash");
7
19
  const logger_1 = require("../logger.cjs");
8
- const utils_2 = require("./utils.cjs");
9
- const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'resimulate');
20
+ const types_1 = require("../types.cjs");
21
+ const utils_2 = require("../utils/utils.cjs");
22
+ const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'resimulate-helper');
10
23
  exports.RESIMULATE_PARAMS = ['to', 'value', 'data'];
11
24
  exports.BLOCKAID_RESULT_TYPE_MALICIOUS = 'Malicious';
12
25
  exports.VALUE_COMPARISON_PERCENT_THRESHOLD = 5;
13
26
  exports.BLOCK_TIME_ADDITIONAL_SECONDS = 60;
27
+ exports.RESIMULATE_INTERVAL_MS = 3000;
28
+ class ResimulateHelper {
29
+ constructor({ getTransactions, updateSimulationData, onStateChange, }) {
30
+ _ResimulateHelper_instances.add(this);
31
+ // Map of transactionId <=> isActive
32
+ _ResimulateHelper_activeResimulations.set(this, new Map());
33
+ // Map of transactionId <=> intervalId
34
+ _ResimulateHelper_intervalIds.set(this, new Map());
35
+ _ResimulateHelper_getTransactions.set(this, void 0);
36
+ _ResimulateHelper_updateSimulationData.set(this, void 0);
37
+ __classPrivateFieldSet(this, _ResimulateHelper_getTransactions, getTransactions, "f");
38
+ __classPrivateFieldSet(this, _ResimulateHelper_updateSimulationData, updateSimulationData, "f");
39
+ onStateChange(() => {
40
+ const unapprovedTransactions = __classPrivateFieldGet(this, _ResimulateHelper_instances, "m", _ResimulateHelper_getUnapprovedTransactions).call(this);
41
+ const unapprovedTransactionIds = new Set(unapprovedTransactions.map((tx) => tx.id));
42
+ // Start or stop resimulation based on the current isFocused state
43
+ unapprovedTransactions.forEach((transactionMeta) => {
44
+ if (transactionMeta.isFocused) {
45
+ __classPrivateFieldGet(this, _ResimulateHelper_instances, "m", _ResimulateHelper_start).call(this, transactionMeta);
46
+ }
47
+ else {
48
+ __classPrivateFieldGet(this, _ResimulateHelper_instances, "m", _ResimulateHelper_stop).call(this, transactionMeta);
49
+ }
50
+ });
51
+ // Force stop any running active resimulation that are no longer unapproved transactions list
52
+ __classPrivateFieldGet(this, _ResimulateHelper_activeResimulations, "f").forEach((isActive, transactionId) => {
53
+ if (isActive && !unapprovedTransactionIds.has(transactionId)) {
54
+ __classPrivateFieldGet(this, _ResimulateHelper_instances, "m", _ResimulateHelper_stop).call(this, {
55
+ id: transactionId,
56
+ // Forcing this to false to ensure the resimulation is stopped
57
+ isFocused: false,
58
+ });
59
+ }
60
+ });
61
+ });
62
+ }
63
+ }
64
+ exports.ResimulateHelper = ResimulateHelper;
65
+ _ResimulateHelper_activeResimulations = new WeakMap(), _ResimulateHelper_intervalIds = new WeakMap(), _ResimulateHelper_getTransactions = new WeakMap(), _ResimulateHelper_updateSimulationData = new WeakMap(), _ResimulateHelper_instances = new WeakSet(), _ResimulateHelper_start = function _ResimulateHelper_start(transactionMeta) {
66
+ const { id: transactionId } = transactionMeta;
67
+ const isActive = __classPrivateFieldGet(this, _ResimulateHelper_activeResimulations, "f").get(transactionId);
68
+ if (!transactionMeta.isFocused || isActive) {
69
+ return;
70
+ }
71
+ const listener = async () => {
72
+ try {
73
+ __classPrivateFieldGet(this, _ResimulateHelper_updateSimulationData, "f").call(this, transactionMeta);
74
+ }
75
+ catch (error) {
76
+ /* istanbul ignore next */
77
+ log('Error during transaction resimulation', error);
78
+ }
79
+ };
80
+ const intervalId = setInterval(listener, exports.RESIMULATE_INTERVAL_MS);
81
+ __classPrivateFieldGet(this, _ResimulateHelper_intervalIds, "f").set(transactionId, intervalId);
82
+ __classPrivateFieldGet(this, _ResimulateHelper_activeResimulations, "f").set(transactionId, true);
83
+ log(`Started resimulating transaction ${transactionId} every 3 seconds`);
84
+ }, _ResimulateHelper_stop = function _ResimulateHelper_stop(transactionMeta) {
85
+ const { id: transactionId } = transactionMeta;
86
+ const isActive = __classPrivateFieldGet(this, _ResimulateHelper_activeResimulations, "f").get(transactionId);
87
+ if (transactionMeta.isFocused || !isActive) {
88
+ return;
89
+ }
90
+ __classPrivateFieldGet(this, _ResimulateHelper_instances, "m", _ResimulateHelper_removeListener).call(this, transactionId);
91
+ log(`Stopped resimulating transaction ${transactionId} every 3 seconds`);
92
+ }, _ResimulateHelper_removeListener = function _ResimulateHelper_removeListener(id) {
93
+ const intervalId = __classPrivateFieldGet(this, _ResimulateHelper_intervalIds, "f").get(id);
94
+ if (intervalId) {
95
+ clearInterval(intervalId);
96
+ __classPrivateFieldGet(this, _ResimulateHelper_intervalIds, "f").delete(id);
97
+ }
98
+ __classPrivateFieldGet(this, _ResimulateHelper_activeResimulations, "f").delete(id);
99
+ }, _ResimulateHelper_getUnapprovedTransactions = function _ResimulateHelper_getUnapprovedTransactions() {
100
+ return __classPrivateFieldGet(this, _ResimulateHelper_getTransactions, "f").call(this).filter((tx) => tx.status === types_1.TransactionStatus.unapproved);
101
+ };
14
102
  /**
15
103
  * Determine if a transaction should be resimulated.
104
+ *
16
105
  * @param originalTransactionMeta - The original transaction metadata.
17
106
  * @param newTransactionMeta - The new transaction metadata.
18
107
  * @returns Whether the transaction should be resimulated.
@@ -45,6 +134,7 @@ function shouldResimulate(originalTransactionMeta, newTransactionMeta) {
45
134
  exports.shouldResimulate = shouldResimulate;
46
135
  /**
47
136
  * Determine if the simulation data has changed.
137
+ *
48
138
  * @param originalSimulationData - The original simulation data.
49
139
  * @param newSimulationData - The new simulation data.
50
140
  * @returns Whether the simulation data has changed.
@@ -84,6 +174,7 @@ function hasSimulationDataChanged(originalSimulationData, newSimulationData) {
84
174
  exports.hasSimulationDataChanged = hasSimulationDataChanged;
85
175
  /**
86
176
  * Determine if the transaction parameters have been updated.
177
+ *
87
178
  * @param originalTransactionMeta - The original transaction metadata.
88
179
  * @param newTransactionMeta - The new transaction metadata.
89
180
  * @returns Whether the transaction parameters have been updated.
@@ -106,6 +197,7 @@ function isParametersUpdated(originalTransactionMeta, newTransactionMeta) {
106
197
  }
107
198
  /**
108
199
  * Determine if a transaction has a new security alert.
200
+ *
109
201
  * @param originalTransactionMeta - The original transaction metadata.
110
202
  * @param newTransactionMeta - The new transaction metadata.
111
203
  * @returns Whether the transaction has a new security alert.
@@ -125,6 +217,7 @@ function hasNewSecurityAlert(originalTransactionMeta, newTransactionMeta) {
125
217
  }
126
218
  /**
127
219
  * Determine if a transaction has a value and simulation native balance mismatch.
220
+ *
128
221
  * @param originalTransactionMeta - The original transaction metadata.
129
222
  * @param newTransactionMeta - The new transaction metadata.
130
223
  * @returns Whether the transaction has a value and simulation native balance mismatch.
@@ -142,6 +235,7 @@ function hasValueAndNativeBalanceMismatch(originalTransactionMeta, newTransactio
142
235
  }
143
236
  /**
144
237
  * Determine if a balance change has been updated.
238
+ *
145
239
  * @param originalBalanceChange - The original balance change.
146
240
  * @param newBalanceChange - The new balance change.
147
241
  * @returns Whether the balance change has been updated.
@@ -151,6 +245,7 @@ function isBalanceChangeUpdated(originalBalanceChange, newBalanceChange) {
151
245
  }
152
246
  /**
153
247
  * Determine if the percentage change between two values is within a threshold.
248
+ *
154
249
  * @param originalValue - The original value.
155
250
  * @param newValue - The new value.
156
251
  * @param originalNegative - Whether the original value is negative.
@@ -169,4 +264,4 @@ function percentageChangeWithinThreshold(originalValue, newValue, originalNegati
169
264
  return ((0, utils_2.getPercentageChange)(originalValueBN, newValueBN) <=
170
265
  exports.VALUE_COMPARISON_PERCENT_THRESHOLD);
171
266
  }
172
- //# sourceMappingURL=resimulate.cjs.map
267
+ //# sourceMappingURL=ResimulateHelper.cjs.map