MCPcopy Create free account
hub / github.com/ccxt/ccxt / #getEvent

Method #getEvent

js/src/static_dependencies/ethers/interface.js:374–431  ·  view source on GitHub ↗
(key, values, forceUnique)

Source from the content-addressed store, hash-verified

372 }
373 // Find an event definition by any means necessary (unless it is ambiguous)
374 #getEvent(key, values, forceUnique) {
375 // EventTopic
376 if (isHexString(key)) {
377 const eventTopic = key.toLowerCase();
378 for (const fragment of this.#events.values()) {
379 if (eventTopic === fragment.topicHash) {
380 return fragment;
381 }
382 }
383 return null;
384 }
385 // It is a bare name, look up the function (will return null if ambiguous)
386 if (key.indexOf("(") === -1) {
387 const matching = [];
388 for (const [name, fragment] of this.#events) {
389 if (name.split("(" /* fix:) */)[0] === key) {
390 matching.push(fragment);
391 }
392 }
393 if (values) {
394 // Remove all matches that don't have a compatible length.
395 for (let i = matching.length - 1; i >= 0; i--) {
396 if (matching[i].inputs.length < values.length) {
397 matching.splice(i, 1);
398 }
399 }
400 // Remove all matches that don't match the Typed signature
401 for (let i = matching.length - 1; i >= 0; i--) {
402 const inputs = matching[i].inputs;
403 for (let j = 0; j < values.length; j++) {
404 // Not a typed value
405 if (!Typed.isTyped(values[j])) {
406 continue;
407 }
408 // Make sure the value type matches the input type
409 if (values[j].type !== inputs[j].baseType) {
410 matching.splice(i, 1);
411 break;
412 }
413 }
414 }
415 }
416 if (matching.length === 0) {
417 return null;
418 }
419 if (matching.length > 1 && forceUnique) {
420 const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", ");
421 assertArgument(false, `ambiguous event description (i.e. matches ${matchStr})`, "key", key);
422 }
423 return matching[0];
424 }
425 // Normalize the signature and lookup the function
426 const result = this.#events.get(EventFragment.from(key).format());
427 if (result) {
428 return result;
429 }
430 return null;
431 }

Callers 3

getEventNameMethod · 0.95
hasEventMethod · 0.95
getEventMethod · 0.95

Calls 10

isHexStringFunction · 0.90
assertArgumentFunction · 0.90
splitMethod · 0.80
pushMethod · 0.80
valuesMethod · 0.45
isTypedMethod · 0.45
mapMethod · 0.45
formatMethod · 0.45
getMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected