@@ -19,10 +19,15 @@ export const publicClient = createPublicClient({
1919 chain : mainnet ,
2020} ) ;
2121
22- export const getEventLogs = async ( { contractAddress, event, maxLogs } : GetEventLogs ) : Promise < Log [ ] > => {
22+ export const getEventLogs = async ( {
23+ contractAddress,
24+ event,
25+ maxLogs,
26+ fromBlock : initialFromBlock ,
27+ } : GetEventLogs ) : Promise < Log [ ] > => {
2328 const latestBlock = await publicClient . getBlockNumber ( ) ;
2429 let toBlock = latestBlock ;
25- let fromBlock = getBlockInRange ( toBlock ) ;
30+ let fromBlock = initialFromBlock ?? getBlockInRange ( toBlock ) ;
2631
2732 let tries = 0 ;
2833 const logs : Log [ ] = [ ] ;
@@ -79,8 +84,10 @@ export const getUniqueLogs = (logs: Log[]): Log[] => {
7984export const getTransactionsWithEvents = async (
8085 logs : Log [ ] ,
8186 events : readonly AbiEvent [ ] ,
82- ) : Promise < TransactionReceipt [ ] > =>
83- logs . reduce < Promise < TransactionReceipt [ ] > > ( async ( accumulatorPromise , log ) => {
87+ ) : Promise < TransactionReceipt [ ] > => {
88+ const eventTopics = events . map ( ( event ) => encodeEventTopics ( { abi : [ event ] } ) [ 0 ] ) ;
89+
90+ return logs . reduce < Promise < TransactionReceipt [ ] > > ( async ( accumulatorPromise , log ) => {
8491 const accumulator = await accumulatorPromise ;
8592
8693 if ( accumulator . length >= NUMBER_OF_TRANSACTIONS ) {
@@ -93,9 +100,8 @@ export const getTransactionsWithEvents = async (
93100 return accumulator ;
94101 }
95102
96- const hasAllEvents = events . every ( ( event , index ) => {
103+ const hasAllEvents = eventTopics . every ( ( eventTopic , index ) => {
97104 const logTopic = receipt . logs [ index ] ! . topics [ 0 ] ;
98- const eventTopic = encodeEventTopics ( { abi : [ event ] } ) [ 0 ] ;
99105
100106 return logTopic === eventTopic ;
101107 } ) ;
@@ -108,3 +114,4 @@ export const getTransactionsWithEvents = async (
108114
109115 return accumulator ;
110116 } , Promise . resolve ( [ ] ) ) ;
117+ } ;
0 commit comments