diff --git a/README-es.md b/README-es.md index 9d873d1..734b099 100644 --- a/README-es.md +++ b/README-es.md @@ -736,8 +736,8 @@ query { ```graphql mutation { decodeEvent( - contractAddress: "5DfG5TyaffuJ78rHP71cvkYEtktRkpeMiJNJyxd8Q5924GR8" - id: "81735cc9-76d3-5984-83af-5872bc9eaeb7" + contractAddress: "5ELpkDtq7werhT5ybZZMbVBcQTPNomvJP7j5kJQifv7GzVik" + id: "972e782c-2517-5648-9bf1-4c693d2fed90" ) } ``` @@ -747,7 +747,7 @@ mutation { ```graphql { "data": { - "decodeEvent": "[{\"decodedData\":{\"args\":[\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"0x00000000000000000000048c27395000\"],\"event\":{\"args\":[{\"name\":\"from\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"to\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"value\",\"type\":{\"info\":10,\"type\":\"Balance\"}}],\"docs\":[\" Event emitted when a token transfer occurs.\"],\"identifier\":\"Transfer\",\"index\":0}},\"formattedData\":{\"from\":\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"to\":\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"value\":5}}]" + "decodeEvent": "{\"identifier\":\"Transfer\",\"decodedData\":{\"args\":[\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y\",\"0x000000000000000000002d79883d2000\"],\"event\":{\"args\":[{\"name\":\"from\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"to\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"value\",\"type\":{\"info\":10,\"type\":\"Balance\"}}],\"docs\":[\" Event emitted when a token transfer occurs.\"],\"identifier\":\"Transfer\",\"index\":0}},\"formattedData\":{\"from\":\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"to\":\"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y\",\"value\":50}}" } } ``` diff --git a/README.md b/README.md index af8b516..43d872d 100644 --- a/README.md +++ b/README.md @@ -736,8 +736,8 @@ query { ```graphql mutation { decodeEvent( - contractAddress: "5DfG5TyaffuJ78rHP71cvkYEtktRkpeMiJNJyxd8Q5924GR8" - id: "81735cc9-76d3-5984-83af-5872bc9eaeb7" + contractAddress: "5ELpkDtq7werhT5ybZZMbVBcQTPNomvJP7j5kJQifv7GzVik" + id: "972e782c-2517-5648-9bf1-4c693d2fed90" ) } ``` @@ -747,7 +747,7 @@ mutation { ```graphql { "data": { - "decodeEvent": "[{\"decodedData\":{\"args\":[\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"0x00000000000000000000048c27395000\"],\"event\":{\"args\":[{\"name\":\"from\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"to\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"value\",\"type\":{\"info\":10,\"type\":\"Balance\"}}],\"docs\":[\" Event emitted when a token transfer occurs.\"],\"identifier\":\"Transfer\",\"index\":0}},\"formattedData\":{\"from\":\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"to\":\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"value\":5}}]" + "decodeEvent": "{\"identifier\":\"Transfer\",\"decodedData\":{\"args\":[\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y\",\"0x000000000000000000002d79883d2000\"],\"event\":{\"args\":[{\"name\":\"from\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"to\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"value\",\"type\":{\"info\":10,\"type\":\"Balance\"}}],\"docs\":[\" Event emitted when a token transfer occurs.\"],\"identifier\":\"Transfer\",\"index\":0}},\"formattedData\":{\"from\":\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"to\":\"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y\",\"value\":50}}" } } ``` @@ -765,7 +765,7 @@ mutation { ```graphql { "data": { - "decodeEvents": "[{\"decodedData\":{\"args\":[\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"0x00000000000000000000048c27395000\"],\"event\":{\"args\":[{\"name\":\"from\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"to\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"value\",\"type\":{\"info\":10,\"type\":\"Balance\"}}],\"docs\":[\" Event emitted when a token transfer occurs.\"],\"identifier\":\"Transfer\",\"index\":0}},\"formattedData\":{\"from\":\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"to\":\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"value\":5}}]" + "decodeEvents": "[{\"identifier\":\"Transfer\",\"decodedData\":{\"args\":[\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"0x00000000000000000000048c27395000\"],\"event\":{\"args\":[{\"name\":\"from\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"to\",\"type\":{\"info\":9,\"lookupIndex\":11,\"type\":\"Option\",\"docs\":[],\"namespace\":\"Option\",\"sub\":{\"info\":10,\"lookupIndex\":2,\"type\":\"AccountId\",\"docs\":[],\"namespace\":\"ink_env::types::AccountId\",\"lookupNameRoot\":\"InkEnvAccountId\"}}},{\"name\":\"value\",\"type\":{\"info\":10,\"type\":\"Balance\"}}],\"docs\":[\" Event emitted when a token transfer occurs.\"],\"identifier\":\"Transfer\",\"index\":0}},\"formattedData\":{\"from\":\"5GVmSPghWsjACADGYi78dmhuZEgfgDwfixR7BM3aMEoNuTBc\",\"to\":\"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty\",\"value\":5}}]" } } ``` diff --git a/package.json b/package.json index d7a9ca9..1aa8e5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ink-substrate-explorer-api", - "version": "1.0.1", + "version": "1.0.2", "description": "Ink Explorer is an application that provides Ink contracts related information on Substrate based blockchains.", "author": "Blockcoders ", "license": "MIT", diff --git a/src/app.resolver.spec.ts b/src/app.resolver.spec.ts index 344a19e..16ffa97 100644 --- a/src/app.resolver.spec.ts +++ b/src/app.resolver.spec.ts @@ -24,7 +24,7 @@ describe('AppResolver', () => { describe('version', () => { it('should return the current version', () => { - expect(resolver.version()).toEqual('v1.0.1') + expect(resolver.version()).toEqual('v1.0.2') }) }) }) diff --git a/src/app.resolver.ts b/src/app.resolver.ts index 12041d1..023882b 100644 --- a/src/app.resolver.ts +++ b/src/app.resolver.ts @@ -9,6 +9,6 @@ export class AppResolver { @Query(/* istanbul ignore next */ () => String) version(): string { - return 'v1.0.1' + return 'v1.0.2' } } diff --git a/src/events/entity/event.entity.ts b/src/events/entity/event.entity.ts index 46bf318..6861615 100644 --- a/src/events/entity/event.entity.ts +++ b/src/events/entity/event.entity.ts @@ -28,6 +28,10 @@ export class Event extends BaseEntity { @Field(/* istanbul ignore next */ () => String) index!: string + @Column({ nullable: true }) + @Field(/* istanbul ignore next */ () => String, { nullable: true }) + identifier?: string + @Column() @Field(/* istanbul ignore next */ () => String) section!: string diff --git a/src/events/events.resolver.spec.ts b/src/events/events.resolver.spec.ts index aa83047..f8e6859 100644 --- a/src/events/events.resolver.spec.ts +++ b/src/events/events.resolver.spec.ts @@ -17,7 +17,8 @@ describe('EventsResolver', () => { useFactory: jest.fn(() => ({ findById: () => mockEvents[0], fetchEvents: () => mockEvents, - decodeEvents: () => mockDecodedEvent, + decodeEvent: () => mockDecodedEvent, + decodeEvents: () => [mockDecodedEvent], formatDecoded: () => mockFormattedEvent, })), }, @@ -57,7 +58,7 @@ describe('EventsResolver', () => { take: 10, contract: mockEvents[0].contractAddress, } - expect(resolver.decodeEvents(args)).resolves.toEqual(JSON.stringify(mockDecodedEvent)) + expect(resolver.decodeEvents(args)).resolves.toEqual(JSON.stringify([mockDecodedEvent])) }) it('should return an error message', () => { diff --git a/src/events/events.resolver.ts b/src/events/events.resolver.ts index 3ab6753..022569d 100644 --- a/src/events/events.resolver.ts +++ b/src/events/events.resolver.ts @@ -38,7 +38,7 @@ export class EventsResolver { throw new Error('Event not found') } const response = await this.eventsService.decodeEvents([event], contractAddress as string) - return JSON.stringify(response) + return JSON.stringify(response[0]) } catch (error) { return error } diff --git a/src/events/events.service.ts b/src/events/events.service.ts index 76f36e1..78d7a42 100644 --- a/src/events/events.service.ts +++ b/src/events/events.service.ts @@ -98,8 +98,13 @@ export class EventsService { try { const decodedEvent = this.decodeContractEmittedEvent(contract.metadata as string, event.data) event.decodedData = decodedEvent + event.identifier = decodedEvent?.event?.identifier await this.eventRepository.update(event.id, event) - return { decodedData: decodedEvent, formattedData: this.formatDecoded(decodedEvent) } + return { + identifier: decodedEvent?.event?.identifier, + decodedData: decodedEvent, + formattedData: this.formatDecoded(decodedEvent), + } } catch (error) { this.logger.error(error) return { message: "Can't decode event", error } diff --git a/src/schema.graphql b/src/schema.graphql index c2ae06b..3d27e56 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -31,6 +31,7 @@ type Event { decodedData: String formattedData: String! id: String! + identifier: String index: String! method: String! section: String!