Fixed WebSocketProvider filter events (#784).

This commit is contained in:
Richard Moore 2020-04-15 16:46:15 -04:00
parent 7498c18235
commit 69f707762e
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 16 additions and 8 deletions

@ -123,6 +123,16 @@ export class Event {
defineReadOnly(this, "once", once);
}
get event(): EventType {
switch (this.type) {
case "tx":
return this.hash;
case "filter":
return this.filter;
}
return this.tag;
}
get type(): string {
return this.tag.split(":")[0]
}

@ -13,7 +13,6 @@ import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
/**
* Notes:
*
@ -40,11 +39,11 @@ export type Subscription = {
tag: string;
processFunc: (payload: any) => void;
};
/*
function subscribable(tag: string): boolean {
return (tag === "block" || tag === "pending");
}
*/
// For more info about the Real-time Event API see:
// https://geth.ethereum.org/docs/rpc/pubsub
export class WebSocketProvider extends JsonRpcProvider {
readonly _websocket: any;
readonly _requests: { [ name: string ]: InflightRequest };
@ -237,7 +236,7 @@ export class WebSocketProvider extends JsonRpcProvider {
return;
}
tag = "tx";
} else if (this.listenerCount(event.tag)) {
} else if (this.listenerCount(event.event)) {
// There are remaining event listeners
return;
}
@ -252,5 +251,4 @@ export class WebSocketProvider extends JsonRpcProvider {
this.send("eth_unsubscribe", [ subId ]);
});
}
}