From b343d6f3f30ddc2662f75f440557907f2df2678e Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Fri, 7 Jan 2022 14:22:53 -0500 Subject: [PATCH] Add "signature", "timestamp", and "rawOutput" to events Allows FireFly to record richer data about the underlying blockchain event that triggered the token event. Signed-off-by: Andrew Richardson --- src/event-stream/event-stream.interfaces.ts | 1 + src/event-stream/event-stream.service.ts | 1 + src/tokens/tokens.interfaces.ts | 10 +++ src/tokens/tokens.service.ts | 8 ++- test/app.e2e-spec.ts | 80 +++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/event-stream/event-stream.interfaces.ts b/src/event-stream/event-stream.interfaces.ts index fe2bf5a..508a7f8 100644 --- a/src/event-stream/event-stream.interfaces.ts +++ b/src/event-stream/event-stream.interfaces.ts @@ -35,6 +35,7 @@ export interface Event { transactionIndex: string; transactionHash: string; logIndex: string; + timestamp: string; data: any; inputMethod?: string; inputArgs?: Record; diff --git a/src/event-stream/event-stream.service.ts b/src/event-stream/event-stream.service.ts index 65aa86f..d7b018b 100644 --- a/src/event-stream/event-stream.service.ts +++ b/src/event-stream/event-stream.service.ts @@ -166,6 +166,7 @@ export class EventStreamService { websocket: { topic }, blockedReryDelaySec: 30, // intentional due to spelling error in ethconnect inputs: true, + timestamps: true, }; const existingStreams = await this.getStreams(); diff --git a/src/tokens/tokens.interfaces.ts b/src/tokens/tokens.interfaces.ts index 4386562..bde5c03 100644 --- a/src/tokens/tokens.interfaces.ts +++ b/src/tokens/tokens.interfaces.ts @@ -111,6 +111,10 @@ export class BlockchainTransaction { @ApiProperty() @IsOptional() // only optional to support activating very old pools - TODO: remove eventually logIndex: string; + + @ApiProperty() + @IsOptional() + signature: string; } export class TokenPoolActivate { @@ -200,6 +204,12 @@ class tokenEventBase { @ApiProperty() transaction: BlockchainTransaction; + + @ApiProperty() + timestamp: string; + + @ApiProperty() + rawOutput: any; } export class TokenPoolEvent extends tokenEventBase { diff --git a/src/tokens/tokens.service.ts b/src/tokens/tokens.service.ts index 39b1a31..c565322 100644 --- a/src/tokens/tokens.service.ts +++ b/src/tokens/tokens.service.ts @@ -375,11 +375,14 @@ class TokenListener implements EventListener { type: unpackedId.isFungible ? TokenType.FUNGIBLE : TokenType.NONFUNGIBLE, operator: data.operator, data: decodedData, + timestamp: event.timestamp, + rawOutput: data, transaction: { blockNumber: event.blockNumber, transactionIndex: event.transactionIndex, transactionHash: event.transactionHash, logIndex: event.logIndex, + signature: event.signature, }, }, }; @@ -410,7 +413,7 @@ class TokenListener implements EventListener { transferId += `.${eventIndex}`; } - const commonData = { + const commonData = { id: transferId, poolId: unpackedId.poolId, tokenIndex: unpackedId.tokenIndex, @@ -418,11 +421,14 @@ class TokenListener implements EventListener { amount: data.value, operator: data.operator, data: decodedData, + timestamp: event.timestamp, + rawOutput: data, transaction: { blockNumber: event.blockNumber, transactionIndex: event.transactionIndex, transactionHash: event.transactionHash, logIndex: event.logIndex, + signature: event.signature, }, }; diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts index 959652d..41ba377 100644 --- a/test/app.e2e-spec.ts +++ b/test/app.e2e-spec.ts @@ -387,6 +387,7 @@ describe('AppController (e2e)', () => { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', + timestamp: '2020-01-01 00:00:00Z', data: { operator: 'bob', type_id: '340282366920938463463374607431768211456', @@ -406,10 +407,17 @@ describe('AppController (e2e)', () => { type: 'fungible', operator: 'bob', data: '', + timestamp: '2020-01-01 00:00:00Z', + rawOutput: { + operator: 'bob', + type_id: '340282366920938463463374607431768211456', + data: '0x00', + }, transaction: { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', + signature: tokenCreateEventSignature, }, }, }); @@ -434,6 +442,7 @@ describe('AppController (e2e)', () => { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', + timestamp: '2020-01-01 00:00:00Z', data: { operator: 'bob', type_id: '340282366920938463463374607431768211456', @@ -453,10 +462,17 @@ describe('AppController (e2e)', () => { type: 'fungible', operator: 'bob', data: '', + timestamp: '2020-01-01 00:00:00Z', + rawOutput: { + operator: 'bob', + type_id: '340282366920938463463374607431768211456', + data: '0x00', + }, transaction: { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', + signature: tokenCreateEventSignature, }, }, }); @@ -489,6 +505,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { id: '340282366920938463463374607431768211456', from: ZERO_ADDRESS, @@ -522,11 +539,26 @@ describe('AppController (e2e)', () => { operator: 'A', uri: 'firefly://token/0000000000000000000000000000000100000000000000000000000000000000', data: 'test', + timestamp: '2020-01-01 00:00:00Z', + rawOutput: { + id: '340282366920938463463374607431768211456', + from: ZERO_ADDRESS, + to: 'A', + operator: 'A', + value: '5', + transaction: { + blockNumber: '1', + transactionIndex: '0x0', + transactionHash: '0x123', + logIndex: '1', + }, + }, transaction: { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + signature: transferSingleEventSignature, }, }, }); @@ -562,6 +594,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { id: '57896044618658097711785492504343953926975274699741220483192166611388333031425', from: 'A', @@ -595,11 +628,25 @@ describe('AppController (e2e)', () => { operator: 'A', uri: 'firefly://token/8000000000000000000000000000000100000000000000000000000000000001', data: 'test', + timestamp: '2020-01-01 00:00:00Z', + rawOutput: { + id: '57896044618658097711785492504343953926975274699741220483192166611388333031425', + from: 'A', + to: ZERO_ADDRESS, + operator: 'A', + value: '1', + transaction: { + blockNumber: '1', + transactionIndex: '0x0', + transactionHash: '0x123', + }, + }, transaction: { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + signature: transferSingleEventSignature, }, }, }); @@ -635,6 +682,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { id: '57896044618658097711785492504343953926975274699741220483192166611388333031425', from: 'A', @@ -660,11 +708,20 @@ describe('AppController (e2e)', () => { operator: 'A', uri: 'firefly://token/8000000000000000000000000000000100000000000000000000000000000001', data: '', + timestamp: '2020-01-01 00:00:00Z', + rawOutput: { + id: '57896044618658097711785492504343953926975274699741220483192166611388333031425', + from: 'A', + to: 'B', + operator: 'A', + value: '1', + }, transaction: { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + signature: transferSingleEventSignature, }, }, }); @@ -751,6 +808,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { from: 'A', to: 'B', @@ -779,11 +837,20 @@ describe('AppController (e2e)', () => { operator: 'A', uri: 'firefly://token/8000000000000000000000000000000100000000000000000000000000000001', data: '', + timestamp: '2020-01-01 00:00:00Z', + rawOutput: { + from: 'A', + to: 'B', + operator: 'A', + id: '57896044618658097711785492504343953926975274699741220483192166611388333031425', + value: '1', + }, transaction: { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + signature: transferBatchEventSignature, }, }, }); @@ -804,11 +871,20 @@ describe('AppController (e2e)', () => { operator: 'A', uri: 'firefly://token/8000000000000000000000000000000100000000000000000000000000000002', data: '', + timestamp: '2020-01-01 00:00:00Z', + rawOutput: { + from: 'A', + to: 'B', + operator: 'A', + id: '57896044618658097711785492504343953926975274699741220483192166611388333031426', + value: '1', + }, transaction: { blockNumber: '1', transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + signature: transferBatchEventSignature, }, }, }); @@ -878,6 +954,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { operator: 'bob', type_id: '340282366920938463463374607431768211456', @@ -916,6 +993,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { operator: 'bob', type_id: '340282366920938463463374607431768211456', @@ -956,6 +1034,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { operator: 'bob', type_id: '340282366920938463463374607431768211456', @@ -970,6 +1049,7 @@ describe('AppController (e2e)', () => { transactionIndex: '0x0', transactionHash: '0x123', logIndex: '1', + timestamp: '2020-01-01 00:00:00Z', data: { id: '340282366920938463463374607431768211456', from: ZERO_ADDRESS,