Skip to content

Commit

Permalink
Merge pull request #55 from kaleido-io/protocolid
Browse files Browse the repository at this point in the history
Alter formatting of blockchain event IDs to match FireFly core
  • Loading branch information
peterbroadhurst authored Feb 1, 2022
2 parents b343d6f + 2ed4150 commit 2ae612a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,17 @@ class TokenListener implements EventListener {
return undefined;
}

// This intentionally matches the formatting of protocol IDs for blockchain events in FireFly core
const blockNumber = event.blockNumber ?? '0';
const txIndex = BigInt(event.transactionIndex).toString(10);
let transferId = [event.blockNumber, txIndex, event.logIndex].join('.');
const logIndex = event.logIndex ?? '0';
let transferId = [
blockNumber.padStart(12, '0'),
txIndex.padStart(6, '0'),
logIndex.padStart(6, '0'),
].join('/');
if (eventIndex !== undefined) {
transferId += `.${eventIndex}`;
transferId += '/' + eventIndex.toString(10).padStart(6, '0');
}

const commonData = <TokenTransferEvent>{
Expand Down
10 changes: 5 additions & 5 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ describe('AppController (e2e)', () => {
expect(message).toEqual(<WebSocketMessage>{
event: 'token-mint',
data: <TokenMintEvent>{
id: '1.0.1',
id: '000000000001/000000/000001',
poolId: 'F1',
to: 'A',
amount: '5',
Expand Down Expand Up @@ -620,7 +620,7 @@ describe('AppController (e2e)', () => {
expect(message).toEqual(<WebSocketMessage>{
event: 'token-burn',
data: <TokenBurnEvent>{
id: '1.0.1',
id: '000000000001/000000/000001',
poolId: 'N1',
tokenIndex: '1',
from: 'A',
Expand Down Expand Up @@ -699,7 +699,7 @@ describe('AppController (e2e)', () => {
expect(message).toEqual(<WebSocketMessage>{
event: 'token-transfer',
data: <TokenTransferEvent>{
id: '1.0.1',
id: '000000000001/000000/000001',
poolId: 'N1',
tokenIndex: '1',
from: 'A',
Expand Down Expand Up @@ -828,7 +828,7 @@ describe('AppController (e2e)', () => {
expect(message).toEqual(<WebSocketMessage>{
event: 'token-transfer',
data: <TokenTransferEvent>{
id: '1.0.1.0',
id: '000000000001/000000/000001/000000',
poolId: 'N1',
tokenIndex: '1',
from: 'A',
Expand Down Expand Up @@ -862,7 +862,7 @@ describe('AppController (e2e)', () => {
expect(message).toEqual(<WebSocketMessage>{
event: 'token-transfer',
data: <TokenTransferEvent>{
id: '1.0.1.1',
id: '000000000001/000000/000001/000001',
poolId: 'N1',
tokenIndex: '2',
from: 'A',
Expand Down

0 comments on commit 2ae612a

Please sign in to comment.