Skip to content

Commit

Permalink
Fixed WebSocketProvider filter events (#784).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 15, 2020
1 parent 7498c18 commit 69f7077
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 10 additions & 0 deletions packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
14 changes: 6 additions & 8 deletions packages/providers/src.ts/websocket-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);


/**
* Notes:
*
Expand All @@ -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 };
Expand Down Expand Up @@ -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;
}
Expand All @@ -252,5 +251,4 @@ export class WebSocketProvider extends JsonRpcProvider {
this.send("eth_unsubscribe", [ subId ]);
});
}

}

0 comments on commit 69f7077

Please sign in to comment.