watcher-ts/packages/solidity-mapper/src/logs.ts
Ashwin Phatak b243025ca8
Test cases in solidity-mapper for contract, fixed-size byte arrays and enum types (#26)
* Add tests for getStorageInfo and getEventNameTopics.

* Lint solidity-mapper package code.

* Add test for contract type.

* Add test for fixed size byte arrays.

* Add test for Enum types.

* Add tests for variables packed together and using single slot.

* Fix comments in test contracts.

Co-authored-by: nikugogoi <95nikass@gmail.com>
2021-06-02 11:23:33 +05:30

27 lines
707 B
TypeScript

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;
}, {});
};