| 1030 | } |
| 1031 | |
| 1032 | encodeEventLog(fragment: EventFragment | string, values: ReadonlyArray<any>): { data: string, topics: Array<string> } { |
| 1033 | if (typeof(fragment) === "string") { |
| 1034 | const f = this.getEvent(fragment); |
| 1035 | assertArgument(f, "unknown event", "eventFragment", fragment); |
| 1036 | fragment = f; |
| 1037 | } |
| 1038 | |
| 1039 | const topics: Array<string> = [ ]; |
| 1040 | |
| 1041 | const dataTypes: Array<ParamType> = [ ]; |
| 1042 | const dataValues: Array<string> = [ ]; |
| 1043 | |
| 1044 | if (!fragment.anonymous) { |
| 1045 | topics.push(fragment.topicHash); |
| 1046 | } |
| 1047 | |
| 1048 | assertArgument(values.length === fragment.inputs.length, |
| 1049 | "event arguments/values mismatch", "values", values); |
| 1050 | |
| 1051 | fragment.inputs.forEach((param, index) => { |
| 1052 | const value = values[index]; |
| 1053 | if (param.indexed) { |
| 1054 | if (param.type === "string") { |
| 1055 | topics.push(id(value)) |
| 1056 | } else if (param.type === "bytes") { |
| 1057 | topics.push(keccak256(value)) |
| 1058 | } else if (param.baseType === "tuple" || param.baseType === "array") { |
| 1059 | // @TODO |
| 1060 | throw new Error("not implemented"); |
| 1061 | } else { |
| 1062 | topics.push(this.#abiCoder.encode([ param.type] , [ value ])); |
| 1063 | } |
| 1064 | } else { |
| 1065 | dataTypes.push(param); |
| 1066 | dataValues.push(value); |
| 1067 | } |
| 1068 | }); |
| 1069 | |
| 1070 | return { |
| 1071 | data: this.#abiCoder.encode(dataTypes , dataValues), |
| 1072 | topics: topics |
| 1073 | }; |
| 1074 | } |
| 1075 | |
| 1076 | // Decode a filter for the event and the search criteria |
| 1077 | decodeEventLog(fragment: EventFragment | string, data: BytesLike, topics?: ReadonlyArray<string>): Result { |