@@ -20,7 +20,6 @@ import {
2020 type Hex ,
2121 type Log ,
2222 type Transaction ,
23- decodeAbiParameters ,
2423 decodeEventLog ,
2524 decodeFunctionData ,
2625 encodeAbiParameters ,
@@ -2198,50 +2197,22 @@ export function decodeAndReorderLogArgs(event: AbiEvent, log: Log) {
21982197 event . inputs [ 2 ] ! . indexed = true ;
21992198 }
22002199
2201- const indexedInputs : AbiParameter [ ] = [ ] ;
2202- const nonIndexedInputs : AbiParameter [ ] = [ ] ;
2203-
2204- for ( let i = 0 ; i < event . inputs . length ; i ++ ) {
2205- const input = event . inputs [ i ] ! ;
2206- if ( input . indexed ) {
2207- indexedInputs . push ( input ) ;
2208- } else {
2209- nonIndexedInputs . push ( input ) ;
2210- }
2211- }
2212-
2213- const decodedIndexed : unknown [ ] = [ ] ;
2214- for ( let i = 0 ; i < indexedInputs . length ; i ++ ) {
2215- const topic = log . topics [ i + 1 ] ;
2216- if ( ! topic ) {
2217- throw new DecodedArgsError (
2218- `Missing topic at index ${ i + 1 } for indexed parameter "${ indexedInputs [ i ] ! . name ?? i } "` ,
2219- ) ;
2220- }
2221- const [ decoded ] = decodeAbiParameters ( [ indexedInputs [ i ] ! ] , topic ) ;
2222- decodedIndexed . push ( decoded ) ;
2223- }
2224-
2225- const decodedNonIndexed =
2226- nonIndexedInputs . length > 0 && log . data && log . data !== '0x'
2227- ? decodeAbiParameters ( nonIndexedInputs , log . data )
2228- : [ ] ;
2200+ const namedEvent = structuredClone ( event ) ;
2201+ namedEvent . inputs . forEach ( ( input , i ) => {
2202+ input . name = input . name || `__arg${ i } ` ;
2203+ } ) ;
22292204
2230- const args : unknown [ ] = new Array ( event . inputs . length ) ;
2231- let indexedIdx = 0 ;
2232- let nonIndexedIdx = 0 ;
2205+ const decodedLog = decodeEventLog ( {
2206+ abi : [ namedEvent ] ,
2207+ data : log . data ,
2208+ topics : log . topics ,
2209+ } ) as { eventName : string ; args : Record < string , unknown > } ;
22332210
2234- for ( let i = 0 ; i < event . inputs . length ; i ++ ) {
2235- if ( event . inputs [ i ] ! . indexed ) {
2236- args [ i ] = decodedIndexed [ indexedIdx ++ ] ;
2237- } else {
2238- args [ i ] = decodedNonIndexed [ nonIndexedIdx ++ ] ;
2239- }
2240- }
2211+ const args = namedEvent . inputs . map ( ( input ) => decodedLog . args [ input . name ! ] ) ;
22412212
22422213 return {
22432214 ...log ,
2244- eventName : event . name ,
2215+ eventName : decodedLog . eventName ,
22452216 args,
22462217 } as EventLog ;
22472218}
0 commit comments