@@ -194,12 +194,55 @@ export class Abi {
194194 // earlier version are hoisted to v4
195195 case '4' :
196196 return this . #decodeEventV4( record ) ;
197+ case '5' :
198+ return this . #decodeEventV5( record ) ;
197199 // Latest
198200 default :
199- return this . #decodeEventV5 ( record ) ;
201+ return this . #decodeEventV6 ( record ) ;
200202 }
201203 }
202204
205+ #decodeEventV6 = ( record : EventRecord ) : DecodedEvent => {
206+ const topics = record . event . data [ 2 ] as unknown as { toHex : ( ) => string } [ ] ;
207+ // Try to match by signature topic (first topic)
208+ const signatureTopic = topics [ 0 ] ;
209+ const data = record . event . data [ 1 ] as Bytes ;
210+
211+ if ( signatureTopic ) {
212+ const event = this . events . find ( ( e ) => e . signatureTopic !== undefined && e . signatureTopic !== null && e . signatureTopic === signatureTopic . toHex ( ) ) ;
213+
214+ // Early return if event found by signature topic
215+ if ( event ) {
216+ return event . fromU8a ( data ) ;
217+ }
218+ }
219+
220+ // If no event returned yet, it might be anonymous
221+ const amountOfTopics = topics . length ;
222+ const potentialEvents = this . events . filter ( ( e ) => {
223+ // event can't have a signature topic
224+ if ( e . signatureTopic !== null && e . signatureTopic !== undefined ) {
225+ return false ;
226+ }
227+
228+ // event should have same amount of indexed fields as emitted topics
229+ const amountIndexed = e . args . filter ( ( a ) => a . indexed ) . length ;
230+
231+ if ( amountIndexed !== amountOfTopics ) {
232+ return false ;
233+ }
234+
235+ // If all conditions met, it's a potential event
236+ return true ;
237+ } ) ;
238+
239+ if ( potentialEvents . length === 1 ) {
240+ return potentialEvents [ 0 ] . fromU8a ( data ) ;
241+ }
242+
243+ throw new Error ( 'Unable to determine event' ) ;
244+ } ;
245+
203246 #decodeEventV5 = ( record : EventRecord ) : DecodedEvent => {
204247 // Find event by first topic, which potentially is the signature_topic
205248 const signatureTopic = record . topics [ 0 ] ;
0 commit comments