Skip to content

Commit

Permalink
Do not use tokenIndex for fungible pools
Browse files Browse the repository at this point in the history
This is irrelevant (always 0), so do not require it to be passed or
pass it back in events.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Oct 19, 2021
1 parent 7fc4b9f commit 873e2b0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/tokens/tokens.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export class TokenTransfer {
poolId: string;

@ApiProperty()
@IsNotEmpty()
tokenIndex: string;
@IsOptional()
tokenIndex?: string;

@ApiProperty()
@IsNotEmpty()
Expand Down Expand Up @@ -187,7 +187,7 @@ export class TokenPoolEvent extends tokenEventBase {

export class TokenTransferEvent extends tokenEventBase {
@ApiProperty()
tokenIndex: string;
tokenIndex?: string;

@ApiProperty()
from: string;
Expand Down
1 change: 0 additions & 1 deletion src/tokens/tokens.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Util', () => {
expect(unpackTokenId('340282366920938463463374607431768211456')).toEqual({
isFungible: true,
poolId: 'F1',
tokenIndex: '0',
});
expect(
unpackTokenId(
Expand Down
2 changes: 1 addition & 1 deletion src/tokens/tokens.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ export function unpackTokenId(id: string) {
return {
isFungible: isFungible,
poolId: (isFungible ? 'F' : 'N') + (BigInt.asUintN(255, val) >> BigInt(128)),
tokenIndex: BigInt.asUintN(128, val).toString(),
tokenIndex: isFungible ? undefined : BigInt.asUintN(128, val).toString(),
};
}
8 changes: 3 additions & 5 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ describe('AppController (e2e)', () => {
it('Transfer token', async () => {
const request: TokenTransfer = {
poolId: 'F1',
tokenIndex: '0',
from: '1',
to: '2',
amount: '2',
Expand Down Expand Up @@ -419,7 +418,6 @@ describe('AppController (e2e)', () => {
event: 'token-mint',
data: <TokenMintEvent>{
poolId: 'F1',
tokenIndex: '0',
to: 'A',
amount: '5',
operator: 'A',
Expand Down Expand Up @@ -449,7 +447,7 @@ describe('AppController (e2e)', () => {
transactionIndex: '0x0',
transactionHash: '0x123',
data: {
id: '340282366920938463463374607431768211456',
id: '57896044618658097711785492504343953926975274699741220483192166611388333031425',
from: 'A',
to: ZERO_ADDRESS,
operator: 'A',
Expand All @@ -473,8 +471,8 @@ describe('AppController (e2e)', () => {
expect(message).toEqual(<WebSocketMessage>{
event: 'token-burn',
data: <TokenBurnEvent>{
poolId: 'F1',
tokenIndex: '0',
poolId: 'N1',
tokenIndex: '1',
from: 'A',
amount: '1',
operator: 'A',
Expand Down

0 comments on commit 873e2b0

Please sign in to comment.