-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Conversation
packages/web3-core/types/index.d.ts
Outdated
@@ -410,9 +413,14 @@ export interface LogsOptions { | |||
|
|||
export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis'; | |||
|
|||
export interface AbstractProvider extends EventEmitter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to consider the following points
- Using the
extends EventEmitter
. - Remove
extends EventEmitter
(Leaving only thesend
function in the interface). - Remove
extends EventEmitter
and directly define theon
,once
, andremoveListener
functions as well as theWebsocketProviderBase
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Description
Fixes #3380
The only method that
provider
should implement is thesend
function.I'd like you to consider whether the interface of
EventEmitter
should be implemented or not.Type of change
Checklist:
npm run dtslint
with success and extended the tests and types if necessary.npm run test:unit
with success.npm run test:cov
and my test cases do cover all lines and branches of the added code.npm run build-all
and tested the resulting file/'s fromdist
folder in a browser.CHANGELOG.md
file in the root folder.