Skip to content

Commit

Permalink
Add "signature", "timestamp", and "rawOutput" to events
Browse files Browse the repository at this point in the history
Allows FireFly to record richer data about the underlying blockchain event
that triggered the token event.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Jan 19, 2022
1 parent f5d2285 commit b343d6f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/event-stream/event-stream.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface Event {
transactionIndex: string;
transactionHash: string;
logIndex: string;
timestamp: string;
data: any;
inputMethod?: string;
inputArgs?: Record<string, any>;
Expand Down
1 change: 1 addition & 0 deletions src/event-stream/event-stream.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions src/tokens/tokens.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -200,6 +204,12 @@ class tokenEventBase {

@ApiProperty()
transaction: BlockchainTransaction;

@ApiProperty()
timestamp: string;

@ApiProperty()
rawOutput: any;
}

export class TokenPoolEvent extends tokenEventBase {
Expand Down
8 changes: 7 additions & 1 deletion src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
};
Expand Down Expand Up @@ -410,19 +413,22 @@ class TokenListener implements EventListener {
transferId += `.${eventIndex}`;
}

const commonData = {
const commonData = <TokenTransferEvent>{
id: transferId,
poolId: unpackedId.poolId,
tokenIndex: unpackedId.tokenIndex,
uri: await this.getTokenUri(data.id),
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,
},
};

Expand Down
80 changes: 80 additions & 0 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
},
},
});
Expand All @@ -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',
Expand All @@ -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,
},
},
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
});
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
},
},
});
Expand Down Expand Up @@ -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',
Expand All @@ -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,
},
},
});
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
},
},
});
Expand All @@ -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,
},
},
});
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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,
Expand Down

0 comments on commit b343d6f

Please sign in to comment.