| 1075 | |
| 1076 | // Decode a filter for the event and the search criteria |
| 1077 | decodeEventLog(fragment: EventFragment | string, data: BytesLike, topics?: ReadonlyArray<string>): Result { |
| 1078 | if (typeof(fragment) === "string") { |
| 1079 | const f = this.getEvent(fragment); |
| 1080 | assertArgument(f, "unknown event", "eventFragment", fragment); |
| 1081 | fragment = f; |
| 1082 | } |
| 1083 | |
| 1084 | if (topics != null && !fragment.anonymous) { |
| 1085 | const eventTopic = fragment.topicHash; |
| 1086 | assertArgument(isHexString(topics[0], 32) && topics[0].toLowerCase() === eventTopic, |
| 1087 | "fragment/topic mismatch", "topics[0]", topics[0]); |
| 1088 | topics = topics.slice(1); |
| 1089 | } |
| 1090 | |
| 1091 | const indexed: Array<ParamType> = []; |
| 1092 | const nonIndexed: Array<ParamType> = []; |
| 1093 | const dynamic: Array<boolean> = []; |
| 1094 | |
| 1095 | fragment.inputs.forEach((param, index) => { |
| 1096 | if (param.indexed) { |
| 1097 | if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") { |
| 1098 | indexed.push(ParamType.from({ type: "bytes32", name: param.name })); |
| 1099 | dynamic.push(true); |
| 1100 | } else { |
| 1101 | indexed.push(param); |
| 1102 | dynamic.push(false); |
| 1103 | } |
| 1104 | } else { |
| 1105 | nonIndexed.push(param); |
| 1106 | dynamic.push(false); |
| 1107 | } |
| 1108 | }); |
| 1109 | |
| 1110 | const resultIndexed = (topics != null) ? this.#abiCoder.decode(indexed, concat(topics)): null; |
| 1111 | const resultNonIndexed = this.#abiCoder.decode(nonIndexed, data, true); |
| 1112 | |
| 1113 | //const result: (Array<any> & { [ key: string ]: any }) = [ ]; |
| 1114 | const values: Array<any> = [ ]; |
| 1115 | const keys: Array<null | string> = [ ]; |
| 1116 | let nonIndexedIndex = 0, indexedIndex = 0; |
| 1117 | fragment.inputs.forEach((param, index) => { |
| 1118 | let value: null | Indexed | Error = null; |
| 1119 | if (param.indexed) { |
| 1120 | if (resultIndexed == null) { |
| 1121 | value = new Indexed(null); |
| 1122 | |
| 1123 | } else if (dynamic[index]) { |
| 1124 | value = new Indexed(resultIndexed[indexedIndex++]); |
| 1125 | |
| 1126 | } else { |
| 1127 | try { |
| 1128 | value = resultIndexed[indexedIndex++]; |
| 1129 | } catch (error: any) { |
| 1130 | value = error; |
| 1131 | } |
| 1132 | } |
| 1133 | } else { |
| 1134 | try { |