Fix 3380: Add AbstractProvider - #3451
Conversation
|
|
||
| export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis'; | ||
|
|
||
| export interface AbstractProvider extends EventEmitter { |
There was a problem hiding this comment.
I would like to consider the following points
- Using the
extends EventEmitter. - Remove
extends EventEmitter(Leaving only thesendfunction in the interface). - Remove
extends EventEmitterand directly define theon,once, andremoveListenerfunctions as well as theWebsocketProviderBase.
There was a problem hiding this comment.
My $0.02 is to separate the core functionality from the subscription functionality. Not all custom providers support subscription features by default. Classes can implement multiple interfaces in TypeScript, so it shouldn't be problematic to export two interfaces.
I am not an active contributor to this code-base. This is my opinion only.
There was a problem hiding this comment.
Hey @odanado thanks for this PR :) It LGTM. For your 3 points, perhaps just on/once/removeListener is sufficient as the "bare minimum".
What are the types of WebsocketProviderBase?
Also, in light of recent updates to EIP-1193, there is a new request method that would be great to add. I don't think having sendAsync would hurt either even though it's deprecated it has more long term support.
There was a problem hiding this comment.
@ryanio Thank you for the comment.
I didn't know the request method of EIP-1193.
I thought that the interface of the AbstractProvider should be an only of send and sendAsync.
The reasons are as follows.
- The status of EIP-1193 is a draft.
- EIP-1193 is not yet fully implemented in Metamask
I think it should define a provider that has methods such as on/once/removeListener/request separately from AbstractProvider.
|
Thanks for adding sendAsync 🙌 looks like there is a small dtslint issue. |
|
@ryanio I forgot that fix a test. |
Description
Fixes #3380
The only method that
providershould implement is thesendfunction.I'd like you to consider whether the interface of
EventEmittershould be implemented or not.Type of change
Checklist:
npm run dtslintwith success and extended the tests and types if necessary.npm run test:unitwith success.npm run test:covand my test cases do cover all lines and branches of the added code.npm run build-alland tested the resulting file/'s fromdistfolder in a browser.CHANGELOG.mdfile in the root folder.