Skip to content

Commit

Permalink
Fix provider log filters with zero topics (#785).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 17, 2020
1 parent 51e198a commit 4ef0e4f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ function checkTopic(topic: string): string {
}

function serializeTopics(topics: Array<string | Array<string>>): string {

// Remove trailing null AND-topics; they are redundant
topics = topics.slice();
while (topics[topics.length - 1] == null) { topics.pop(); }
while (topics.length > 0 && topics[topics.length - 1] == null) { topics.pop(); }

return topics.map((topic) => {
if (Array.isArray(topic)) {
Expand All @@ -58,6 +57,7 @@ function serializeTopics(topics: Array<string | Array<string>>): string {
}

function deserializeTopics(data: string): Array<string | Array<string>> {
if (data === "") { return [ ]; }
return data.split(/&/g).map((topic) => {
return topic.split("|").map((topic) => {
return ((topic === "null") ? null: topic);
Expand Down Expand Up @@ -146,11 +146,14 @@ export class Event {
get filter(): Filter {
const comps = this.tag.split(":");
if (comps[0] !== "filter") { return null; }
const filter = {
address: comps[1],
topics: deserializeTopics(comps[2])
}
if (!filter.address || filter.address === "*") { delete filter.address; }
const address = comps[1];

const topics = deserializeTopics(comps[2]);
const filter: Filter = { };

if (topics.length > 0) { filter.topics = topics; }
if (address && address !== "*") { filter.address = address; }

return filter;
}

Expand Down Expand Up @@ -976,7 +979,6 @@ export class BaseProvider extends Provider {
_addEventListener(eventName: EventType, listener: Listener, once: boolean): this {
const event = new Event(getEventTag(eventName), listener, once)
this._events.push(event);

this._startEvent(event);

return this;
Expand Down

0 comments on commit 4ef0e4f

Please sign in to comment.