Skip to content

Commit

Permalink
Expose "standard" attribute for token pools (always set to "ERC1155")
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Oct 21, 2021
1 parent 1cb730d commit c718045
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/tokens/tokens.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ class tokenEventBase {
}

export class TokenPoolEvent extends tokenEventBase {
@ApiProperty()
standard: string;

@ApiProperty()
data?: string; // TODO: remove
}
Expand Down
24 changes: 12 additions & 12 deletions src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down Expand Up @@ -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: <TokenPoolEvent>{
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
Expand All @@ -255,19 +257,19 @@ 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) {
// should not happen
return undefined;
} else if (data.from === ZERO_ADDRESS) {
// mint
const parts = unpackTokenId(data.id);
return {
event: 'token-mint',
data: <TokenMintEvent>{
poolId: parts.poolId,
tokenIndex: parts.tokenIndex,
poolId: unpackedId.poolId,
tokenIndex: unpackedId.tokenIndex,
to: data.to,
amount: data.value,
operator: data.operator,
Expand All @@ -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: <TokenBurnEvent>{
poolId: parts.poolId,
tokenIndex: parts.tokenIndex,
poolId: unpackedId.poolId,
tokenIndex: unpackedId.tokenIndex,
from: data.from,
amount: data.value,
operator: data.operator,
Expand All @@ -302,12 +303,11 @@ class TokenListener implements EventListener {
};
} else {
// transfer
const parts = unpackTokenId(data.id);
return {
event: 'token-transfer',
data: <TokenTransferEvent>{
poolId: parts.poolId,
tokenIndex: parts.tokenIndex,
poolId: unpackedId.poolId,
tokenIndex: unpackedId.tokenIndex,
from: data.from,
to: data.to,
amount: data.value,
Expand Down
1 change: 1 addition & 0 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ describe('AppController (e2e)', () => {
data: <TokenPoolEvent>{
data: 'test',
trackingId: 'tx1',
standard: 'ERC1155',
poolId: 'F1',
type: 'fungible',
operator: 'bob',
Expand Down

0 comments on commit c718045

Please sign in to comment.