@@ -61,48 +61,54 @@ export class AppRegistryDapp {
6161 } )
6262 }
6363
64- public async getCreateAppEvent (
64+ public getCreateAppEvent (
6565 receipt : ContractReceipt ,
6666 senderAddress : Address ,
67- ) : Promise < AppCreatedEventObject > {
67+ ) : AppCreatedEventObject {
6868 for ( const log of receipt . logs ) {
6969 try {
70- const parsedLog = this . factory . interface . parseLog ( log )
70+ const parsedLog = this . factory . parseLog ( log )
7171 if ( parsedLog . name === 'AppCreated' ) {
72- const app = await this . getAppById ( parsedLog . args . uid as string )
73- const isOwner = app . owner . toLowerCase ( ) === senderAddress . toLowerCase ( )
74- if ( ! isOwner ) {
75- continue
72+ if ( 'owner' in parsedLog . args && typeof parsedLog . args . owner === 'string' ) {
73+ // newer contracts - filter by owner from event
74+ if ( parsedLog . args . owner . toLowerCase ( ) === senderAddress . toLowerCase ( ) ) {
75+ return {
76+ app : parsedLog . args . app ,
77+ uid : parsedLog . args . uid ,
78+ owner : parsedLog . args . owner ,
79+ } satisfies AppCreatedEventObject
80+ }
81+ } else {
82+ // older contracts - return first match
83+ return {
84+ app : parsedLog . args . app ,
85+ uid : parsedLog . args . uid ,
86+ owner : '' ,
87+ } satisfies AppCreatedEventObject
7688 }
77- return {
78- app : parsedLog . args . app ,
79- uid : parsedLog . args . uid ,
80- } satisfies AppCreatedEventObject
8189 }
8290 } catch {
8391 // no need for error, this log is not from the contract we're interested in
8492 }
8593 }
86- return { app : '' , uid : '' }
94+ return { app : '' , uid : '' , owner : '' }
8795 }
8896
89- public async getRegisterAppEvent (
97+ public getRegisterAppEvent (
9098 receipt : ContractReceipt ,
91- senderAddress : Address ,
92- ) : Promise < AppRegisteredEventObject > {
99+ appAddress : Address ,
100+ ) : AppRegisteredEventObject {
93101 for ( const log of receipt . logs ) {
94102 try {
95- const parsedLog = this . registry . interface . parseLog ( log )
103+ const parsedLog = this . registry . parseLog ( log )
96104 if ( parsedLog . name === 'AppRegistered' ) {
97- const app = await this . getAppById ( parsedLog . args . uid as string )
98- const isOwner = app . owner . toLowerCase ( ) === senderAddress . toLowerCase ( )
99- if ( ! isOwner ) {
100- continue
105+ const eventAppAddress = parsedLog . args . app as Address
106+ if ( eventAppAddress . toLowerCase ( ) === appAddress . toLowerCase ( ) ) {
107+ return {
108+ app : parsedLog . args . app ,
109+ uid : parsedLog . args . uid ,
110+ } satisfies AppRegisteredEventObject
101111 }
102- return {
103- app : parsedLog . args . app ,
104- uid : parsedLog . args . uid ,
105- } satisfies AppRegisteredEventObject
106112 }
107113 } catch {
108114 // no need for error, this log is not from the contract we're interested in
0 commit comments