MCPcopy Create free account
hub / github.com/ccxt/ccxt / decodeEventLog

Method decodeEventLog

ts/src/static_dependencies/ethers/interface.ts:1077–1146  ·  view source on GitHub ↗
(fragment: EventFragment | string, data: BytesLike, topics?: ReadonlyArray<string>)

Source from the content-addressed store, hash-verified

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 {

Callers 1

parseLogMethod · 0.95

Calls 10

getEventMethod · 0.95
assertArgumentFunction · 0.90
isHexStringFunction · 0.90
concatFunction · 0.90
pushMethod · 0.80
sliceMethod · 0.45
forEachMethod · 0.45
fromMethod · 0.45
decodeMethod · 0.45
fromItemsMethod · 0.45

Tested by

no test coverage detected