From 28800d7681f3bab08f6d30a22f0813e04feee18a Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 1 May 2020 16:18:31 -0400 Subject: [PATCH] Allow contract filters to include OR-ed values (#437). --- packages/abi/src.ts/interface.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/abi/src.ts/interface.ts b/packages/abi/src.ts/interface.ts index 7d3efa8f..32868ffa 100644 --- a/packages/abi/src.ts/interface.ts +++ b/packages/abi/src.ts/interface.ts @@ -352,9 +352,21 @@ export class Interface { }) } - let topics: Array = []; + let topics: Array> = []; 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]; @@ -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)); } });