watcher-ts/packages/ipld-eth-client/src/utils.ts
Nabarun Gogoi c06330dd06
Implement rpc-eth-client for Ethereum compatible JSON-RPC endpoint (#398)
* Implement rpc-eth-client with getStorageAt method

* Add test for comparing RPC and GQL eth-client getStorageAt method

* Add getBlockWithTransactions and getBlocks method

* Implement getFullBlocks with RLP encoded data

* Implement getFullTransaction method with raw tx

* Implement getBlockByHash and getLogs methods

* Add flag and interface to switch between RPC and GQL eth clients

* Fix getBlocks to return empty array when block not present

* Return empty array in getBlocks for missing block and use blockNumber in getLogs

* Fix getRawTransaction method for zero signature.v value

* Remove duplicate util from rpc-eth-client
2023-08-08 18:48:55 +05:30

29 lines
784 B
TypeScript

//
// Copyright 2021 Vulcanize, Inc.
//
import leftPad from 'left-pad';
import { ethers } from 'ethers';
export const padKey = (input: string): string =>
leftPad(ethers.utils.hexlify(input).replace('0x', ''), 64, '0');
export const getMappingSlot = (mappingSlot: string, key: string): string => {
const mappingSlotPadded = padKey(mappingSlot);
const keyPadded = padKey(key);
const fullKey = keyPadded.concat(mappingSlotPadded);
const slot = ethers.utils.keccak256(`0x${fullKey}`);
return slot;
};
export const getStorageLeafKey = (slot: string): string => ethers.utils.keccak256(slot);
export const topicToAddress = (topic: string): string => {
return ethers.utils.getAddress(
ethers.utils.hexZeroPad(
ethers.utils.hexStripZeros(topic), 20
)
);
};