From c71804585a29e95dbef8f2a3b716eddf54abeacd Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Wed, 20 Oct 2021 14:38:00 -0400 Subject: [PATCH] Expose "standard" attribute for token pools (always set to "ERC1155") Signed-off-by: Andrew Richardson --- src/tokens/tokens.interfaces.ts | 3 +++ src/tokens/tokens.service.ts | 24 ++++++++++++------------ test/app.e2e-spec.ts | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/tokens/tokens.interfaces.ts b/src/tokens/tokens.interfaces.ts index 7d28897..cb7871f 100644 --- a/src/tokens/tokens.interfaces.ts +++ b/src/tokens/tokens.interfaces.ts @@ -181,6 +181,9 @@ class tokenEventBase { } export class TokenPoolEvent extends tokenEventBase { + @ApiProperty() + standard: string; + @ApiProperty() data?: string; // TODO: remove } diff --git a/src/tokens/tokens.service.ts b/src/tokens/tokens.service.ts index 39c54d6..c42085d 100644 --- a/src/tokens/tokens.service.ts +++ b/src/tokens/tokens.service.ts @@ -42,6 +42,7 @@ import { } from './tokens.interfaces'; import { decodeHex, encodeHex, isFungible, packTokenId, unpackTokenId } from './tokens.util'; +const TOKEN_STANDARD = 'ERC1155'; const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; const tokenCreateEventSignature = 'TokenCreate(address,uint256,bytes)'; @@ -234,13 +235,14 @@ class TokenListener implements EventListener { private transformTokenCreateEvent(event: TokenCreateEvent): WebSocketMessage { const { data } = event; - const parts = unpackTokenId(data.type_id); + const unpackedId = unpackTokenId(data.type_id); const unpackedData = this.safeUnpackData(data.data); return { event: 'token-pool', data: { - poolId: parts.poolId, - type: parts.isFungible ? TokenType.FUNGIBLE : TokenType.NONFUNGIBLE, + standard: TOKEN_STANDARD, + poolId: unpackedId.poolId, + type: unpackedId.isFungible ? TokenType.FUNGIBLE : TokenType.NONFUNGIBLE, operator: data.operator, trackingId: unpackedData.trackingId, data: unpackedData.data, // TODO: remove @@ -255,6 +257,7 @@ class TokenListener implements EventListener { private transformTransferSingleEvent(event: TransferSingleEvent): WebSocketMessage | undefined { const { data } = event; + const unpackedId = unpackTokenId(data.id); const unpackedData = this.safeUnpackData(event.inputArgs?.data); if (data.from === ZERO_ADDRESS && data.to === ZERO_ADDRESS) { @@ -262,12 +265,11 @@ class TokenListener implements EventListener { return undefined; } else if (data.from === ZERO_ADDRESS) { // mint - const parts = unpackTokenId(data.id); return { event: 'token-mint', data: { - poolId: parts.poolId, - tokenIndex: parts.tokenIndex, + poolId: unpackedId.poolId, + tokenIndex: unpackedId.tokenIndex, to: data.to, amount: data.value, operator: data.operator, @@ -282,12 +284,11 @@ class TokenListener implements EventListener { }; } else if (data.to === ZERO_ADDRESS) { // burn - const parts = unpackTokenId(data.id); return { event: 'token-burn', data: { - poolId: parts.poolId, - tokenIndex: parts.tokenIndex, + poolId: unpackedId.poolId, + tokenIndex: unpackedId.tokenIndex, from: data.from, amount: data.value, operator: data.operator, @@ -302,12 +303,11 @@ class TokenListener implements EventListener { }; } else { // transfer - const parts = unpackTokenId(data.id); return { event: 'token-transfer', data: { - poolId: parts.poolId, - tokenIndex: parts.tokenIndex, + poolId: unpackedId.poolId, + tokenIndex: unpackedId.tokenIndex, from: data.from, to: data.to, amount: data.value, diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts index b818b24..ac0cdb6 100644 --- a/test/app.e2e-spec.ts +++ b/test/app.e2e-spec.ts @@ -367,6 +367,7 @@ describe('AppController (e2e)', () => { data: { data: 'test', trackingId: 'tx1', + standard: 'ERC1155', poolId: 'F1', type: 'fungible', operator: 'bob',