| 833 | } |
| 834 | // Decode a filter for the event and the search criteria |
| 835 | decodeEventLog(fragment, data, topics) { |
| 836 | if (typeof (fragment) === "string") { |
| 837 | const f = this.getEvent(fragment); |
| 838 | assertArgument(f, "unknown event", "eventFragment", fragment); |
| 839 | fragment = f; |
| 840 | } |
| 841 | if (topics != null && !fragment.anonymous) { |
| 842 | const eventTopic = fragment.topicHash; |
| 843 | assertArgument(isHexString(topics[0], 32) && topics[0].toLowerCase() === eventTopic, "fragment/topic mismatch", "topics[0]", topics[0]); |
| 844 | topics = topics.slice(1); |
| 845 | } |
| 846 | const indexed = []; |
| 847 | const nonIndexed = []; |
| 848 | const dynamic = []; |
| 849 | fragment.inputs.forEach((param, index) => { |
| 850 | if (param.indexed) { |
| 851 | if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") { |
| 852 | indexed.push(ParamType.from({ type: "bytes32", name: param.name })); |
| 853 | dynamic.push(true); |
| 854 | } |
| 855 | else { |
| 856 | indexed.push(param); |
| 857 | dynamic.push(false); |
| 858 | } |
| 859 | } |
| 860 | else { |
| 861 | nonIndexed.push(param); |
| 862 | dynamic.push(false); |
| 863 | } |
| 864 | }); |
| 865 | const resultIndexed = (topics != null) ? this.#abiCoder.decode(indexed, concat(topics)) : null; |
| 866 | const resultNonIndexed = this.#abiCoder.decode(nonIndexed, data, true); |
| 867 | //const result: (Array<any> & { [ key: string ]: any }) = [ ]; |
| 868 | const values = []; |
| 869 | const keys = []; |
| 870 | let nonIndexedIndex = 0, indexedIndex = 0; |
| 871 | fragment.inputs.forEach((param, index) => { |
| 872 | let value = null; |
| 873 | if (param.indexed) { |
| 874 | if (resultIndexed == null) { |
| 875 | value = new Indexed(null); |
| 876 | } |
| 877 | else if (dynamic[index]) { |
| 878 | value = new Indexed(resultIndexed[indexedIndex++]); |
| 879 | } |
| 880 | else { |
| 881 | try { |
| 882 | value = resultIndexed[indexedIndex++]; |
| 883 | } |
| 884 | catch (error) { |
| 885 | value = error; |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | else { |
| 890 | try { |
| 891 | value = resultNonIndexed[nonIndexedIndex++]; |
| 892 | } |