Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow type of provider argument #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@ethersproject/providers": "^5.7.2",
"@metamask/eth-json-rpc-provider": "^2.3.0",
"async-mutex": "^0.3.1"
},
"devDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions src/NonceTracker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'assert';
import { Mutex } from 'async-mutex';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
Copy link
Contributor

@legobeat legobeat Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be viable to have this type broken out to a separate package, if not either inlined or in .d.ts file here? Looking at the lockfile diff, it's quite a lot of transitive dependencies pulled in for a single type-declaration, which won't even be present at runtime...

Copy link
Contributor

@legobeat legobeat Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had this thought which may or may not be relevant here: what if type-only imports went back to devDependencies, but with the addition of a build/bundle-step which ensures that any types used by them are included in published packages in d.ts declarations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I didn't see this comment before.

Because @metamask/eth-json-rpc-provider shows up in the type declaration, it can't be in devDependencies, it has to be in dependencies instead. This ensures that TypeScript consumers automatically get the type definitions for this import and do not have to add it themselves.

I know that we've discussed splitting this type off before. I am not opposed to that, I am just unsure where. Also, I suspect that most of these transitive dependencies are coming from @metamask/utils. I will open a discussion in chat for this since I feel like it might be easier to talk there.


// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const { Web3Provider } = require('@ethersproject/providers');
Expand All @@ -15,7 +16,7 @@ const BlockTracker = require('eth-block-tracker');
* whose status is `confirmed`
*/
export interface NonceTrackerOptions {
provider: Record<string, unknown>;
provider: SafeEventEmitterProvider;
blockTracker: typeof BlockTracker;
getPendingTransactions: (address: string) => Transaction[];
getConfirmedTransactions: (address: string) => Transaction[];
Expand Down Expand Up @@ -90,8 +91,6 @@ export interface Transaction {
}

export class NonceTracker {
private provider: Record<string, unknown>;

private blockTracker: typeof BlockTracker;

private web3: typeof Web3Provider;
Expand All @@ -103,7 +102,6 @@ export class NonceTracker {
private lockMap: Record<string, Mutex>;

constructor(opts: NonceTrackerOptions) {
this.provider = opts.provider;
this.blockTracker = opts.blockTracker;
this.web3 = new Web3Provider(opts.provider);
this.getPendingTransactions = opts.getPendingTransactions;
Expand Down
216 changes: 215 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,48 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/common@npm:^3.2.0":
version: 3.2.0
resolution: "@ethereumjs/common@npm:3.2.0"
dependencies:
"@ethereumjs/util": ^8.1.0
crc-32: ^1.2.0
checksum: cb9cc11f5c868cb577ba611cebf55046e509218bbb89b47ccce010776dafe8256d70f8f43fab238aec74cf71f62601cd5842bc03a83261200802de365732a14b
languageName: node
linkType: hard

"@ethereumjs/rlp@npm:^4.0.1":
version: 4.0.1
resolution: "@ethereumjs/rlp@npm:4.0.1"
bin:
rlp: bin/rlp
checksum: 30db19c78faa2b6ff27275ab767646929207bb207f903f09eb3e4c273ce2738b45f3c82169ddacd67468b4f063d8d96035f2bf36f02b6b7e4d928eefe2e3ecbc
languageName: node
linkType: hard

"@ethereumjs/tx@npm:^4.2.0":
version: 4.2.0
resolution: "@ethereumjs/tx@npm:4.2.0"
dependencies:
"@ethereumjs/common": ^3.2.0
"@ethereumjs/rlp": ^4.0.1
"@ethereumjs/util": ^8.1.0
ethereum-cryptography: ^2.0.0
checksum: 87a3f5f2452cfbf6712f8847525a80c213210ed453c211c793c5df801fe35ecef28bae17fadd222fcbdd94277478a47e52d2b916a90a6b30cda21f1e0cdaee42
languageName: node
linkType: hard

"@ethereumjs/util@npm:^8.1.0":
version: 8.1.0
resolution: "@ethereumjs/util@npm:8.1.0"
dependencies:
"@ethereumjs/rlp": ^4.0.1
ethereum-cryptography: ^2.0.0
micro-ftch: ^0.3.1
checksum: 9ae5dee8f12b0faf81cd83f06a41560e79b0ba96a48262771d897a510ecae605eb6d84f687da001ab8ccffd50f612ae50f988ef76e6312c752897f462f3ac08d
languageName: node
linkType: hard

"@ethersproject/abstract-provider@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/abstract-provider@npm:5.7.0"
Expand Down Expand Up @@ -512,6 +554,84 @@ __metadata:
languageName: node
linkType: hard

"@metamask/eth-json-rpc-provider@npm:^2.3.0":
version: 2.3.0
resolution: "@metamask/eth-json-rpc-provider@npm:2.3.0"
dependencies:
"@metamask/json-rpc-engine": ^7.3.0
"@metamask/safe-event-emitter": ^3.0.0
"@metamask/utils": ^8.2.0
checksum: 1c02ac329917015eab035e666677cc1acde620e94c1586af4bfa4656b4dc69569af07daae3ed31ce0e046d06c19c873559e89aebcaa7109a8d225a63b526e9a6
languageName: node
linkType: hard

"@metamask/json-rpc-engine@npm:^7.3.0":
version: 7.3.0
resolution: "@metamask/json-rpc-engine@npm:7.3.0"
dependencies:
"@metamask/rpc-errors": ^6.1.0
"@metamask/safe-event-emitter": ^3.0.0
"@metamask/utils": ^8.2.0
checksum: 7e12fb58ee2775269aa3e6e3a40d18d9053b6cefb6eaa2b80558a65986d0e451a9faf3935548d5b4eced857c6b569e768cb235ef10ff0feb72a23ccadaaff4bc
languageName: node
linkType: hard

"@metamask/rpc-errors@npm:^6.1.0":
version: 6.1.0
resolution: "@metamask/rpc-errors@npm:6.1.0"
dependencies:
"@metamask/utils": ^8.1.0
fast-safe-stringify: ^2.0.6
checksum: 9f4821d804e2fcaa8987b0958d02c6d829b7c7db49740c811cb593f381d0c4b00dabb7f1802907f1b2f6126f7c0d83ec34219183d29650f5d24df014ac72906a
languageName: node
linkType: hard

"@metamask/safe-event-emitter@npm:^3.0.0":
version: 3.0.0
resolution: "@metamask/safe-event-emitter@npm:3.0.0"
checksum: 8dc58a76f9f75bf2405931465fc311c68043d851e6b8ebe9f82ae339073a08a83430dba9338f8e3adc4bfc8067607125074bcafa32baee3a5157f42343dc89e5
languageName: node
linkType: hard

"@metamask/utils@npm:^8.1.0, @metamask/utils@npm:^8.2.0":
version: 8.2.1
resolution: "@metamask/utils@npm:8.2.1"
dependencies:
"@ethereumjs/tx": ^4.2.0
"@noble/hashes": ^1.3.1
"@scure/base": ^1.1.3
"@types/debug": ^4.1.7
debug: ^4.3.4
pony-cause: ^2.1.10
semver: ^7.5.4
superstruct: ^1.0.3
checksum: 36a714a17e4949d2040bedb28d4373a22e7e86bb797aa2d59223f9799fd76e662443bcede113719c4e200f5e9d90a9d62feafad5028fff8b9a7a85fface097ca
languageName: node
linkType: hard

"@noble/curves@npm:1.1.0, @noble/curves@npm:~1.1.0":
version: 1.1.0
resolution: "@noble/curves@npm:1.1.0"
dependencies:
"@noble/hashes": 1.3.1
checksum: 2658cdd3f84f71079b4e3516c47559d22cf4b55c23ac8ee9d2b1f8e5b72916d9689e59820e0f9d9cb4a46a8423af5b56dc6bb7782405c88be06a015180508db5
languageName: node
linkType: hard

"@noble/hashes@npm:1.3.1":
version: 1.3.1
resolution: "@noble/hashes@npm:1.3.1"
checksum: 7fdefc0f7a0c1ec27acc6ff88841793e3f93ec4ce6b8a6a12bfc0dd70ae6b7c4c82fe305fdfeda1735d5ad4a9eebe761e6693b3d355689c559e91242f4bc95b1
languageName: node
linkType: hard

"@noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0, @noble/hashes@npm:~1.3.1":
version: 1.3.2
resolution: "@noble/hashes@npm:1.3.2"
checksum: fe23536b436539d13f90e4b9be843cc63b1b17666a07634a2b1259dded6f490be3d050249e6af98076ea8f2ea0d56f578773c2197f2aa0eeaa5fba5bc18ba474
languageName: node
linkType: hard

"@nodelib/fs.scandir@npm:2.1.5":
version: 2.1.5
resolution: "@nodelib/fs.scandir@npm:2.1.5"
Expand Down Expand Up @@ -584,13 +704,50 @@ __metadata:
languageName: node
linkType: hard

"@scure/base@npm:^1.1.3, @scure/base@npm:~1.1.0":
version: 1.1.3
resolution: "@scure/base@npm:1.1.3"
checksum: 1606ab8a4db898cb3a1ada16c15437c3bce4e25854fadc8eb03ae93cbbbac1ed90655af4b0be3da37e12056fef11c0374499f69b9e658c9e5b7b3e06353c630c
languageName: node
linkType: hard

"@scure/bip32@npm:1.3.1":
version: 1.3.1
resolution: "@scure/bip32@npm:1.3.1"
dependencies:
"@noble/curves": ~1.1.0
"@noble/hashes": ~1.3.1
"@scure/base": ~1.1.0
checksum: 394d65f77a40651eba21a5096da0f4233c3b50d422864751d373fcf142eeedb94a1149f9ab1dbb078086dab2d0bc27e2b1afec8321bf22d4403c7df2fea5bfe2
languageName: node
linkType: hard

"@scure/bip39@npm:1.2.1":
version: 1.2.1
resolution: "@scure/bip39@npm:1.2.1"
dependencies:
"@noble/hashes": ~1.3.0
"@scure/base": ~1.1.0
checksum: c5bd6f1328fdbeae2dcdd891825b1610225310e5e62a4942714db51066866e4f7bef242c7b06a1b9dcc8043a4a13412cf5c5df76d3b10aa9e36b82e9b6e3eeaa
languageName: node
linkType: hard

"@tootallnate/once@npm:2":
version: 2.0.0
resolution: "@tootallnate/once@npm:2.0.0"
checksum: ad87447820dd3f24825d2d947ebc03072b20a42bfc96cbafec16bff8bbda6c1a81fcb0be56d5b21968560c5359a0af4038a68ba150c3e1694fe4c109a063bed8
languageName: node
linkType: hard

"@types/debug@npm:^4.1.7":
version: 4.1.12
resolution: "@types/debug@npm:4.1.12"
dependencies:
"@types/ms": "*"
checksum: 47876a852de8240bfdaf7481357af2b88cb660d30c72e73789abf00c499d6bc7cd5e52f41c915d1b9cd8ec9fef5b05688d7b7aef17f7f272c2d04679508d1053
languageName: node
linkType: hard

"@types/glob@npm:^7.1.1":
version: 7.1.4
resolution: "@types/glob@npm:7.1.4"
Expand Down Expand Up @@ -622,6 +779,13 @@ __metadata:
languageName: node
linkType: hard

"@types/ms@npm:*":
version: 0.7.34
resolution: "@types/ms@npm:0.7.34"
checksum: f38d36e7b6edecd9badc9cf50474159e9da5fa6965a75186cceaf883278611b9df6669dc3a3cc122b7938d317b68a9e3d573d316fcb35d1be47ec9e468c6bd8a
languageName: node
linkType: hard

"@types/node@npm:*":
version: 16.3.1
resolution: "@types/node@npm:16.3.1"
Expand Down Expand Up @@ -1277,6 +1441,15 @@ __metadata:
languageName: node
linkType: hard

"crc-32@npm:^1.2.0":
version: 1.2.2
resolution: "crc-32@npm:1.2.2"
bin:
crc32: bin/crc32.njs
checksum: ad2d0ad0cbd465b75dcaeeff0600f8195b686816ab5f3ba4c6e052a07f728c3e70df2e3ca9fd3d4484dc4ba70586e161ca5a2334ec8bf5a41bf022a6103ff243
languageName: node
linkType: hard

"create-hash@npm:^1.1.0, create-hash@npm:^1.1.2":
version: 1.2.0
resolution: "create-hash@npm:1.2.0"
Expand Down Expand Up @@ -1918,6 +2091,18 @@ __metadata:
languageName: node
linkType: hard

"ethereum-cryptography@npm:^2.0.0":
version: 2.1.2
resolution: "ethereum-cryptography@npm:2.1.2"
dependencies:
"@noble/curves": 1.1.0
"@noble/hashes": 1.3.1
"@scure/bip32": 1.3.1
"@scure/bip39": 1.2.1
checksum: 2e8f7b8cc90232ae838ab6a8167708e8362621404d26e79b5d9e762c7b53d699f7520aff358d9254de658fcd54d2d0af168ff909943259ed27dc4cef2736410c
languageName: node
linkType: hard

"ethereumjs-util@npm:^6.1.0":
version: 6.1.0
resolution: "ethereumjs-util@npm:6.1.0"
Expand Down Expand Up @@ -2026,6 +2211,13 @@ __metadata:
languageName: node
linkType: hard

"fast-safe-stringify@npm:^2.0.6":
version: 2.1.1
resolution: "fast-safe-stringify@npm:2.1.1"
checksum: a851cbddc451745662f8f00ddb622d6766f9bd97642dabfd9a405fb0d646d69fc0b9a1243cbf67f5f18a39f40f6fa821737651ff1bceeba06c9992ca2dc5bd3d
languageName: node
linkType: hard

"fastq@npm:^1.6.0":
version: 1.9.0
resolution: "fastq@npm:1.9.0"
Expand Down Expand Up @@ -3019,6 +3211,13 @@ __metadata:
languageName: node
linkType: hard

"micro-ftch@npm:^0.3.1":
version: 0.3.1
resolution: "micro-ftch@npm:0.3.1"
checksum: 0e496547253a36e98a83fb00c628c53c3fb540fa5aaeaf718438873785afd193244988c09d219bb1802984ff227d04938d9571ef90fe82b48bd282262586aaff
languageName: node
linkType: hard

"micromatch@npm:^4.0.4":
version: 4.0.4
resolution: "micromatch@npm:4.0.4"
Expand Down Expand Up @@ -3298,6 +3497,7 @@ __metadata:
"@metamask/eslint-config-mocha": ^10.0.0
"@metamask/eslint-config-nodejs": ^10.0.0
"@metamask/eslint-config-typescript": ^10.0.0
"@metamask/eth-json-rpc-provider": ^2.3.0
"@types/node": ^16.18.59
"@typescript-eslint/eslint-plugin": ^5.30.7
"@typescript-eslint/parser": ^5.30.7
Expand Down Expand Up @@ -3536,6 +3736,13 @@ __metadata:
languageName: node
linkType: hard

"pony-cause@npm:^2.1.10":
version: 2.1.10
resolution: "pony-cause@npm:2.1.10"
checksum: 8b61378f213e61056312dc274a1c79980154e9d864f6ad86e0c8b91a50d3ce900d430995ee24147c9f3caa440dfe7d51c274b488d7f033b65b206522536d7217
languageName: node
linkType: hard

"prelude-ls@npm:^1.2.1":
version: 1.2.1
resolution: "prelude-ls@npm:1.2.1"
Expand Down Expand Up @@ -3830,7 +4037,7 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8":
"semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.4":
version: 7.5.4
resolution: "semver@npm:7.5.4"
dependencies:
Expand Down Expand Up @@ -4113,6 +4320,13 @@ __metadata:
languageName: node
linkType: hard

"superstruct@npm:^1.0.3":
version: 1.0.3
resolution: "superstruct@npm:1.0.3"
checksum: 761790bb111e6e21ddd608299c252f3be35df543263a7ebbc004e840d01fcf8046794c274bcb351bdf3eae4600f79d317d085cdbb19ca05803a4361840cc9bb1
languageName: node
linkType: hard

"supports-color@npm:8.1.1":
version: 8.1.1
resolution: "supports-color@npm:8.1.1"
Expand Down