mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-05-06 23:34:18 +00:00
* Add license & copyright declarations for add-watcher. * Add copyright declarations for cache. * Add copyright declarations for erc20-watcher. * Add copyright declarations for ipld-eth-client. * Add copyright declarations for tracing-client. * Add copyright declarations for uni-watcher. * Add copyright declarations for solidity-mapper. * Add copyright declarations for uni-info-watcher. * Add copyright declarations for util. * Add copyright declarations for lighthouse-watcher. * Change license identifier in .sol files. Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
31 lines
748 B
TypeScript
31 lines
748 B
TypeScript
//
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
//
|
|
|
|
import { JsonFragment } from '@ethersproject/abi';
|
|
import { utils } from 'ethers';
|
|
|
|
interface EventNameTopics {
|
|
[eventName: string]: string
|
|
}
|
|
|
|
/**
|
|
* Function to get event name topics from abi.
|
|
* @param abi
|
|
*/
|
|
export const getEventNameTopics = (abi: JsonFragment[]): EventNameTopics => {
|
|
const eventFragments = abi.filter(({ type }) => type === 'event');
|
|
|
|
return eventFragments.reduce((acc: EventNameTopics, { name, inputs }) => {
|
|
if (inputs && name) {
|
|
const inputParamsString = inputs.map(({ type }) => type)
|
|
.join(',');
|
|
|
|
const signature = utils.keccak256(utils.toUtf8Bytes(`${name}(${inputParamsString})`));
|
|
acc[name] = signature;
|
|
}
|
|
|
|
return acc;
|
|
}, {});
|
|
};
|