Skip to content

Commit

Permalink
Allow contract filters to include OR-ed values (#437).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 1, 2020
1 parent 9f80251 commit 28800d7
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/abi/src.ts/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,21 @@ export class Interface {
})
}

let topics: Array<string> = [];
let topics: Array<string | Array<string>> = [];
if (!eventFragment.anonymous) { topics.push(this.getEventTopic(eventFragment)); }

const encodeTopic = (param: ParamType, value: any): string => {
if (param.type === "string") {
return id(value);
} else if (param.type === "bytes") {
return keccak256(hexlify(value));
}

// Check addresses are valid
if (param.type === "address") { this._abiCoder.encode( [ "address" ], [ value ]); }
return hexZeroPad(hexlify(value), 32);
};

values.forEach((value, index) => {

let param = eventFragment.inputs[index];
Expand All @@ -368,16 +380,12 @@ export class Interface {

if (value == null) {
topics.push(null);
} else if (param.type === "string") {
topics.push(id(value));
} else if (param.type === "bytes") {
topics.push(keccak256(hexlify(value)));
} else if (param.type.indexOf("[") !== -1 || param.type.substring(0, 5) === "tuple") {
} else if (param.baseType === "array" || param.baseType === "tuple") {
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
} else if (Array.isArray(value)) {
topics.push(value.map((value) => encodeTopic(param, value)));
} else {
// Check addresses are valid
if (param.type === "address") { this._abiCoder.encode( [ "address" ], [ value ]); }
topics.push(hexZeroPad(hexlify(value), 32));
topics.push(encodeTopic(param, value));
}
});

Expand Down

0 comments on commit 28800d7

Please sign in to comment.